Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdflibAddPlaceholder not working TypeError: fields.push is not a function #275

Open
jdelos opened this issue Nov 14, 2024 · 0 comments
Open

Comments

@jdelos
Copy link

jdelos commented Nov 14, 2024

Cannot add sing-placeholder in the pdf
A clear and concise description of what the bug is.

Output

 /@signpdf/placeholder-pdf-lib/dist/pdflibAddPlaceholder.js:174
  fields.push(widgetDictRef);

Using you example and does not wor

import  fs from 'fs';
import   path  from 'path';
import { fileURLToPath } from 'url'
import { PDFDocument } from 'pdf-lib';
import { pdflibAddPlaceholder } from '@signpdf/placeholder-pdf-lib';
import  signpdf  from '@signpdf/signpdf';
import  { P12Signer }  from '@signpdf/signer-p12';
const __dirname = fileURLToPath(new URL('.', import.meta.url))


function work() {
    // contributing.pdf is the file that is going to be signed
    var sourcePath = path.join(__dirname,'../documents/EPOS-en.pdf');
    var pdfBuffer = fs.readFileSync(sourcePath);
    console.log("Correct inputs",sourcePath,pdfBuffer)
    // certificate.p12 is the certificate that is going to be used to sign
    var certificatePath = path.join(__dirname,'../documents/signing-certificate.p12');
    var certificateBuffer = fs.readFileSync(certificatePath);
    var signer = new P12Signer(certificateBuffer);

    // Load the document into PDF-LIB
    PDFDocument.load(pdfBuffer).then(function (pdfDoc) {
        // Add a placeholder for a signature.
        pdflibAddPlaceholder({
            pdfDoc: pdfDoc,
            reason: 'The user is declaring consent through JavaScript.',
            contactInfo: 'signpdf@example.com',
            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)
                .then(function (signedPdf) {
                    // signedPdf is a Buffer of an electronically signed PDF. Store it.
                    var targetPath = path.join(__dirname,'./pdf-lib.pdf');
                    fs.writeFileSync(targetPath, signedPdf);
                })
        })
    })
}

work();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant