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 with stages
in 48 seconds
......@@ -5,7 +5,7 @@ declare class PDFparser {
readonly config: any;
constructor(document: Buffer);
getPDFMeta: () => Promise<IgetMetaResponse>;
insertQrCode: (imgBytes: ArrayBuffer) => Promise<ArrayBuffer>;
insertQrCode: (imgBytes: ArrayBuffer, url: string) => Promise<ArrayBuffer>;
private createPageLinkAnnotation;
}
export default PDFparser;
......@@ -46,10 +46,10 @@ class PDFparser {
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 img = yield pdfDoc.embedPng(imgBytes);
const scaled = img.scale(0.5);
const scaled = img.scale(0.1);
const pages = pdfDoc.getPages();
const firstPage = pages[0];
firstPage.drawImage(img, {
......@@ -58,7 +58,7 @@ class PDFparser {
width: scaled.width,
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,
imgYPos: firstPage.getHeight() / 2 - scaled.height / 2,
imgWidth: scaled.width,
......
......@@ -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 img = await pdfDoc.embedPng(imgBytes);
const scaled = img.scale(0.5);
const scaled = img.scale(0.1);
const pages = pdfDoc.getPages();
......@@ -58,16 +61,12 @@ class PDFparser {
height: scaled.height,
});
const link = this.createPageLinkAnnotation(
firstPage,
"https://pdf-lib.js.org/",
{
imgXPos: firstPage.getWidth() / 2 - scaled.width / 2,
imgYPos: firstPage.getHeight() / 2 - scaled.height / 2,
imgWidth: scaled.width,
imagHeight: 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(PDFName.of("Annots"), pdfDoc.context.obj([link]));
......
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