Skip to content
Snippets Groups Projects
Commit 1d62a8df authored by Zdravko Iliev's avatar Zdravko Iliev
Browse files

multipage support

parent 6a5aa3a4
No related branches found
No related tags found
1 merge request!1Draft: Resolve "[Document Sealing] Implement PDF parser"
Pipeline #49124 passed with stages
in 44 seconds
......@@ -51,20 +51,22 @@ class PDFparser {
const img = yield pdfDoc.embedPng(imgBytes);
const scaled = img.scale(0.2);
const pages = pdfDoc.getPages();
const firstPage = pages[0];
firstPage.drawImage(img, {
x: firstPage.getWidth() / 2 - scaled.width / 2,
y: firstPage.getHeight() / 2 - scaled.height / 2,
width: scaled.width,
height: scaled.height,
});
const link = this.createPageLinkAnnotation(firstPage, url, {
imgXPos: firstPage.getWidth() / 2 - scaled.width / 2,
imgYPos: firstPage.getHeight() / 2 - scaled.height / 2,
imgWidth: scaled.width,
imagHeight: scaled.height,
});
firstPage.node.set(pdf_lib_1.PDFName.of("Annots"), pdfDoc.context.obj([link]));
for (let index = 0; index < pages.length; index++) {
const page = pages[index];
page.drawImage(img, {
x: page.getWidth() / 2 - scaled.width / 2,
y: page.getHeight() / 2 - scaled.height / 2,
width: scaled.width,
height: scaled.height,
});
const link = this.createPageLinkAnnotation(page, url, {
imgXPos: page.getWidth() / 2 - scaled.width / 2,
imgYPos: page.getHeight() / 2 - scaled.height / 2,
imgWidth: scaled.width,
imagHeight: scaled.height,
});
page.node.set(pdf_lib_1.PDFName.of("Annots"), pdfDoc.context.obj([link]));
}
const pdfBytes = yield pdfDoc.save();
return pdfBytes;
});
......
......@@ -52,23 +52,25 @@ class PDFparser {
const pages = pdfDoc.getPages();
const firstPage = pages[0];
for (let index = 0; index < pages.length; index++) {
const page = pages[index];
firstPage.drawImage(img, {
x: firstPage.getWidth() / 2 - scaled.width / 2,
y: firstPage.getHeight() / 2 - scaled.height / 2,
width: scaled.width,
height: scaled.height,
});
page.drawImage(img, {
x: page.getWidth() / 2 - scaled.width / 2,
y: page.getHeight() / 2 - scaled.height / 2,
width: scaled.width,
height: scaled.height,
});
const link = this.createPageLinkAnnotation(firstPage, url, {
imgXPos: firstPage.getWidth() / 2 - scaled.width / 2,
imgYPos: firstPage.getHeight() / 2 - scaled.height / 2,
imgWidth: scaled.width,
imagHeight: scaled.height,
});
const link = this.createPageLinkAnnotation(page, url, {
imgXPos: page.getWidth() / 2 - scaled.width / 2,
imgYPos: page.getHeight() / 2 - scaled.height / 2,
imgWidth: scaled.width,
imagHeight: scaled.height,
});
firstPage.node.set(PDFName.of("Annots"), pdfDoc.context.obj([link]));
page.node.set(PDFName.of("Annots"), pdfDoc.context.obj([link]));
}
const pdfBytes = await pdfDoc.save();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment