-
-
Notifications
You must be signed in to change notification settings - Fork 858
Added support to only flatten some fields#1758
Added support to only flatten some fields#1758betabites wants to merge 3 commits intoHopding:masterfrom
Conversation
What?
Makes a few line changes that allow users to (optionally) only flatten some fields when flattening a PDF form.
Why?
The purpose of this is to allow some fields to be pre-filled, without fully locking out all fields.
How?
The changes in this PR are intended to build upon the existing flattening logic. In the existing logic, one of the first steps flatten() takes is to fetch all fields in the form, then iterate through them.
// ...
const fields = this.getFields(); // <-- Get all fields
for (let i = 0, lenFields = fields.length; i < lenFields; i++) { <-- Iterate through them
// ...
This PR simply allows the PDFField objects to be passed in as a part of the options argument
// ...
// If no fields were specified, recursively call this.flatten() with all fields
if (!options.fields) return this.flatten({...options, fields: this.getFields()});
// If fields were specified, process them
const fields = options.fields;
for (let i = 0, lenFields = fields.length; i < lenFields; i++) {
Testing?
The existing test cases were used. Given that this is only a 3-liner change, and doesn't really add any new features, I thought the existing tests would be enough.
I'm not able to run the integration tests due to a build error with ttypescript? Might need some help with that one...
yarn run v1.22.22
$ yarn build:cjs && yarn build:es && yarn build:esm && yarn build:esm:min && yarn build:umd && yarn build:umd:min && yarn build:downlevel-dts
$ ttsc --module commonjs --outDir cjs
C:\...\pdf-lib\node_modules\ttypescript\lib\loadTypescript.js:11
function __() { this.constructor = d; }
^
TypeError: Cannot set property constructor of [object Object] which has only a getter
at new __ (C:\...\pdf-lib\node_modules\ttypescript\lib\loadTypescript.js:11:42)
at __extends (C:\...\pdf-lib\node_modules\ttypescript\lib\loadTypescript.js:12:84)
at C:\...\pdf-lib\node_modules\ttypescript\lib\loadTypescript.js:38:5
at Object.<anonymous> (C:\...\pdf-lib\node_modules\ttypescript\lib\loadTypescript.js:73:2)
at Module._compile (node:internal/modules/cjs/loader:1730:14)
at Object..js (node:internal/modules/cjs/loader:1895:10)
at Module.load (node:internal/modules/cjs/loader:1465:32)
at Function._load (node:internal/modules/cjs/loader:1282:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
Node.js v22.15.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
New Dependencies?
No
Screenshots
N/A
Suggested Reading?
No
Anything Else?
Checklist
- I read CONTRIBUTING.md.
- I read MAINTAINERSHIP.md#pull-requests.
- I added/updated unit tests for my changes.
- I added/updated integration tests for my changes.
- I ran the integration tests.
- I tested my changes in Node, Deno, and the browser.
- I viewed documents produced with my changes in Adobe Acrobat, Foxit Reader, Firefox, and Chrome.
- I added/updated doc comments for any new/modified public APIs.
- My changes work for both new and existing PDF files.
- I ran the linter on my changes.
# src/api/form/PDFForm.ts
- SVG support (from cantoo-scribe/pdf-lib fork)
- PDF encryption/decryption (from pdf-lib-plus-encrypt fork)
- Incremental save for digital signatures (from pdf-lib-incremental-save)
- Rounded rectangles (from pdfme/pdf-lib fork)
- Hyperlinks support (PR Hopding#1691)
- Form field improvements (PRs Hopding#1748, Hopding#1758)
https://claude.ai/code/session_01T85UagjFeYdf4vUW9pzeyn
- SVG support (from cantoo-scribe/pdf-lib fork)
- PDF encryption/decryption (from pdf-lib-plus-encrypt fork)
- Incremental save for digital signatures (from pdf-lib-incremental-save)
- Rounded rectangles (from pdfme/pdf-lib fork)
- Hyperlinks support (PR Hopding#1691)
- Form field improvements (PRs Hopding#1748, Hopding#1758)
https://claude.ai/code/session_01T85UagjFeYdf4vUW9pzeyn