chunyenHuang / hummusRecipe

A powerful PDF tool for NodeJS based on HummusJS.
https://hummus-recipe.s3.amazonaws.com/docs/Recipe.html
MIT License
340 stars 91 forks source link

Set root/catalog "AcroForm" object and reference to widget #63

Open ssleptsov opened 5 years ago

ssleptsov commented 5 years ago

I'm trying to convert this code from pdfkit to hummusRecipe. And I can't find a way to set a AcroForm and add widget/sig. Do you have any suggestion? Thanks!

` const signature = pdf.ref({ Type: 'Sig', Filter: 'Adobe.PPKLite', SubFilter: 'adbe.pkcs7.detached', ByteRange: [ 0, DEFAULT_BYTE_RANGE_PLACEHOLDER, DEFAULT_BYTE_RANGE_PLACEHOLDER, DEFAULT_BYTE_RANGE_PLACEHOLDER, ], Contents: Buffer.from(String.fromCharCode(0).repeat(signatureLength)), Reason: new String(reason), // eslint-disable-line no-new-wrappers M: new Date(), });

// Generate signature annotation widget
const widget = pdf.ref({
    Type: 'Annot',
    Subtype: 'Widget',
    FT: 'Sig',
    Rect: [0, 0, 0, 0],
    V: signature,
    T: new String('Signature1'), // eslint-disable-line no-new-wrappers
    F: 4,
    P: pdf._root.data.Pages.data.Kids[0], // eslint-disable-line no-underscore-dangle
});
// Include the widget in a page
pdf._root.data.Pages.data.Kids[0].data.Annots = [widget];

// Create a form (with the widget) and link in the _root
const form = pdf.ref({
    SigFlags: 3,
    Fields: [widget],
});
pdf._root.data.AcroForm = form;

`

chunyenHuang commented 5 years ago

Hello @ssleptsov I am sorry that hummusRecipe only supports certain annotations now https://chunyenhuang.github.io/hummusRecipe/Recipe.html#.annot

You may fork and hack the code for different annotations here https://github.com/chunyenHuang/hummusRecipe/blob/master/lib/annotation.js#L59

I will consider to add the support for your case. Thanks for asking.

sourav-prescriber-360 commented 5 years ago

Do we have any update on this. I am also trying to add the same Signature Widget so that I can digitally sign it using node-signpdf

john-attrium-204 commented 5 years ago

Do we have any update on this. I am also trying to add the same Signature Widget so that I can digitally sign it using node-signpdf

Have you done with your task of signing a pdf ?