Comments (1)
I think the check of the P12Signer
is a bit too strict, but the issue is that the pdfDoc.save()
method is returning a UInt8Array
instead of a Buffer
. You can fix this like so:
async signPdf3(uploadPath, fileName) {
const PDFDocument = require('pdf-lib').PDFDocument;
const pdflibAddPlaceholder = require('@signpdf/placeholder-pdf-lib').pdflibAddPlaceholder;
const signpdf = require('@signpdf/signpdf').default;
const P12Signer = require('@signpdf/signer-p12').P12Signer;
// contributing.pdf is the file that is going to be signed
const sourcePath = path.join(uploadPath, fileName);
const pdfBuffer = fs.readFileSync(sourcePath);
// certificate.p12 is the certificate that is going to be used to sign
const certificatePath = path.join(__dirname, './allInOne2.p12');
const certificateBuffer = fs.readFileSync(certificatePath);
const signer = new P12Signer(certificateBuffer);
// Load the document into PDF-LIB
PDFDocument.load(pdfBuffer).then(function(pdfDoc) {
// Add a placeholder for a signature.
pdflibAddPlaceholder({
pdfDoc,
reason: 'The user is declaring consent through JavaScript.',
contactInfo: '[email protected]',
name: 'John Doe',
location: 'Free Text Str., Free World',
});
// Get the modified PDFDocument bytes
pdfDoc.save().then(function(pdfWithPlaceholderBytes) {
// And finally sign the document.
signpdf
- .sign(pdfWithPlaceholderBytes, signer)
+ .sign(Buffer.from(pdfWithPlaceholderBytes), signer)
.then(function(signedPdf) {
// signedPdf is a Buffer of an electronically signed PDF. Store it.
const targetPath = path.join(uploadPath, fileName);
fs.writeFileSync(targetPath, signedPdf);
console.log('删除陈工3243434');
});
});
});
},
from node-signpdf.
Related Issues (20)
- Node requirement is set to 12. Needs an update
- Add a signature box to the signed pdf HOT 8
- 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
- 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
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.