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 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++) {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -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);
|
||||
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" });
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user