PDFKit 0.20.2 drops the structure parent of a form widget and has no supported option for its alternate name. This source repair restores those options and honors an explicit field font size with the default form font. It also keeps each widget attached to its original page when a multipage document's structure is finalized later.
The regression was reported by Robert-Krueger in PDFKit #1803. The example creates two tagged pages with editable fields, existing reference text, document metadata and an embedded font. The source patch, tests and example are free. The proposed upstream fix is PR #1805; it has not been merged or released.
Use Node.js 24. Download this directory, including the source patch and generate.cjs. From that directory:
git clone https://github.com/foliojs/pdfkit.git pdfkit
cd pdfkit
git checkout 563aba49416d9a5444fd8fa09ea2501d3629d2e4
git apply --check ../pdfkit-accessible-forms.patch
git apply ../pdfkit-accessible-forms.patch
node .yarn/releases/yarn-4.16.0.cjs install --immutable
node .yarn/releases/yarn-4.16.0.cjs build
cd ..
node generate.cjs ./pdfkit request-form.pdfThis uses a fixed source revision after 0.20.2, including upstream's existing Node bundling repair. It is a source build, not a new stable PDFKit release or a patch for an arbitrary installed version. The generated file is also available as request-form.pdf.
Install veraPDF and run:
verapdf --flavour ua1 request-form.pdfThe generated two-page sample should pass the PDF/UA-1 profile. Open it in a PDF form viewer to inspect the fields. Validation after editing is a separate check; see the limits below.
const fieldStructure = doc.struct('Form', { title: 'Request number' });
doc.addStructure(fieldStructure);
doc.formText('requestNumber', 60, 180, 240, 28, {
alternateName: 'Request number',
structParent: fieldStructure,
fontSize: 11,
});alternateName writes the field's /TU text string. structParent connects the widget to its Form structure element through an object reference and the parent tree. It is separate from parent, which groups form fields. An explicit fontSize applies to the default form font too; 0 retains automatic sizing, while omission preserves inherited appearance behavior.
These options alone do not make an arbitrary document accessible. PDFKit's accessibility guide covers document metadata, language, reading order, tagged content and artifacts. The complete sample is in generate.cjs.
For Node bundles, follow PDFKit's font-registration guidance. The verification included a local CommonJS esbuild bundle with registered Helvetica metrics; no AWS deployment was performed.
PDFKit 0.20.2 already accepts subset: 'PDF/UA'. The separate @types/pdfkit 0.17.6 declarations omit that literal from PDFKit.Mixins.PDFSubsets, which causes the error discussed in PDFKit #1804. For these versions, a temporary assertion on this supported literal allows the documented option while retaining checks on the other options:
import PDFDocument = require('pdfkit');
const doc = new PDFDocument({
subset: 'PDF/UA' as PDFKit.Mixins.PDFSubsets,
tagged: true,
lang: 'en-US',
displayTitle: true,
info: { Title: 'Accessible document' },
});Use this assertion only for the known supported literal, and remove it when the declarations include PDF/UA. It does not change PDFKit's runtime or make arbitrary subset strings valid. Metadata and a subset setting alone do not establish document accessibility.
The standalone TypeScript example generates a tagged paragraph with an embedded font. It uses the published 0.20.2 package and does not use form fields or require the source repair above. To run it in a separate directory with an embeddable font file:
npm install --save-exact pdfkit@0.20.2
npm install --save-dev --save-exact @types/pdfkit@0.17.6 typescript@7.0.2
npx tsc --ignoreConfig --strict --target ES2022 --module Node16 --moduleResolution Node16 --outDir compiled typescript-example.ts
node compiled/typescript-example.js /path/to/your-font.ttf
verapdf --flavour ua1 typed-pdfua.pdfIn the type verification, the original literal failed with TS2322; the scoped assertion compiled under strict mode, while unsupported unasserted subsets and a non-boolean tagged value remained errors. The emitted JavaScript completed PDF generation. The sample using the upstream Roboto fixture passed veraPDF 1.30.2's PDF/UA-1 profile. Validate your own content and fonts separately.
The verification record lists the exact tools and results. Regression tests inspect serialized widget references, distinct page and structure parents, field hierarchy, Unicode names, absent values and explicit zero sizes. The upstream unit and visual suite was run with four workers. A run with unrestricted workers timed out in four visual tests; no test timeout was increased.
The generated sample passes veraPDF's PDF/UA-1 profile. Two programmatic pypdf fill/save/reopen cycles preserved both fields, their matching page widgets, structure links, metadata and reference text. Rendered pages were inspected for correct values and clipping. These are software checks, not human assistive-technology validation or confirmation from the original reporter.
After pypdf regenerated field appearances, the saved sample failed the font-embedding rule 7.21.4.1-1. The example keeps the report's Helvetica form font; the body text uses embedded Roboto. A separate probe with initForm({ embedFonts: true }) exposed CMap/Unicode validation failures (7.21.3.1-1 and 7.21.7-1) and incorrect prefilled appearance rendering in Poppler. This patch does not change that separate font behavior or promise that a viewer's saved file remains PDF/UA conforming. If your workflow validates completed forms, validate the output from your actual editor too. No production document or screen reader was tested.
License: MIT; see LICENSE. The example uses the font fixture from the upstream source checkout.
If this saves you some time and you'd like to buy me a coffee, thank you. It is entirely optional; the repair and example are free.
- USDC / SOL · Solana:
9tY6D9mwcFaJwwzEHvw2v7nhSpdjqjNBYtuooyBN6rYy - USDC / ETH · Base:
0x568Ab98578d682FB0B0b45619BE73EbFfbf5a6eA - USDT · BNB Smart Chain (BEP20):
0x568Ab98578d682FB0B0b45619BE73EbFfbf5a6eA