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

insertQrcode

parent 0bbe8de4
No related branches found
No related tags found
1 merge request!1Draft: Resolve "[Document Sealing] Implement PDF parser"
Pipeline #49092 passed with stages
in 1 minute and 9 seconds
......@@ -5,5 +5,6 @@ declare class PDFparser {
readonly config: any;
constructor(document: Buffer);
getPDFMeta: () => Promise<IgetMetaResponse>;
insertQrCode: (imgBytes: ArrayBuffer) => Promise<ArrayBuffer>;
}
export default PDFparser;
......@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const verify_pdf_1 = __importDefault(require("@ninja-labs/verify-pdf"));
const pdfdataextract_1 = require("pdfdataextract");
const config_1 = require("./config");
const { PDFDocument } = require("pdf-lib");
class PDFparser {
constructor(document) {
this.getPDFMeta = () => __awaiter(this, void 0, void 0, function* () {
......@@ -44,6 +45,19 @@ class PDFparser {
throw new Error("Could not get pdf metadata");
}
});
this.insertQrCode = (imgBytes) => __awaiter(this, void 0, void 0, function* () {
const pdfDoc = yield PDFDocument.load(this.document);
const img = yield pdfDoc.embedPng(imgBytes);
const imagePage = pdfDoc.insertPage(0);
imagePage.drawImage(img, {
x: 0,
y: 0,
width: imagePage.getWidth(),
height: imagePage.getHeight(),
});
const pdfBytes = yield pdfDoc.save();
return pdfBytes;
});
this.document = document;
this.config = config_1.config;
}
......
......@@ -38,6 +38,7 @@
},
"dependencies": {
"@ninja-labs/verify-pdf": "^0.3.9",
"pdf-lib": "^1.17.1",
"pdfdataextract": "^3.2.0"
}
}
......@@ -2,6 +2,7 @@ import verifyPDF from "@ninja-labs/verify-pdf";
import { PdfData } from "pdfdataextract";
import { config } from "./config";
import { IgetMetaResponse } from "./types";
const { PDFDocument } = require("pdf-lib");
class PDFparser {
readonly document;
......@@ -39,6 +40,23 @@ class PDFparser {
throw new Error("Could not get pdf metadata");
}
};
insertQrCode = async (imgBytes: ArrayBuffer): Promise<ArrayBuffer> => {
const pdfDoc = await PDFDocument.load(this.document);
const img = await pdfDoc.embedPng(imgBytes);
const imagePage = pdfDoc.insertPage(0);
imagePage.drawImage(img, {
x: 0,
y: 0,
width: imagePage.getWidth(),
height: imagePage.getHeight(),
});
const pdfBytes = await pdfDoc.save();
return pdfBytes;
};
}
export default PDFparser;
......@@ -1077,6 +1077,20 @@
dependencies:
node-forge "^0.10.0"
"@pdf-lib/standard-fonts@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@pdf-lib/standard-fonts/-/standard-fonts-1.0.0.tgz#8ba691c4421f71662ed07c9a0294b44528af2d7f"
integrity sha512-hU30BK9IUN/su0Mn9VdlVKsWBS6GyhVfqjwl1FjZN4TxP6cCw0jP2w7V3Hf5uX7M0AZJ16vey9yE0ny7Sa59ZA==
dependencies:
pako "^1.0.6"
"@pdf-lib/upng@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@pdf-lib/upng/-/upng-1.0.1.tgz#7dc9c636271aca007a9df4deaf2dd7e7960280cb"
integrity sha512-dQK2FUMQtowVP00mtIksrlZhdFXQZPC+taih1q4CvPZ5vqdxR/LKBaFg0oAfzd1GlHZXXSPdQfzQnt+ViGvEIQ==
dependencies:
pako "^1.0.10"
"@sinonjs/commons@^1.7.0":
version "1.8.1"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.1.tgz#e7df00f98a203324f6dc7cc606cad9d4a8ab2217"
......@@ -3864,6 +3878,11 @@ p-try@^2.0.0:
resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==
pako@^1.0.10, pako@^1.0.11, pako@^1.0.6:
version "1.0.11"
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
parent-module@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"
......@@ -3921,6 +3940,16 @@ path-type@^4.0.0:
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==
pdf-lib@^1.17.1:
version "1.17.1"
resolved "https://registry.yarnpkg.com/pdf-lib/-/pdf-lib-1.17.1.tgz#9e7dd21261a0c1fb17992580885b39e7d08f451f"
integrity sha512-V/mpyJAoTsN4cnP31vc0wfNA1+p20evqqnap0KLoRUN0Yk/p3wN52DOEsL4oBFcLdb76hlpKPtzJIgo67j/XLw==
dependencies:
"@pdf-lib/standard-fonts" "^1.0.0"
"@pdf-lib/upng" "^1.0.1"
pako "^1.0.11"
tslib "^1.11.1"
pdfdataextract@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/pdfdataextract/-/pdfdataextract-3.2.0.tgz#c40d59fb0de4ed6e63a1da08f87d4f4550e841ec"
......@@ -4769,7 +4798,7 @@ tr46@^2.0.2:
dependencies:
punycode "^2.1.1"
tslib@^1.8.1, tslib@^1.9.0:
tslib@^1.11.1, tslib@^1.8.1, tslib@^1.9.0:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
......
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