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 e63253e commit 5398400
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/placeholder-pdf-lib/dist/pdflibAddPlaceholder.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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;
Expand Down

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

15 changes: 8 additions & 7 deletions packages/placeholder-pdf-lib/dist/pdflibAddPlaceholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ 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
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 5398400

Please sign in to comment.