diff --git a/Rev1/node/public/js/signer.js b/Rev1/node/public/js/signer.js index e3854ae..e4df9ba 100644 --- a/Rev1/node/public/js/signer.js +++ b/Rev1/node/public/js/signer.js @@ -13,9 +13,9 @@ function submitForm(e) { const ypos = document.getElementById("ypos"); const sf = document.getElementById("sf"); const formData = new FormData(); - formData.append("xpos", xpos.value); - formData.append("ypos", ypos.value); - formData.append("sf", sf.value); + formData.append("x", parseFloat(xpos.value)); + formData.append("y", parseFloat(ypos.value)); + formData.append("sf", parseFloat(sf.value)); formData.append("files", mainFile.files[0]); console.log(mainFile.files[0]); for (let i = 0; i < imgFiles.files.length; i++) { diff --git a/Rev1/node/public/upload/converted/AnkaSmartTeknolojiJLCPCB_Ithalat_deleted.pdf b/Rev1/node/public/upload/converted/AnkaSmartTeknolojiJLCPCB_Ithalat_deleted.pdf deleted file mode 100644 index e612bf0..0000000 Binary files a/Rev1/node/public/upload/converted/AnkaSmartTeknolojiJLCPCB_Ithalat_deleted.pdf and /dev/null differ diff --git a/Rev1/node/public/upload/converted/Enpara.com Şirketim işlem dekontu.pdf b/Rev1/node/public/upload/converted/Enpara.com Şirketim işlem dekontu.pdf deleted file mode 100644 index 2ef21d5..0000000 Binary files a/Rev1/node/public/upload/converted/Enpara.com Şirketim işlem dekontu.pdf and /dev/null differ diff --git a/Rev1/node/routes/invoice_sign.js b/Rev1/node/routes/invoice_sign.js index d4da392..e8e7e9f 100644 --- a/Rev1/node/routes/invoice_sign.js +++ b/Rev1/node/routes/invoice_sign.js @@ -19,21 +19,25 @@ const orderReccentFiles = (dir) => { const { PDFDocument } = require("pdf-lib"); -const signPDF = async (sourceFile) => { +const signPDF = async (sourceFile, { x = 0, y = 0, sf = 1.0 }) => { // Fetch PNG image const pngUrl = signDir; const pngSignBytes = fs.readFileSync(signDir); const pngStampBytes = fs.readFileSync(stampDir); - const pBytes = fs.readFileSync(rawDir + sourceFile); - const pdfDoc = await PDFDocument.load(pBytes); + try { + const pBytes = fs.readFileSync(rawDir + sourceFile); + const pdfDoc = await PDFDocument.load(pBytes); + } catch (error) { + throw error; + } // Embed the JPG image bytes and PNG image bytes const pngSign = await pdfDoc.embedPng(pngSignBytes); const pngStamp = await pdfDoc.embedPng(pngStampBytes); // Get the width/height of the PNG image scaled down to 50% of its original size - const pngSignDims = pngSign.scale(0.1); - const pngStampDims = pngStamp.scale(0.1); + const pngSignDims = pngSign.scale(sf); + const pngStampDims = pngStamp.scale(sf); // Add a blank page to the document const pages = pdfDoc.getPages(); @@ -41,14 +45,14 @@ const signPDF = async (sourceFile) => { // Draw the PNG image near the lower right corner of the JPG image page = pages[0]; page.drawImage(pngStamp, { - x: page.getWidth() / 2 - pngStampDims.width / 2 + 75, - y: page.getHeight() / 2 - pngStampDims.height, + x: page.getWidth() / 2 - pngStampDims.width / 2 + x, + y: page.getHeight() / 2 - pngStampDims.height + y, width: pngStampDims.width, height: pngStampDims.height, }); page.drawImage(pngSign, { - x: page.getWidth() / 2 - pngSignDims.width / 2 + 75, - y: page.getHeight() / 2 - pngSignDims.height, + x: page.getWidth() / 2 - pngSignDims.width / 2 + x, + y: page.getHeight() / 2 - pngSignDims.height + y, width: pngSignDims.width, height: pngSignDims.height, }); @@ -144,9 +148,17 @@ const fileStorageEngine = multer.diskStorage({ const upload = multer({ storage: fileStorageEngine }); router.post("/upload_files", upload.array("files"), uploadFiles); function uploadFiles(req, res) { - signPDF(req.files[0].originalname); - // console.log(req.files); - // console.log(req.files[0].toString("latin1")); + console.log(req.body); + try { + signPDF(req.files[0].originalname, { + x: parseFloat(req.body.x), + y: parseFloat(req.body.y), + sf: parseFloat(req.body.sf), + }); + } catch (error) { + res.err("Failed to parse files"); + } + res.setHeader("content-type", "text/html; charset=utf-8"); res.setHeader("Access-Control-Allow-Origin", "*"); res.json({ message: "Successfully uploaded files" }); diff --git a/Rev1/node/views/invoice_sign.pug b/Rev1/node/views/invoice_sign.pug index 343d24d..8dc0578 100644 --- a/Rev1/node/views/invoice_sign.pug +++ b/Rev1/node/views/invoice_sign.pug @@ -5,8 +5,8 @@ block content .row .col-sm-8 h3 Invoice Signer - .progress - .progress-bar.progress-bar-animated.progress-bar-striped(role="progressbar",aria-valuenow="30",aria-valuemin="0",aria-valuemax="100",style="width: 25%") + //- .progress + //- .progress-bar.progress-bar-animated.progress-bar-striped(role="progressbar",aria-valuenow="30",aria-valuemin="0",aria-valuemax="100",style="width: 25%") form#form .m-3 label.form-label.file-upload-wrapper(for='formFile') Choose a file to embed an image @@ -25,7 +25,7 @@ block content input#ypos.form-control(type="number",required='',value="50") .col label(for="scalefactor") Scale Factor - input#sf.form-control(type="number",required='',value="1.0") + input#sf.form-control(type="number",required='', step="0.001",value="0.5") .m-3.text-start button.btn.btn-primary(type="submit") Confirm .col-sm-4