Simple Example Sign PDF

See original GitHub issue

I don’t know, why You not create simple example for this library? Not all users know how use this library…

  1. How to import Your library? especially plainAddPlaceholder
  2. How create p12 certificate?
  3. How write signed pdf to file?
  4. How change “Signed by signedpdf signpdf@example.com” in pdf file?

I read this README, but You only reference code tester I have look at issue but You not clear answer, for example (https://github.com/vbuch/node-signpdf/issues/126), but You not answer with clear answer 😦 You may need to add add 'dist' to the import path. something like 'node-sginpdf/dist/helpers/plainAddPlaceholder' why You dont answer with const { plainAddPlaceholder } = require('node-signpdf/dist/helpers'); I have googling but I don’t get anything that help me

For other, if You confuse, You can read this simple example

const signer = require('node-signpdf').default
const fs = require('fs')
const { plainAddPlaceholder } = require('node-signpdf/dist/helpers');

const pdfSignedPath = `./signed.pdf`;
const pdfBuffer = fs.readFileSync(`./source.pdf`);
const certBuffer = fs.readFileSync(`./certificate.p12`);

let inputBuffer = plainAddPlaceholder({
    pdfBuffer,
    reason: 'Signed Certificate.',
    contactInfo: 'sign@example.com',
    name: 'Example',
    location: 'Jakarta',
    signatureLength: certBuffer.length,
});

const signedPdf = signer.sign(
  inputBuffer,
  certBuffer,
  { asn1StrictParsing : true },
);

fs.writeFileSync(pdfSignedPath, signedPdf);

source.pdf is file pdf that will signed signed.pdf is target of signed file certificate.p12 is Your certificate, generate this with openssl or You can use sample in folder ‘resources’ of this library

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
christianledgardcommented, Apr 20, 2022

¡Hello! I’m getting the following error while trying to run @hscstudio and @fdimarh example:

throw new _SignPdfError.default(`Expected xref at ${position} but found other content.`, _SignPdfError.default.TYPE_PARSE);
            ^

SignPdfError: Expected xref at NaN but found other content.
    at getXref`

¿What am I missing?

Screen Shot 2022-04-19 at 19 47 36

I tried to run it locally, and I got the same error message. Here is the Replit Link where you can reproduce the issue. Thank you for the help!

1reaction
fdimarhcommented, Mar 12, 2022

Maybe this snippet code will help you get better understanding to signing PDF with this library

import { SignPdf } from 'node-signpdf';
import fs from 'fs';
import { Buffer } from 'buffer';
import { plainAddPlaceholder } from 'node-signpdf/dist/helpers/index.js';

const pathSignedPdf = 'path/to/your/signed.pdf'
const p12Buffer = fs.readFileSync('path/to/your/certificate.p12');
const pdfBuffer = fs.readFileSync('path/to/your/file/need/to/sign.pdf');
const pdfBufferToSign = plainAddPlaceholder({
    pdfBuffer
});
const signer = new SignPdf()
const signedPdf = signer.sign(pdfBufferToSign, p12Buffer, { passphrase: 'your/passphrase' });
const bufferPdf = Buffer.from(signedPdf)

fs.createWriteStream(pathSignedPdf).write(bufferPdf);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Signed PDF Files - Tecxoft TSA
Sample PDF Files. Sample digitally signed files showing variations of digital signatures. To test a PDF visible and invisible signature, test sign PDF....
Read more >
How to Create a Digital Signature for PDF
Enter your password in the prompt (i.e., the one you entered earlier), then click the “Sign” button to place your digital signature on...
Read more >
Signing PDFs in Adobe Acrobat
Open the PDF document or form that you want to sign. · Click the Sign icon in the toolbar. · The Fill &...
Read more >
PDF Digital Signature | GemBox.Presentation Example
Shows how to digitally sign a generated PDF file using GemBox. ... in the preceding examples are part of a simple Public Key...
Read more >
How to Sign a PDF Form
Open the PDF document or form that you want to sign. 2. Click the Sign icon ... an example of the Signature panel....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found