Repository navigation
Highlights
Update fontkit
The new version of fontkit uses native compression for smaller and faster Node.js builds. It also includes security fixes and many bug fixes. See the release notes for more info.
Update png-js
The new version of png-js improves performance and reduces memory usage when processing large files. It also provides better error messages and includes security fixes. PDFKit now uses the synchronous png-js method. See the release notes for more info.
Plenty of bug fixes and small improvements
The changes range from rendering improvements to API additions like the addPageLabel method, the decorationThickness and underlineOffset text options, the scaleDown, flipH and flipV image options, and the headerRows table option.
The full list is below.
Time for a 1.0 release
PDFKit and its related libraries have a long history in the Node.js and JavaScript ecosystem. Over that time, they adopted many patterns that have since become obsolete. Recently, we’ve modernized the codebase to follow current best practices where possible. At the same time, with help from the community (and AI), we’ve fixed a lot of bugs and added important features like table support. The codebase is now a solid foundation for a 1.0 release.
CHANGELOG
- Fix gradients whose last stop comes before 1 stretching the stops over the whole gradient. The last color now stays solid from that stop to the end
- Add a
headerRowstable option, which repeats the first rows at the top of each new page. Fixes #1657 - Add a
scaleDownoption todoc.image(), which works likefitbut keeps an image smaller than the rectangle at its own size instead of enlarging it. Fixes #1347 - Fix standard fonts drawing a narrow no-break space as
/and a non-breaking hyphen as a double space. They now use the no-break space and the hyphen. Fixes #1071, fixes #1040 - Add
decorationThicknessandunderlineOffsettext options. Fixes #993 - Add
doc.addPageLabel(), which sets the page labels viewers show, such as roman numerals for a preface or numbering that starts at 49. Fixes #1269 - Add a
startoption todoc.list(), so anumberedorletteredlist can carry on counting after other content. Fixes #1350 - Export the predefined page sizes as
PAGE_SIZES. Fixes #1236 - Fix
doc.text()adding pages until it runs out of memory when the line width is negative, which happens whenindentwithindentAllLinesis larger thanwidth, or the gaps take up more than the width shared by thecolumns. Such text is now drawn one character per line, as it already was for a line too narrow to hold a character - Add
flipHandflipVoptions todoc.image(), which mirror an image without embedding it a second time. Fixes #1309 - Fix
wordSpacingremoving consecutive line breaks:text()andboundsOfString()collapsed every run of whitespace to one space, soTest\n\nTextwas drawn as the single lineTest Text. Only runs of whitespace within a line are collapsed now. Fixes #1034 - Fix
heightOfStringdrawing the measured text into the page when it is called after atextcall withcontinued: true, because it measured with the line wrapper that call had left behind, which draws its lines. A measurement that passescontinued: trueitself still uses that wrapper and draws as before. Fixes #1284 - Render SVG quadratic curves with equivalent cubic control points, so reversing a path preserves its shape. Fixes #550
- Fix the visual test renderer rejecting its standard-font directory on Windows because its path ends in a backslash.
- Fix the underline, strike-through, link and
goTorectangle of text drawn with abaselineother than the default sitting an ascent too low, because they were placed from the top of the line while the glyphs had moved up with the baseline. Fixes #994, #1245 - Fix links to a named destination going nowhere in readers that look the name up in sorted order, such as Chrome (PDFium) and qpdf, because name tree keys were sorted by locale with
localeCompareinstead of by their bytes: with destinations namedappendixandChapter1,Chapter1was written second and could not be found. The keys of theEmbeddedFilesandJavaScriptname trees are sorted the same way - Escape document information in XMP metadata and omit characters XML 1.0 cannot represent, without changing the PDF Info dictionary. Fixes #1817
- Fix
widthOfString(), line wrapping and text positioning with theSymbolandZapfDingbatsstandard fonts, which measured many characters as 0 wide (for example theZapfDingbatseuro sign, theSymbolletters and most of theZapfDingbatsornaments) because the text was looked up in the Roman character table instead of the font's own built-in encoding, and the metrics of nearly all of their glyphs were not included. Fixes #580 - Fix text in a standard font garbling or dropping the characters after a tab, a carriage return or any other character code below
0x10, which was written into the hex string of the text as a single digit, so the following digits paired up wrongly: a\rbefore a line break showed asÐ, andTab\therewas read back asTab–†W&P. Fixes #1425, #606 - Reuse the glyph width and kerning tables of a standard font across documents instead of building them again for every document that uses it, which made a short document using two standard fonts more than twice as slow to create
- Fix
doc.table()parsing a font passed as binary data (e.g. registered withregisterFont(name, uint8Array)) again for every cell, when it restores the font after measuring and drawing the cell, which made tables with such fonts slower. A font loaded from the sameUint8Arrayis now reused without parsing it again - Add
lineBreak: 'whitespace'todoc.text(), which breaks a line only at whitespace, a soft hyphen or a zero-width space. The Unicode line breaking rules the wrapper follows also allow a break after a hyphen or a slash, sodesign-systemorhttps://github.com/foliojs/pdfkitcould be cut at a line end, and a text extractor that joins the lines, such as a résumé parser, reads two words - Add an
objectStreamsoption, which packs the objects that are not streams into compressed object streams and writes a cross-reference stream instead of the xref table, making documents with many such objects, e.g. tagged ones, much smaller. It requires apdfVersionof1.5or higher, and cannot be used with encryption or PDF/A-1. Fixes #1810 - Fix wrapped text with
align: 'center'sitting left of the middle of the line whencharacterSpacingorwordSpacingis set, and withalign: 'right'running past the right edge by thewordSpacingof each gap between words - Fix
boundsOfString()withlineBreak: falseleaving outwordSpacing, so its width now matches the rendered text and its underline - Fix the underline, strike, link and goTo of wrapped text, and
boundsOfString()with awidth, countingcharacterSpacingandwordSpacingtwice, so they no longer run past the text and match the same text drawn withlineBreak: false - Fix the Node build throwing once a bundler inlines it into an application bundle,
Cannot find module '#standard-fonts/Helvetica'on the first document from an ESM bundle andInvalid URLwhile importing a CommonJS one, because the standard font metrics and the PDF/A ICC profile were resolved relative to pdfkit's own package directory at import time. Both are now resolved on first use, a standard font that cannot be loaded names itself and the fix in its error, andregisterStdFontsis exported from the Node build as it already was from the browser build, so a bundle can register the fonts it uses frompdfkit/standard-fonts/<Name>. The Node build now requires the standard fonts by a path relative to the built file, which replaces the#standard-fonts/*import mapping and lets an ESM bundle load them from a copy ofjs/standard-fontsnext to it. Fixes #1801 - Fix
doc.list()drawing the label of anumberedorlettereditem with the line wrapper's own options object, which threwunsupported number: NaNforaligncenterandright, applied a word spacing derived from the previous line to the label foralignjustify, and sized the underline, strike, link and goTo of every label after the first from the previous item's text - Add a
hiddenoption to form annotation methods, for a field that should start hidden (e.g. one an interactive action reveals later) instead of the usual default of visible and printable - Fix annotations placed under
doc.rotate()marking the wrong area, because_convertRectderived each corner's y from the already transformed x and mapped only two of the four corners, so the rectangle a viewer makes interactive did not follow the rotated content. Fixes #1153 - Add
onClick,onMouseDown,onMouseEnter,onMouseExit,onFocusandonBluroptions to form annotation methods, for the JavaScript a field runs on each of those events. Each accepts a string or a plain function, whose source text is written into the action - Add an
embedFontsoption toinitForm, embedding a complete, character-addressable copy of each custom font used in a form field. Viewers that regenerate a field's appearance from its value, such as Adobe Acrobat/Reader, need one to resolve field text; without it they fall back to a substitute font. It adds roughly the size of the font file per font, so it is off by default. Fixes #1096 - Add
alternateNameandstructParentoptions to form annotations so tagged form widgets can have an accessible name and belong to aFormstructure element. Retain the annotation's page when its structure is finalized after a page change. Honor an explicitfontSizewhen the field uses the default form font. Fixes #1803