Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign multiple PDF pages at the same time in the same location (#2008) #2278

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions src/main/resources/static/css/sign.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,53 +62,54 @@ select#font-select option {
background-color: rgba(52, 152, 219, 0.2);
/* Darken background on hover */
}

.signature-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 1rem;
padding: 1rem;
max-height: 400px;
overflow-y: auto;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 1rem;
padding: 1rem;
max-height: 400px;
overflow-y: auto;
}

.signature-list {
max-height: 400px;
overflow-y: auto;
max-height: 400px;
overflow-y: auto;
}

.signature-list-item {
padding: 0.75rem;
border: 1px solid #dee2e6;
border-radius: 4px;
margin-bottom: 0.5rem;
cursor: pointer;
transition: background-color 0.2s;
padding: 0.75rem;
border: 1px solid #dee2e6;
border-radius: 4px;
margin-bottom: 0.5rem;
cursor: pointer;
transition: background-color 0.2s;
}

.signature-list-item:hover {
background-color: #f8f9fa;
background-color: #f8f9fa;
}

.signature-list-info {
display: flex;
justify-content: space-between;
align-items: center;
display: flex;
justify-content: space-between;
align-items: center;
}

.signature-list-name {
font-weight: 500;
font-weight: 500;
}

.signature-list-details {
color: #6c757d;
font-size: 0.875rem;
color: #6c757d;
font-size: 0.875rem;
}

.signature-list-details small:not(:last-child) {
margin-right: 1rem;
margin-right: 1rem;
}

.view-toggle {
text-align: right;
padding: 0.5rem 1rem;
}
text-align: right;
padding: 0.5rem 1rem;
}
77 changes: 74 additions & 3 deletions src/main/resources/static/js/draggable-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const DraggableUtils = {
nextId: 0,
pdfDoc: null,
pageIndex: 0,
elementAllPages: [],
documentsMap: new Map(),
lastInteracted: null,

Expand Down Expand Up @@ -197,6 +198,68 @@ const DraggableUtils = {
deleteAllDraggableCanvases() {
this.boxDragContainer.querySelectorAll(".draggable-canvas").forEach((el) => el.remove());
},
async addAllPagesDraggableCanvas(element) {
if (element) {
let currentPage = this.pageIndex
if (!this.elementAllPages.includes(element)) {
this.elementAllPages.push(element)
element.style.filter = 'sepia(1) hue-rotate(90deg) brightness(1.2)';
let newElement = {
"element": element,
"offsetWidth": element.width,
"offsetHeight": element.height
}

let pagesMap = this.documentsMap.get(this.pdfDoc);

if (!pagesMap) {
pagesMap = {};
this.documentsMap.set(this.pdfDoc, pagesMap);
}
let page = this.pageIndex

for (let pageIndex = 0; pageIndex < this.pdfDoc.numPages; pageIndex++) {

if (pagesMap[`${pageIndex}-offsetWidth`]) {
if (!pagesMap[pageIndex].includes(newElement)) {
pagesMap[pageIndex].push(newElement);
}
} else {
pagesMap[pageIndex] = []
pagesMap[pageIndex].push(newElement)
pagesMap[`${pageIndex}-offsetWidth`] = pagesMap[`${page}-offsetWidth`];
pagesMap[`${pageIndex}-offsetHeight`] = pagesMap[`${page}-offsetHeight`];
}
await this.goToPage(pageIndex)
}
} else {
const index = this.elementAllPages.indexOf(element);
if (index !== -1) {
this.elementAllPages.splice(index, 1);
}
element.style.filter = '';
let pagesMap = this.documentsMap.get(this.pdfDoc);

if (!pagesMap) {
pagesMap = {};
this.documentsMap.set(this.pdfDoc, pagesMap);
}
for (let pageIndex = 0; pageIndex < this.pdfDoc.numPages; pageIndex++) {
if (pagesMap[`${pageIndex}-offsetWidth`] && pageIndex != currentPage) {
const pageElements = pagesMap[pageIndex];
pageElements.forEach(elementPage => {
const elementIndex = pageElements.findIndex(elementPage => elementPage['element'].id === element.id);
if (elementIndex !== -1) {
pageElements.splice(elementIndex, 1);
}
});
}
await this.goToPage(pageIndex)
}
}
await this.goToPage(currentPage)
}
},
deleteDraggableCanvas(element) {
if (element) {
//Check if deleted element is the last interacted
Expand Down Expand Up @@ -241,7 +304,7 @@ const DraggableUtils = {
}

const draggablesData = pagesMap[this.pageIndex];
if (draggablesData) {
if (draggablesData && Array.isArray(draggablesData)) {
draggablesData.forEach((draggableData) => this.boxDragContainer.appendChild(draggableData.element));
}

Expand Down Expand Up @@ -273,6 +336,13 @@ const DraggableUtils = {

//return pdfCanvas.toDataURL();
},

async goToPage(pageIndex) {
this.storePageContents();
await this.renderPage(this.pdfDoc, pageIndex);
this.loadPageContents();
},

async incrementPage() {
if (this.pageIndex < this.pdfDoc.numPages - 1) {
this.storePageContents();
Expand All @@ -297,14 +367,16 @@ const DraggableUtils = {
this.storePageContents();

const pagesMap = this.documentsMap.get(this.pdfDoc);

for (let pageIdx in pagesMap) {
if (pageIdx.includes("offset")) {
continue;
}
console.log(typeof pageIdx);

const page = pdfDocModified.getPage(parseInt(pageIdx));
const draggablesData = pagesMap[pageIdx];
let draggablesData = pagesMap[pageIdx];

const offsetWidth = pagesMap[pageIdx + "-offsetWidth"];
const offsetHeight = pagesMap[pageIdx + "-offsetHeight"];

Expand Down Expand Up @@ -383,7 +455,6 @@ const DraggableUtils = {
});
}
}

this.loadPageContents();
return pdfDocModified;
},
Expand Down
Loading
Loading