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

scale down qrcode

parent 52a1720d
No related branches found
No related tags found
1 merge request!1Draft: Resolve "[Document Sealing] Implement PDF parser"
Pipeline #49118 passed
...@@ -5,7 +5,7 @@ declare class PDFparser { ...@@ -5,7 +5,7 @@ declare class PDFparser {
readonly config: any; readonly config: any;
constructor(document: Buffer); constructor(document: Buffer);
getPDFMeta: () => Promise<IgetMetaResponse>; getPDFMeta: () => Promise<IgetMetaResponse>;
insertQrCode: (imgBytes: ArrayBuffer) => Promise<ArrayBuffer>; insertQrCode: (imgBytes: ArrayBuffer, url: string) => Promise<ArrayBuffer>;
private createPageLinkAnnotation; private createPageLinkAnnotation;
} }
export default PDFparser; export default PDFparser;
...@@ -46,10 +46,10 @@ class PDFparser { ...@@ -46,10 +46,10 @@ class PDFparser {
throw new Error("Could not get pdf metadata"); throw new Error("Could not get pdf metadata");
} }
}); });
this.insertQrCode = (imgBytes) => __awaiter(this, void 0, void 0, function* () { this.insertQrCode = (imgBytes, url) => __awaiter(this, void 0, void 0, function* () {
const pdfDoc = yield PDFDocument.load(this.document); const pdfDoc = yield PDFDocument.load(this.document);
const img = yield pdfDoc.embedPng(imgBytes); const img = yield pdfDoc.embedPng(imgBytes);
const scaled = img.scale(0.5); const scaled = img.scale(0.1);
const pages = pdfDoc.getPages(); const pages = pdfDoc.getPages();
const firstPage = pages[0]; const firstPage = pages[0];
firstPage.drawImage(img, { firstPage.drawImage(img, {
...@@ -58,7 +58,7 @@ class PDFparser { ...@@ -58,7 +58,7 @@ class PDFparser {
width: scaled.width, width: scaled.width,
height: scaled.height, height: scaled.height,
}); });
const link = this.createPageLinkAnnotation(firstPage, "https://pdf-lib.js.org/", { const link = this.createPageLinkAnnotation(firstPage, url, {
imgXPos: firstPage.getWidth() / 2 - scaled.width / 2, imgXPos: firstPage.getWidth() / 2 - scaled.width / 2,
imgYPos: firstPage.getHeight() / 2 - scaled.height / 2, imgYPos: firstPage.getHeight() / 2 - scaled.height / 2,
imgWidth: scaled.width, imgWidth: scaled.width,
......
...@@ -41,11 +41,14 @@ class PDFparser { ...@@ -41,11 +41,14 @@ class PDFparser {
} }
}; };
insertQrCode = async (imgBytes: ArrayBuffer): Promise<ArrayBuffer> => { insertQrCode = async (
imgBytes: ArrayBuffer,
url: string
): Promise<ArrayBuffer> => {
const pdfDoc = await PDFDocument.load(this.document); const pdfDoc = await PDFDocument.load(this.document);
const img = await pdfDoc.embedPng(imgBytes); const img = await pdfDoc.embedPng(imgBytes);
const scaled = img.scale(0.5); const scaled = img.scale(0.1);
const pages = pdfDoc.getPages(); const pages = pdfDoc.getPages();
...@@ -58,16 +61,12 @@ class PDFparser { ...@@ -58,16 +61,12 @@ class PDFparser {
height: scaled.height, height: scaled.height,
}); });
const link = this.createPageLinkAnnotation( const link = this.createPageLinkAnnotation(firstPage, url, {
firstPage, imgXPos: firstPage.getWidth() / 2 - scaled.width / 2,
"https://pdf-lib.js.org/", imgYPos: firstPage.getHeight() / 2 - scaled.height / 2,
{ imgWidth: scaled.width,
imgXPos: firstPage.getWidth() / 2 - scaled.width / 2, imagHeight: scaled.height,
imgYPos: firstPage.getHeight() / 2 - scaled.height / 2, });
imgWidth: scaled.width,
imagHeight: scaled.height,
}
);
firstPage.node.set(PDFName.of("Annots"), pdfDoc.context.obj([link])); firstPage.node.set(PDFName.of("Annots"), pdfDoc.context.obj([link]));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment