Repository navigation
feat(pdf): PDF output without a browser, presentations first (#44, #46) - #57
Merged
Merged
Conversation
A presentation is written as a PDF file by the library itself, in the worker or on a server, with no browser and no dependency (p10node#44, first milestone p10node#46): - src/core/draw: pages of drawing commands (paths, glyph runs, pictures, groups with transforms, clips and opacity, links); SVG path data and transforms; PNG and GIF unpacked, JPEG read for its size; a text layout that breaks, aligns and spaces lines as the viewer's CSS does, measured in the host's font files (FontBook), Helvetica where none serves; an SVG reader for the engine's charts and SVG pictures; an SVG backend; - src/core/pdf: the PDF writer: fonts embedded as subsets (TrueType as CIDFontType2, PostScript outlines as OpenType) with ToUnicode maps, Helvetica as the PDF's own font, JPEG copied, PNG / GIF with soft masks, axial and radial shadings, transparency, link annotations, an outline from the slides' titles; - src/core/pptx/draw: a slide as a page, placed as SlideView places it: shapes and their outlines, fills, arrowheads, flips and rotation, pictures with crop and shape, tables whose rows grow to their text, charts, text boxes with insets, anchors and vertical text. The preset geometry moves to core; - the engine: `pdf` (slides, hidden ones, title) and `pptx.svg`. Fixes found on the way, in the font files of p10node#45: - Font.open kept a Node Buffer as it is: its `slice` shares memory, so subsetFont wrote the subset's glyph count into the font's own hhea and read every side bearing from the wrong place (glyphs drawn off their advance in a PDF). Bytes are now a plain Uint8Array and tables are copied, not sliced; - FontBook reads a file declared for several families once (one font, one subset in a PDF). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es, transparency - SVG pictures count elements and path segments as they are drawn, `use` included, and a `use` of itself is drawn once: a small file cannot repeat itself into millions of commands; - PNG data is unpacked up to what its pixels take, a GIF frame is checked before it is unpacked, 16-bit color keys compare all their bits; - each glyph run stands for its own characters (a line in two fonts was copied with characters twice); a glyph that stands for other text in another place (a ligature and U+FB01) is given /ActualText; - runs are cut where their glyphs are, by halving, not by reading every glyph for every line (a narrow box of long text was quadratic); lines are never broken inside a cluster; tabs move the pen and draw nothing; - fonts' licenses: bitmaps only is not embedded, no subsetting embeds the whole font; a font that fails to embed, or a picture that cannot be read, falls back with a warning instead of failing the file; - a subset keyed by CID says Adobe-Identity-0, as the PDF does; - transparent groups are isolated transparency groups, a gradient whose alpha changes has a soft mask; hard stops make no zero-width interval; numbers are decimal and clamped; subset tags are unique; link addresses are ASCII; - an empty selection of slides is refused instead of writing a file of no page. A cropped and flipped picture is flipped in its frame, as PowerPoint does: the PDF already did; the viewer flipped the whole picture about its own centre and showed the other side of the crop, and now does the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- an SVG's clip paths count toward its segments; - a link with half a surrogate pair is written (U+FFFD), not an error that takes the file down; a picture part that throws, or rejects with anything, leaves its picture out; - what each glyph stands for is worked out once per run (the ActualText check made long runs quadratic); a line in two fonts finds its pieces by halving; a line can end after an ideograph of two UTF-16 units; - soft masks have names of their own (they could take an alpha's name); a form's box is the page in the form's space, not a fixed square that left far-off drawings out; a gradient along a line is a shading pattern (with a soft mask where its alpha changes); - gradient stops are rounded before their intervals are made, so /Bounds only grows; a font embedded whole has no subset tag; - a CFF's strings are read byte by byte (one long string was past the arguments a call may take); a PNG's data is read to its end, so one cut short of its checksum is refused (at most 1 MB past its pixels is read); - the docs say a CID-keyed font that may not be subset is set in Helvetica. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- transforms, pattern matrices and gradient stops are written to six significant digits, and the boxes and patterns worked out from them use the numbers as written: a scale of 0.00149 written as 0.001 left a form's box short of what it drew, two nested small scales made a pattern's matrix 0 and its stroke vanished; - what a glyph stands for is worked out on each export, not kept: a text command changed between two exports gave the old text; - a gradient of no length paints its last stop's color, as SVG says; - a color fill and a color outline are painted together again (B), so translucent ones overlap as they did; - two embedded fonts of one name keep apart (-2, -3…); - a rejection that cannot be made a string is reported as an error; - a PNG that unpacks to more than 1 MB past its pixels is refused; - a line can end after an ideograph of CJK Extension H. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`pdf({ slides })` wrote a hidden slide it named: a list of pages (a
server's `nativePageRanges`) then showed what was hidden. Hidden slides
are now written only with `hidden: true`, whether `slides` names them or
not; a list of nothing but hidden slides is refused.
Found by the review of the convert package's PDF output.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #44 and the first milestone, #46 (PPTX → PDF).
Stacked on #54 (font files, #45): the base is
feat/font-files. Once #54 merges, this goes tomain.What it does
A presentation is written as a PDF file by the library itself. It needs no browser, no print dialog and no dependency, and it runs in the worker or on a server.
The design follows #44: layout produces pages of drawing commands, and a backend paints them as PDF or SVG.
src/core/drawholds the drawing layer:FontBook;src/core/pdf/writer.tswrites the file:/ActualTextwhere one glyph stands for different text;src/core/pptx/draw.tsturns a slide into a page, placed the waySlideViewplaces it:The preset geometry moves from
src/reactto core.Licenses and limits:
useand clip paths included.Fixes to #54 found along the way
Bufferaliasing:Font.openkept a NodeBufferas it was. Itssliceshares memory, sosubsetFontwrote the subset's glyph count into the font's ownhheatable and read every side bearing from the wrong place. Glyphs were then drawn off their advance. Browsers never hit this; a server reading fonts withreadFileSyncdoes.FontBooknow reads a file declared for several families once, so it becomes one font and one subset.Viewer change
A cropped picture that is also flipped is now flipped within its frame, as PowerPoint does: crop first, then mirror. The viewer used to mirror the whole picture about its own centre, which showed the other side of the crop. The PDF and the viewer now agree.
Review
Codex reviewed this branch in three rounds before the push. Everything they found is fixed and has a test.
13f8175:857f05d:186cacc:Tests and checks
test/pdf-output.test.tshas 48 tests. They cover:bun run typecheckis clean.feat/font-fileswithout this PR: encodings, plus ODF fixtures that needmain's zip fix fix(core): part of a Blob read as a stream ends where it was asked to, on any runtime #52.pdftotextextracts clean text;pdffontsshows embedded subsets with Unicode maps;Not yet
Next
to: 'pdf'into@p10node/convert(feat(convert): @p10node/convert, server-side conversion (CLI + HTTP service with Gotenberg's routes) (#43) #56). Gotenberg's route then stops answering 501 for presentations.🤖 Generated with Claude Code