The surprisingly complex journey to text-selectable client-side generated PDFs
SDocs (sdocs.dev) documents how generating client-side PDFs with reliable text selection is a deep rabbit hole—font embedding, glyph mapping, and layout primitives are all non-trivial.
What Matters
- Client-side PDF generation requires manually embedding fonts, mapping glyphs, and computing text runs—browser layout engines do none of this for you.
- Text selectability fails when glyph positions are stored as absolute coordinates rather than logical character sequences.
-
SDocs ships a CLI (
sdocs-dev,npm i -g sdocs-dev) that lets agents generate styled PDFs via terminal commands. - The intended workflow: tell a CLI agent to “sdoc” a document—e.g. “write up the plan and sdoc it to me”—rather than manual export.
- [HN: @ak217] paged.js is an underappreciated open-source foundation for print/PDF using CSS paged media standards; handles edge cases like tables spanning multiple pages.
- [HN: @gobdovan] Building a cross-app paste normalizer (VS Code, Google Docs, PDFs, Chromium) revealed that apps write incompatible UTTypes to the pasteboard, making clean PDF copy-paste structurally hard.
- [HN: @josefrichter] PDF generation sits in the same “known Pandora’s box” category as email templates and CSS print—well-understood to be painful, routinely underestimated anyway.