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

add dynamic coords

parent 6a7e9056
No related branches found
No related tags found
1 merge request!1Draft: Resolve "[Document Sealing] Implement PDF parser"
Pipeline #49804 failed
......@@ -5,7 +5,7 @@ declare class PDFparser {
readonly config: any;
constructor(document: Buffer);
getPDFMeta: () => Promise<IGetMetaResponse>;
insertQrCode: (imgBytes: ArrayBuffer, url: string, scaleFactor: number) => Promise<ArrayBuffer>;
insertQrCode: (imgBytes: ArrayBuffer, url: string, coords: any, scaleFactor: number) => Promise<ArrayBuffer>;
private createPageLinkAnnotation;
}
export default PDFparser;
......@@ -45,13 +45,17 @@ class PDFparser {
throw new errors_1.GeneralError(error);
}
});
this.insertQrCode = (imgBytes, url, scaleFactor) => __awaiter(this, void 0, void 0, function* () {
this.insertQrCode = (imgBytes, url, coords, scaleFactor) => __awaiter(this, void 0, void 0, function* () {
const pdfDoc = yield pdf_lib_1.PDFDocument.load(this.document);
const img = yield pdfDoc.embedPng(imgBytes);
const scaled = img.scale(scaleFactor);
const pages = pdfDoc.getPages();
for (let index = 0; index < pages.length; index++) {
const page = pages[index];
console.log("dynamic x ", coords[index + 1].x);
console.log("dynamic y ", coords[index + 1].y);
console.log("x", page.getWidth() / 2 - scaled.width / 2);
console.log("y", page.getHeight() / 2 - scaled.height / 2);
page.drawImage(img, {
x: page.getWidth() / 2 - scaled.width / 2,
y: page.getHeight() / 2 - scaled.height / 2,
......
......@@ -50,6 +50,7 @@ class PDFparser {
insertQrCode = async (
imgBytes: ArrayBuffer,
url: string,
coords: any,
scaleFactor: number
): Promise<ArrayBuffer> => {
const pdfDoc = await PDFDocument.load(this.document);
......@@ -62,6 +63,12 @@ class PDFparser {
for (let index = 0; index < pages.length; index++) {
const page = pages[index];
console.log("dynamic x ", coords[index + 1].x);
console.log("dynamic y ", coords[index + 1].y);
console.log("x", page.getWidth() / 2 - scaled.width / 2);
console.log("y", page.getHeight() / 2 - scaled.height / 2);
page.drawImage(img, {
x: page.getWidth() / 2 - scaled.width / 2,
y: page.getHeight() / 2 - scaled.height / 2,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment