Skip to content

Commit

Permalink
📦 [placeholder-pdf-lib]
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuch committed Nov 13, 2023
1 parent f5bbae0 commit d14d172
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
10 changes: 7 additions & 3 deletions packages/placeholder-pdf-lib/dist/pdflibAddPlaceholder.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
export function pdflibAddPlaceholder({ pdfDoc, reason, contactInfo, name, location, signatureLength, byteRangePlaceholder, subFilter, widgetRect, }: InputType): void;
export type PDFDocumentFactory = import('pdf-lib').PDFDocumentFactory;
export type PDFDocument = import('pdf-lib').PDFDocument;
export type InputType = {
pdfDoc: any;
pdfDoc: PDFDocument;
reason: string;
contactInfo: string;
name: string;
location: string;
signatureLength?: number;
byteRangePlaceholder?: string;
/**
* One of SUBFILTER_* from
* One of SUBFILTER_* from \@signpdf/utils
*/
subFilter?: string;
/**
* [x1, y1, x2, y2] widget rectangle
*/
widgetRect?: number[];
};
//# sourceMappingURL=pdflibAddPlaceholder.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions packages/placeholder-pdf-lib/dist/pdflibAddPlaceholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ exports.pdflibAddPlaceholder = void 0;
var _utils = require("@signpdf/utils");
var _pdfLib = require("pdf-lib");
/**
* @typedef {import('pdf-lib').PDFDocumentFactory} PDFDocumentFactory
* @typedef {import('pdf-lib').PDFDocument} PDFDocument
*/

/**
* @typedef {object} InputType
* @property {PDFDocumentFactory} pdfDoc
* @property {PDFDocument} pdfDoc
* @property {string} reason
* @property {string} contactInfo
* @property {string} name
* @property {string} location
* @property {number} [signatureLength]
* @property {string} [byteRangePlaceholder]
* @property {string} [subFilter] One of SUBFILTER_* from @signpdf/utils
* @property {string} [subFilter] One of SUBFILTER_* from \@signpdf/utils
* @property {number[]} [widgetRect] [x1, y1, x2, y2] widget rectangle
*/

Expand Down Expand Up @@ -69,6 +69,7 @@ const pdflibAddPlaceholder = ({
Name: _pdfLib.PDFString.of(name),
Location: _pdfLib.PDFString.of(location)
}, pdfDoc.index);
const signatureDictRef = pdfDoc.context.register(signatureDict);

// Create the signature widget
const rect = _pdfLib.PDFArray.withContext(pdfDoc.context);
Expand All @@ -78,19 +79,19 @@ const pdflibAddPlaceholder = ({
Subtype: 'Widget',
FT: 'Sig',
Rect: rect,
V: signatureDict,
V: signatureDictRef,
T: _pdfLib.PDFString.of('Signature1'),
F: 4,
F: _utils.ANNOTATION_FLAGS.PRINT,
P: pages[0].ref
}, pdfDoc.index);
const widgetDictRef = pdfDoc.context.register(widgetDict);

// Annotate the widget
// Annotate the widget on the first page
pages[0].node.set(_pdfLib.PDFName.of('Annots'), pdfDoc.context.obj([widgetDictRef]));

// Reference the widget in the AcroForm
// Reference the widget in the a new AcroForm
pdfDoc.catalog.set(_pdfLib.PDFName.of('AcroForm'), pdfDoc.context.obj({
SigFlags: 3,
SigFlags: _utils.SIG_FLAGS.SIGNATURES_EXIST | _utils.SIG_FLAGS.APPEND_ONLY,
Fields: [widgetDictRef]
}));
};
Expand Down

0 comments on commit d14d172

Please sign in to comment.