backup
This commit is contained in:
1 parent
9368202494
commit
d0aafe80be
5 files changed
+28
-16
No files matched your search
@@ -13,9 +13,9 @@ function submitForm(e) {
|
|||||||
const ypos = document.getElementById("ypos");
|
const ypos = document.getElementById("ypos");
|
||||||
const sf = document.getElementById("sf");
|
const sf = document.getElementById("sf");
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("xpos", xpos.value);
|
formData.append("x", parseFloat(xpos.value));
|
||||||
formData.append("ypos", ypos.value);
|
formData.append("y", parseFloat(ypos.value));
|
||||||
formData.append("sf", sf.value);
|
formData.append("sf", parseFloat(sf.value));
|
||||||
formData.append("files", mainFile.files[0]);
|
formData.append("files", mainFile.files[0]);
|
||||||
console.log(mainFile.files[0]);
|
console.log(mainFile.files[0]);
|
||||||
for (let i = 0; i < imgFiles.files.length; i++) {
|
for (let i = 0; i < imgFiles.files.length; i++) {
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -19,21 +19,25 @@ const orderReccentFiles = (dir) => {
|
|||||||
|
|
||||||
const { PDFDocument } = require("pdf-lib");
|
const { PDFDocument } = require("pdf-lib");
|
||||||
|
|
||||||
const signPDF = async (sourceFile) => {
|
const signPDF = async (sourceFile, { x = 0, y = 0, sf = 1.0 }) => {
|
||||||
// Fetch PNG image
|
// Fetch PNG image
|
||||||
const pngUrl = signDir;
|
const pngUrl = signDir;
|
||||||
const pngSignBytes = fs.readFileSync(signDir);
|
const pngSignBytes = fs.readFileSync(signDir);
|
||||||
const pngStampBytes = fs.readFileSync(stampDir);
|
const pngStampBytes = fs.readFileSync(stampDir);
|
||||||
|
try {
|
||||||
const pBytes = fs.readFileSync(rawDir + sourceFile);
|
const pBytes = fs.readFileSync(rawDir + sourceFile);
|
||||||
const pdfDoc = await PDFDocument.load(pBytes);
|
const pdfDoc = await PDFDocument.load(pBytes);
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
// Embed the JPG image bytes and PNG image bytes
|
// Embed the JPG image bytes and PNG image bytes
|
||||||
const pngSign = await pdfDoc.embedPng(pngSignBytes);
|
const pngSign = await pdfDoc.embedPng(pngSignBytes);
|
||||||
const pngStamp = await pdfDoc.embedPng(pngStampBytes);
|
const pngStamp = await pdfDoc.embedPng(pngStampBytes);
|
||||||
|
|
||||||
// Get the width/height of the PNG image scaled down to 50% of its original size
|
// Get the width/height of the PNG image scaled down to 50% of its original size
|
||||||
const pngSignDims = pngSign.scale(0.1);
|
const pngSignDims = pngSign.scale(sf);
|
||||||
const pngStampDims = pngStamp.scale(0.1);
|
const pngStampDims = pngStamp.scale(sf);
|
||||||
|
|
||||||
// Add a blank page to the document
|
// Add a blank page to the document
|
||||||
const pages = pdfDoc.getPages();
|
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
|
// Draw the PNG image near the lower right corner of the JPG image
|
||||||
page = pages[0];
|
page = pages[0];
|
||||||
page.drawImage(pngStamp, {
|
page.drawImage(pngStamp, {
|
||||||
x: page.getWidth() / 2 - pngStampDims.width / 2 + 75,
|
x: page.getWidth() / 2 - pngStampDims.width / 2 + x,
|
||||||
y: page.getHeight() / 2 - pngStampDims.height,
|
y: page.getHeight() / 2 - pngStampDims.height + y,
|
||||||
width: pngStampDims.width,
|
width: pngStampDims.width,
|
||||||
height: pngStampDims.height,
|
height: pngStampDims.height,
|
||||||
});
|
});
|
||||||
page.drawImage(pngSign, {
|
page.drawImage(pngSign, {
|
||||||
x: page.getWidth() / 2 - pngSignDims.width / 2 + 75,
|
x: page.getWidth() / 2 - pngSignDims.width / 2 + x,
|
||||||
y: page.getHeight() / 2 - pngSignDims.height,
|
y: page.getHeight() / 2 - pngSignDims.height + y,
|
||||||
width: pngSignDims.width,
|
width: pngSignDims.width,
|
||||||
height: pngSignDims.height,
|
height: pngSignDims.height,
|
||||||
});
|
});
|
||||||
@@ -144,9 +148,17 @@ const fileStorageEngine = multer.diskStorage({
|
|||||||
const upload = multer({ storage: fileStorageEngine });
|
const upload = multer({ storage: fileStorageEngine });
|
||||||
router.post("/upload_files", upload.array("files"), uploadFiles);
|
router.post("/upload_files", upload.array("files"), uploadFiles);
|
||||||
function uploadFiles(req, res) {
|
function uploadFiles(req, res) {
|
||||||
signPDF(req.files[0].originalname);
|
console.log(req.body);
|
||||||
// console.log(req.files);
|
try {
|
||||||
// console.log(req.files[0].toString("latin1"));
|
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("content-type", "text/html; charset=utf-8");
|
||||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
res.json({ message: "Successfully uploaded files" });
|
res.json({ message: "Successfully uploaded files" });
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ block content
|
|||||||
.row
|
.row
|
||||||
.col-sm-8
|
.col-sm-8
|
||||||
h3 Invoice Signer
|
h3 Invoice Signer
|
||||||
.progress
|
//- .progress
|
||||||
.progress-bar.progress-bar-animated.progress-bar-striped(role="progressbar",aria-valuenow="30",aria-valuemin="0",aria-valuemax="100",style="width: 25%")
|
//- .progress-bar.progress-bar-animated.progress-bar-striped(role="progressbar",aria-valuenow="30",aria-valuemin="0",aria-valuemax="100",style="width: 25%")
|
||||||
form#form
|
form#form
|
||||||
.m-3
|
.m-3
|
||||||
label.form-label.file-upload-wrapper(for='formFile') Choose a file to embed an image
|
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")
|
input#ypos.form-control(type="number",required='',value="50")
|
||||||
.col
|
.col
|
||||||
label(for="scalefactor") Scale Factor
|
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
|
.m-3.text-start
|
||||||
button.btn.btn-primary(type="submit") Confirm
|
button.btn.btn-primary(type="submit") Confirm
|
||||||
.col-sm-4
|
.col-sm-4
|
||||||
|
|||||||
Reference in new issue
Block a user