From e9f5625a5fb48eb9211a826f9cce8e35ae7b186e Mon Sep 17 00:00:00 2001 From: Valery Buchinsky Date: Fri, 3 Nov 2023 12:03:13 +0200 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=99=88=20Keep=20the=20/out/=20folder,?= =?UTF-8?q?=20ignore=20its=20contents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 361c6756..42ceaaf4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ yarn-error.log* coverage .coveralls.yml -packages/examples/output +packages/examples/output/* node_modules/ .npm From 3614fc51d7874f2cb1e5fe2022e64fb9faadf948 Mon Sep 17 00:00:00 2001 From: Valery Buchinsky Date: Fri, 3 Nov 2023 12:05:43 +0200 Subject: [PATCH 2/6] =?UTF-8?q?=E2=9C=A8=20Allow=20passing=20widget=20dime?= =?UTF-8?q?nsins=20to=20placeholder=20helpers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts | 8 ++++++-- .../dist/pdfkitAddPlaceholder.d.ts.map | 2 +- .../placeholder-pdfkit010/dist/pdfkitAddPlaceholder.js | 8 +++++--- .../placeholder-pdfkit010/src/pdfkitAddPlaceholder.js | 6 ++++-- packages/placeholder-plain/dist/plainAddPlaceholder.d.ts | 8 ++++++-- .../placeholder-plain/dist/plainAddPlaceholder.d.ts.map | 2 +- packages/placeholder-plain/dist/plainAddPlaceholder.js | 9 ++++++--- packages/placeholder-plain/src/plainAddPlaceholder.js | 5 ++++- 8 files changed, 33 insertions(+), 15 deletions(-) diff --git a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts index 92b6a0bd..1e24dff0 100644 --- a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts +++ b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts @@ -1,4 +1,4 @@ -export function pdfkitAddPlaceholder({ pdf, pdfBuffer, reason, contactInfo, name, location, signatureLength, byteRangePlaceholder, subFilter, }: InputType): ReturnType; +export function pdfkitAddPlaceholder({ pdf, pdfBuffer, reason, contactInfo, name, location, signatureLength, byteRangePlaceholder, subFilter, widgetRect, }: InputType): ReturnType; export type InputType = { /** * PDFDocument @@ -12,9 +12,13 @@ export type InputType = { signatureLength?: number; byteRangePlaceholder?: string; /** - * One of SUBFILTER_* from + * One of SUBFILTER_* from \@signpdf/utils */ subFilter?: string; + /** + * [x1, y1, x2, y2] widget rectangle + */ + widgetRect?: number[]; }; export type ReturnType = { signature: any; diff --git a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts.map b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts.map index c519e497..f4604ecd 100644 --- a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts.map +++ b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"pdfkitAddPlaceholder.d.ts","sourceRoot":"","sources":["../src/pdfkitAddPlaceholder.js"],"names":[],"mappings":"AAqCO,iJAHI,SAAS,GACP,UAAU,CAkHtB;;;;;SAzIY,MAAM;eACN,MAAM;YACN,MAAM;iBACN,MAAM;UACN,MAAM;cACN,MAAM;sBACN,MAAM;2BACN,MAAM;;;;gBACN,MAAM;;;eAKN,GAAG;UACH,GAAG;YACH,GAAG"} \ No newline at end of file +{"version":3,"file":"pdfkitAddPlaceholder.d.ts","sourceRoot":"","sources":["../src/pdfkitAddPlaceholder.js"],"names":[],"mappings":"AAsCO,6JAHI,SAAS,GACP,UAAU,CAmHtB;;;;;SA3IY,MAAM;eACN,MAAM;YACN,MAAM;iBACN,MAAM;UACN,MAAM;cACN,MAAM;sBACN,MAAM;2BACN,MAAM;;;;gBACN,MAAM;;;;iBACN,MAAM,EAAE;;;eAKR,GAAG;UACH,GAAG;YACH,GAAG"} \ No newline at end of file diff --git a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.js b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.js index 8d443d8f..88d3a63d 100644 --- a/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.js +++ b/packages/placeholder-pdfkit010/dist/pdfkitAddPlaceholder.js @@ -18,7 +18,8 @@ var _pdfkitReferenceMock = require("./pdfkitReferenceMock"); * @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 */ /** @@ -44,7 +45,8 @@ const pdfkitAddPlaceholder = ({ location, signatureLength = _utils.DEFAULT_SIGNATURE_LENGTH, byteRangePlaceholder = _utils.DEFAULT_BYTE_RANGE_PLACEHOLDER, - subFilter = _utils.SUBFILTER_ADOBE_PKCS7_DETACHED + subFilter = _utils.SUBFILTER_ADOBE_PKCS7_DETACHED, + widgetRect = [0, 0, 0, 0] }) => { /* eslint-disable no-underscore-dangle,no-param-reassign */ // Generate the signature placeholder @@ -105,7 +107,7 @@ const pdfkitAddPlaceholder = ({ Type: 'Annot', Subtype: 'Widget', FT: 'Sig', - Rect: [0, 0, 0, 0], + Rect: widgetRect, V: signature, T: new String(signatureName + (fieldIds.length + 1)), // eslint-disable-line no-new-wrappers diff --git a/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js b/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js index 81e4c1cd..cc3524bb 100644 --- a/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js +++ b/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.js @@ -18,7 +18,8 @@ import {PDFKitReferenceMock} from './pdfkitReferenceMock'; * @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 */ /** @@ -45,6 +46,7 @@ export const pdfkitAddPlaceholder = ({ signatureLength = DEFAULT_SIGNATURE_LENGTH, byteRangePlaceholder = DEFAULT_BYTE_RANGE_PLACEHOLDER, subFilter = SUBFILTER_ADOBE_PKCS7_DETACHED, + widgetRect = [0, 0, 0, 0], }) => { /* eslint-disable no-underscore-dangle,no-param-reassign */ // Generate the signature placeholder @@ -114,7 +116,7 @@ export const pdfkitAddPlaceholder = ({ Type: 'Annot', Subtype: 'Widget', FT: 'Sig', - Rect: [0, 0, 0, 0], + Rect: widgetRect, V: signature, T: new String(signatureName + (fieldIds.length + 1)), // eslint-disable-line no-new-wrappers F: ANNOTATION_FLAGS.PRINT, diff --git a/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts b/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts index a00eea4d..10320769 100644 --- a/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts +++ b/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts @@ -1,4 +1,4 @@ -export function plainAddPlaceholder({ pdfBuffer, reason, contactInfo, name, location, signatureLength, subFilter, }: InputType): Buffer; +export function plainAddPlaceholder({ pdfBuffer, reason, contactInfo, name, location, signatureLength, subFilter, widgetRect, }: InputType): Buffer; export type InputType = { pdfBuffer: Buffer; reason: string; @@ -7,8 +7,12 @@ export type InputType = { location: string; signatureLength?: number; /** - * One of SUBFILTER_* from + * One of SUBFILTER_* from \@signpdf/utils */ subFilter?: string; + /** + * [x1, y1, x2, y2] widget rectangle + */ + widgetRect?: number[]; }; //# sourceMappingURL=plainAddPlaceholder.d.ts.map \ No newline at end of file diff --git a/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts.map b/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts.map index 26500ca9..e40bbc1e 100644 --- a/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts.map +++ b/packages/placeholder-plain/dist/plainAddPlaceholder.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"plainAddPlaceholder.d.ts","sourceRoot":"","sources":["../src/plainAddPlaceholder.js"],"names":[],"mappings":"AAwDO,qHAHI,SAAS,GACP,MAAM,CA2FlB;;eA9GY,MAAM;YACN,MAAM;iBACN,MAAM;UACN,MAAM;cACN,MAAM;sBACN,MAAM;;;;gBACN,MAAM"} \ No newline at end of file +{"version":3,"file":"plainAddPlaceholder.d.ts","sourceRoot":"","sources":["../src/plainAddPlaceholder.js"],"names":[],"mappings":"AAyDO,iIAHI,SAAS,GACP,MAAM,CA6FlB;;eAjHY,MAAM;YACN,MAAM;iBACN,MAAM;UACN,MAAM;cACN,MAAM;sBACN,MAAM;;;;gBACN,MAAM;;;;iBACN,MAAM,EAAE"} \ No newline at end of file diff --git a/packages/placeholder-plain/dist/plainAddPlaceholder.js b/packages/placeholder-plain/dist/plainAddPlaceholder.js index 8022c336..39015ae5 100644 --- a/packages/placeholder-plain/dist/plainAddPlaceholder.js +++ b/packages/placeholder-plain/dist/plainAddPlaceholder.js @@ -36,7 +36,8 @@ const getAcroFormRef = slice => { * @property {string} name * @property {string} location * @property {number} [signatureLength] -* @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 */ /** @@ -58,7 +59,8 @@ const plainAddPlaceholder = ({ name, location, signatureLength = _utils.DEFAULT_SIGNATURE_LENGTH, - subFilter = _utils.SUBFILTER_ADOBE_PKCS7_DETACHED + subFilter = _utils.SUBFILTER_ADOBE_PKCS7_DETACHED, + widgetRect = [0, 0, 0, 0] }) => { let pdf = (0, _utils.removeTrailingNewLine)(pdfBuffer); const info = (0, _readPdf.default)(pdf); @@ -100,7 +102,8 @@ const plainAddPlaceholder = ({ name, location, signatureLength, - subFilter + subFilter, + widgetRect }); if (!getAcroFormRef(pdf.toString())) { const rootIndex = (0, _getIndexFromRef.default)(info.xref, info.rootRef); diff --git a/packages/placeholder-plain/src/plainAddPlaceholder.js b/packages/placeholder-plain/src/plainAddPlaceholder.js index 94e73d18..67ef3d4b 100644 --- a/packages/placeholder-plain/src/plainAddPlaceholder.js +++ b/packages/placeholder-plain/src/plainAddPlaceholder.js @@ -39,7 +39,8 @@ const getAcroFormRef = (slice) => { * @property {string} name * @property {string} location * @property {number} [signatureLength] -* @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 */ /** @@ -62,6 +63,7 @@ export const plainAddPlaceholder = ({ location, signatureLength = DEFAULT_SIGNATURE_LENGTH, subFilter = SUBFILTER_ADOBE_PKCS7_DETACHED, + widgetRect = [0, 0, 0, 0], }) => { let pdf = removeTrailingNewLine(pdfBuffer); const info = readPdf(pdf); @@ -118,6 +120,7 @@ export const plainAddPlaceholder = ({ location, signatureLength, subFilter, + widgetRect, }); if (!getAcroFormRef(pdf.toString())) { From f3afac8882fee0040da29441870fa22765fc2fe7 Mon Sep 17 00:00:00 2001 From: Valery Buchinsky Date: Fri, 3 Nov 2023 12:06:33 +0200 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=93=9D=20[examples]=20Create=20an=20e?= =?UTF-8?q?xample=20of=20a=20visible=20signature=20widget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../examples/src/pdfkit010-with-visual.js | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 packages/examples/src/pdfkit010-with-visual.js diff --git a/packages/examples/src/pdfkit010-with-visual.js b/packages/examples/src/pdfkit010-with-visual.js new file mode 100644 index 00000000..0dd46ba7 --- /dev/null +++ b/packages/examples/src/pdfkit010-with-visual.js @@ -0,0 +1,130 @@ +var fs = require('fs'); +var path = require('path'); +var PDFDocument = require('pdfkit'); +var signpdf = require('@signpdf/signpdf').default; +var P12Signer = require('@signpdf/signer-p12').P12Signer; +var pdfkitAddPlaceholder = require('@signpdf/placeholder-pdfkit010').pdfkitAddPlaceholder; + +/** + * Transform coordinates from top/left to bottom/left coordinate system + */ +function topLeftToBottomLeft(coords, page) { + return [ + coords[0], // x1 + page.height - coords[1], // y1 + coords[2], // x2 + page.height - coords[3], // y2 + ]; +} + +function addVisual(pdf) { + // Go to first page + pdf.switchToPage(0); + + var margin = 30; + var padding = 10; + var label = 'Signed with @signpdf'; + pdf + .fillColor('#008B93') + .fontSize(10); + var text = { + width: pdf.widthOfString(label), + height: pdf.heightOfString(label) + }; + text.x = pdf.page.width - text.width - margin; + text.y = pdf.page.height - text.height - margin; + + pdf.text(label, text.x, text.y, {width: text.width, height: text.height}); + + return [ + text.x - padding, + text.y - padding, + text.x + text.width + padding, + text.y + text.height + padding, + ]; +} + +function work() { + // Start a PDFKit document + var pdf = new PDFDocument({ + autoFirstPage: false, + size: 'A4', + layout: 'portrait', + bufferPages: true, + });; + pdf.info.CreationDate = ''; + + // At the end we want to convert the PDFKit to a string/Buffer and store it in a file. + // Here is how this is going to happen: + var pdfReady = new Promise(function (resolve) { + // Collect the ouput PDF + // and, when done, resolve with it stored in a Buffer + var pdfChunks = []; + pdf.on('data', function (data) { + pdfChunks.push(data); + }); + pdf.on('end', function () { + resolve(Buffer.concat(pdfChunks)); + }); + }); + + // Add some content to the page(s) + pdf + .addPage() + .fillColor('#333') + .fontSize(25) + .moveDown() + .text('@signpdf'); + + // !!! ADDING VISUALS AND APPLYING TO SIGNATURE WIDGET ==> + + // Add a some visuals and make sure to get their dimensions. + var visualRect = addVisual(pdf); + // Convert these dimension as Widgets' (0,0) is bottom-left based while the + // rest of the coordinates on the page are top-left. + var widgetRect = topLeftToBottomLeft(visualRect, pdf.page); + + // Here comes the signing. We need to add the placeholder so that we can later sign. + var refs = pdfkitAddPlaceholder({ + pdf: pdf, + pdfBuffer: Buffer.from([pdf]), // FIXME: This shouldn't be needed. + reason: 'Showing off.', + contactInfo: 'signpdf@example.com', + name: 'Sign PDF', + location: 'The digital world.', + signatureLength: 1612, + widgetRect: widgetRect, // <== !!! This is where we tell the widget to be visible + }); + + // <== !!! ADDING VISUALS AND APPLYING TO SIGNATURE WIDGET + + // `refs` here contains PDFReference objects to signature, form and widget. + // PDFKit doesn't know much about them, so it won't .end() them. We need to do that for it. + Object.keys(refs).forEach(function (key) { + refs[key].end() + }); + + // Once we .end the PDFDocument, the `pdfReady` Promise will resolve with + // the Buffer of a PDF that has a placeholder for signature that we need. + // Other that we will also need a certificate + // certificate.p12 is the certificate that is going to be used to sign + var certificatePath = path.join(__dirname, '/../../../resources/certificate.p12'); + var certificateBuffer = fs.readFileSync(certificatePath); + var signer = new P12Signer(certificateBuffer); + + // Once the PDF is ready we need to sign it and eventually store it on disc. + pdfReady + .then(function (pdfWithPlaceholder) { + return signpdf.sign(pdfWithPlaceholder, signer); + }) + .then(function (signedPdf) { + var targetPath = path.join(__dirname, '/../output/pdfkit010-with-visual.pdf'); + fs.writeFileSync(targetPath, signedPdf); + }); + + // Finally end the PDFDocument stream. + pdf.end(); + // This has just triggered the `pdfReady` Promise to be resolved. +}; + +work(); \ No newline at end of file From 46f6adbbb80081e0a8cc3b4e2b715a49be87e130 Mon Sep 17 00:00:00 2001 From: Valery Buchinsky Date: Fri, 3 Nov 2023 13:23:38 +0200 Subject: [PATCH 4/6] =?UTF-8?q?=E2=9C=85=20[placeholder-pdfkit010]=20Test?= =?UTF-8?q?=20it=20accepts=20widgetRect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pdfkitAddPlaceholder.test.js | 54 ++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.test.js b/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.test.js index a99465e1..fef1cfd5 100644 --- a/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.test.js +++ b/packages/placeholder-pdfkit010/src/pdfkitAddPlaceholder.test.js @@ -1,4 +1,4 @@ -import {SIG_FLAGS, SUBFILTER_ETSI_CADES_DETACHED} from '@signpdf/utils'; +import {SIG_FLAGS, SUBFILTER_ADOBE_PKCS7_DETACHED, SUBFILTER_ETSI_CADES_DETACHED} from '@signpdf/utils'; import {createPdfkitDocument} from '@signpdf/internal-utils'; import {pdfkitAddPlaceholder} from './pdfkitAddPlaceholder'; import PDFObject from './pdfkit/pdfobject'; @@ -74,10 +74,10 @@ describe(pdfkitAddPlaceholder, () => { expect(pdf.page.dictionary.data.Annots[0].data.Subtype).toEqual('Widget'); const widgetData = pdf.page.dictionary.data.Annots[0].data.V.data; expect(PDFObject.convert(widgetData.Reason)).toEqual('(test reason)'); - expect(PDFObject.convert(widgetData.ContactInfo)).toEqual('(testemail@example.com)'); - expect(PDFObject.convert(widgetData.Name)).toEqual('(test name)'); - expect(PDFObject.convert(widgetData.Location)).toEqual('(test Location)'); - expect(widgetData.SubFilter).toEqual('adbe.pkcs7.detached'); + expect(PDFObject.convert(widgetData.ContactInfo)).toEqual(`(${defaults.contactInfo})`); + expect(PDFObject.convert(widgetData.Name)).toEqual(`(${defaults.name})`); + expect(PDFObject.convert(widgetData.Location)).toEqual(`(${defaults.location})`); + expect(widgetData.SubFilter).toEqual(SUBFILTER_ADOBE_PKCS7_DETACHED); }); it('allows defining signature SubFilter', () => { @@ -100,7 +100,49 @@ describe(pdfkitAddPlaceholder, () => { expect(widget.data.Subtype).toEqual('Widget'); const widgetData = widget.data.V.data; expect(PDFObject.convert(widgetData.Reason)).toEqual('(test reason)'); - expect(widgetData.SubFilter).toEqual('ETSI.CAdES.detached'); + expect(widgetData.SubFilter).toEqual(SUBFILTER_ETSI_CADES_DETACHED); + }); + + it('sets the widget rectange to invisible by default', () => { + const {pdf} = createPdfkitDocument(); + const refs = pdfkitAddPlaceholder({ + ...defaults, + pdf, + pdfBuffer: Buffer.from([pdf]), + reason: 'test reason', + }); + expect(Object.keys(refs)).toEqual(expect.arrayContaining([ + 'signature', + 'form', + 'widget', + ])); + expect(pdf.page.dictionary.data.Annots).toHaveLength(1); + const widget = pdf.page.dictionary.data.Annots[0]; + const rect = widget.data.Rect; + expect(Array.isArray(rect)).toBe(true); + expect(rect).toEqual([0, 0, 0, 0]); + }); + + it('allows defining widget rectange', () => { + const {pdf} = createPdfkitDocument(); + const widgetRect = [100, 100, 200, 200]; + const refs = pdfkitAddPlaceholder({ + ...defaults, + pdf, + pdfBuffer: Buffer.from([pdf]), + reason: 'test reason', + widgetRect, + }); + expect(Object.keys(refs)).toEqual(expect.arrayContaining([ + 'signature', + 'form', + 'widget', + ])); + expect(pdf.page.dictionary.data.Annots).toHaveLength(1); + const widget = pdf.page.dictionary.data.Annots[0]; + const rect = widget.data.Rect; + expect(Array.isArray(rect)).toBe(true); + expect(rect).toEqual(widgetRect); }); it('adds placeholder to PDFKit document when AcroForm is already there', () => { From 5901adfde78780809dacff725279631f0530a1ee Mon Sep 17 00:00:00 2001 From: Valery Buchinsky Date: Fri, 3 Nov 2023 13:28:46 +0200 Subject: [PATCH 5/6] =?UTF-8?q?=E2=9C=85=20[placeholder-plain]=20Test=20it?= =?UTF-8?q?=20respects=20widgetRect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plainAddPlaceholder.test.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/placeholder-plain/src/plainAddPlaceholder.test.js b/packages/placeholder-plain/src/plainAddPlaceholder.test.js index 9238814d..9e6ed59a 100644 --- a/packages/placeholder-plain/src/plainAddPlaceholder.test.js +++ b/packages/placeholder-plain/src/plainAddPlaceholder.test.js @@ -28,4 +28,31 @@ describe(plainAddPlaceholder, () => { expect(output).toBeInstanceOf(Buffer); expect(output.indexOf('/ByteRange', 13350)).toBe(19489); }); + + it('sets the widget rectange to invisible by default', () => { + const input = readTestResource('w3dummy.pdf'); + const output = plainAddPlaceholder({ + pdfBuffer: input, + reason: 'Because I can', + location: 'some place', + name: 'example name', + contactInfo: 'emailfromp1289@gmail.com', + }); + expect(output).toBeInstanceOf(Buffer); + expect(output.indexOf('/Rect [0 0 0 0]')).not.toBe(-1); + }); + + it('allows defining widget rectange', () => { + const input = readTestResource('w3dummy.pdf'); + const output = plainAddPlaceholder({ + pdfBuffer: input, + reason: 'Because I can', + location: 'some place', + name: 'example name', + contactInfo: 'emailfromp1289@gmail.com', + widgetRect: [100, 100, 200, 200], + }); + expect(output).toBeInstanceOf(Buffer); + expect(output.indexOf('/Rect [100 100 200 200]')).not.toBe(-1); + }); }); From 1f607b26dafbaaee718a734677f62da25d1c548b Mon Sep 17 00:00:00 2001 From: Valery Buchinsky Date: Fri, 10 Nov 2023 12:33:25 +0200 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=93=9D=20Add=20widgetRect=20changes?= =?UTF-8?q?=20in=20CHANGELOG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f04fe40f..01d3099a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,12 @@ * [utils] Added SIG_FLAGS and ANNOTATION_FLAGS to improve readability; * [utils] Reworked findByteRange to match in more cases where it was incompatible so far (it didn't allow optional spaces in the array). -* [pdfkit010] Uses SIG_FLAGS and ANNOTATION_FLAGS instead of magic numbers; +* [placeholder-pdfkit010] Uses SIG_FLAGS and ANNOTATION_FLAGS instead of magic numbers; +* [placeholder-pdfkit010] Allow passing in widgetRect to override the default [0, 0, 0, 0] one; +* [placeholder-plain] Allow passing in widgetRect to override the default [0, 0, 0, 0] one; * [signpdf] Use the BR position findByteRange provides to spare a search for it; -* Bumped version of axios +* [examples] Introduce [an example that provides a visible widget](packages/examples/src/pdfkit010-with-visual.js) (implemented with pdfkit); +* Bumped version of axios; ## [3.0.0]