Comments (2)
UPDATE :
On adding the visual tag implementation I tried to solve the issue but it still remains same no green tick.
const multer = require("multer");
const fs = require("fs");
const path = require("path");
const signpdf = require("@signpdf/signpdf").default;
const { P12Signer } = require("@signpdf/signer-p12");
const { pdflibAddPlaceholder } = require("@signpdf/placeholder-pdf-lib");
const { PDFDocument, rgb, StandardFonts } = require("pdf-lib");
// const { SUBFILTER_ETSI_CADES_DETACHED } = require("@signpdf/utils");
const storage = multer.diskStorage({
destination: "uploads/",
filename: function (req, file, cb) {
cb(
null,
file.fieldname + "-" + Date.now() + path.extname(file.originalname)
);
},
});
function topLeftToBottomLeft(coords, page) {
const pageHeight = page.getHeight();
return [
coords[0],
pageHeight - coords[1],
coords[2], // x2
pageHeight - coords[3],
];
}
async function addVisual(pdfDoc) {
const page = pdfDoc.getPages()[0]; // Get the first page
var margin = 30;
var padding = 10;
var label = "Signed with @signpdf";
const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica);
const fontSize = 10;
const x = page.getWidth() - margin;
const y = page.getHeight() - margin;
page.drawText(label, {
x: x,
y: y,
size: fontSize,
font: helveticaFont,
color: rgb(0, 0, 0),
});
return [
x - padding,
y - padding,
x + fontSize + padding,
y + fontSize + padding,
];
}
exports.upload = multer({ storage: storage }).single("file");
exports.signDocument = async (req, res, next) => {
try {
const pdfPath = req.file.path;
const pfxPath = "assets/docsinger.pfx";
const password = "Mawai@123";
let pdfBuffer, signedPdfBuffer;
pdfBuffer = fs.readFileSync(pdfPath);
let pfxBuffer = fs.readFileSync(pfxPath);
let pdfDoc = await PDFDocument.load(pdfBuffer);
const page = pdfDoc.getPages()[0];
const widgetRect = await addVisual(pdfDoc);
pdflibAddPlaceholder({
pdfDoc,
pdfBuffer,
reason: "SwiftDocuSign",
contactInfo: "[email protected]",
name: "Jeba Prince",
location: "SwiftDocuSign",
date: new Date(),
signatureLength: 15000,
widgetRect: topLeftToBottomLeft(widgetRect, page),
});
let pdfBufferWithPlaceholder = Buffer.from(await pdfDoc.save());
const p12Signer = new P12Signer(pfxBuffer, {
passphrase: password,
});
try {
signedPdfBuffer = await signpdf.sign(pdfBufferWithPlaceholder, p12Signer);
console.log("Signing done!");
} catch (error) {
throw new Error(error);
}
try {
fs.writeFileSync(pdfPath, signedPdfBuffer);
} catch (error) {
throw new Error("Failed to write signed PDF to file");
}
// Send response
res.status(200).send({
success: true,
message: "PDF signed successfully",
});
} catch (error) {
// Handle errors
console.error("Error signing PDF:", error);
res.status(500).send({
success: false,
error: error.message,
});
}
};
from node-signpdf.
https://stackoverflow.com/a/40391641/2528232
from node-signpdf.
Related Issues (20)
- Signer implementation expected using 3.2.3 HOT 1
- Issue with PFX HOT 2
- Unable to sign using a p12 certificate - Error: Only 8, 16, 24, or 32 bits supported: 320 HOT 1
- Build fails because of missing type HOT 1
- Appending remote PADES signatures HOT 5
- Make Pades sign ETSI compliant HOT 1
- TypeError: pdf.ref is not a function HOT 1
- placeholder-pdfkit stops the pdf stream emitting the "end" event HOT 5
- PKCS#12 MAC could not be verified. Invalid password? HOT 1
- Could not resolve dependency with [email protected] HOT 2
- PDF expected as Buffer. HOT 1
- Run-time compatibility HOT 6
- Error when trying to sign a pdf document when using @signpdf module HOT 1
- error open with adobe reader HOT 1
- Error when using node JS pdf-lib: Expected xref at NaN but found other content
- How can fields of placeholder be visible. HOT 19
- Illegal values in ByteRange array/ Signature has not yet been verified
- Angular 17: Buffer is not defined
- Can't deploy on mongo.db using mexc-sdk js HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-signpdf.