Each is its own module with its own release line, so a program takes the reader without the rasteriser, or the rasteriser without the writer.
Reads and writes the format itself. Lexer and object model, cross-reference tables and streams with hybrid files and /Prev chains, object streams, repair by scanning when the table is wrong, every filter (Flate, LZW with early change, ASCIIHex, ASCII85, RunLength, PNG and TIFF predictors), the standard security handler from RC4-40 to AES-256, content streams and inline images, the page tree with inherited attributes โ and a writer that produces the same bytes twice. Of 118 863 real PDFs, 118 833 open; the thirty that do not are 27 PNGs named .pdf, one PostScript file and two truncated past recovery. It also writes a LINEARIZED file since v0.16.0 โ Annex F’s eleven parts, both cross-reference sections and a hint stream carrying the page offset and shared object tables โ and qpdf --check reports nothing about the output it does not also report about the input. Since v0.18.0 that includes documents whose pages share objects, which the page tree’s own inheritance makes the ordinary multi-page PDF: one /Resources on the pages node is reached by every page, and F.4.2’s shared object hint table now says which of part 6’s and part 8’s objects each page after the first depends on. Measured over eight shapes against qpdf 12.4.2 โ private pages, a shared content stream, two and twenty-five pages inheriting one resource dictionary, and pages 2 and 3 sharing an object page 1 never reaches. โ What it still does not say is where in a page a shared object is first used: F.4.1’s fraction is written 0/1, so a reader may fetch one earlier than it needs it, never later. โ Since v0.19.0 it also refuses three bombs of one shape โ a count the file chose, used as a size. An object stream declaring /N 10000000000000 asked for a 160 TB slice from a 51-byte object and ended the process with a fatal out-of-memory, which recover() does not catch and GOMEMLIMIT does not prevent; a 102-byte file asked for a 932 MiB predictor row; a fax bounded its width only when /Rows was present, and /Rows is optional. Each ceiling is now derived from bytes actually held rather than from a number the file asserts. None was found by reading the code โ the object stream and the predictor row came from fuzzing, and the fax from the audit that the object stream’s issue asked for, which is why FuzzCCITTDecode no longer pins the parameters it is meant to vary. It reads and verifies digital signatures since v0.20.0: Document.Signatures lists the signed fields, Document.SignedBytes returns the bytes a signature covers after validating its /ByteRange, and the reader/signature sub-package verifies adbe.pkcs7.detached and ETSI.CAdES.detached on top of go-authn/cms. It was checked against poppler pdfsig 26.10.0 on OpenSSL-made fixtures โ RSA, ECDSA and CAdES valid; an incremental update leaves the earlier signature valid, not whole-file; two stacked signatures; seven tamperings refused by both. One deliberate difference: pdfsig calls a SHA-1 signature valid and this package refuses it by name. A /ByteRange the file does not bear out is refused, and a signer’s claimed name, reason, location and time are reported only when the signature covers the dictionary that holds them. At most 64 distinct signatures and 1 GiB of signed bytes are verified per document. โ Trust โ the certificate chain and revocation โ is the caller’s.
repository ยท pkg.go.dev
The verbs, and the pdfops command โ 64 of them, counted from the source of its command table at v0.45.1. Merge, select, delete, reverse, move, rotate, crop, resize, split, n-up, booklet, poster, divide, duplex, overlay, blank pages, watermarks, page numbers, Bates stamps, a placed picture โ a signature or a logo โ page labels, layers, text colour, sanitize, flatten, compress, encrypt, decrypt, permissions, repair, attachments, forms โ and reading a page back as text, pictures, tables (CSV, JSON or Markdown) or a whole document in Markdown. Links and bookmarks are carried over and pointed at the pages they became. It signs a PDF since v0.39.0: ops.Sign and pdfops sign add a digital signature as an incremental update, so every earlier signature still verifies, with a detached CMS from go-authn/cms โ RSA, RSA-PSS, ECDSA or Ed25519 โ under adbe.pkcs7.detached or ETSI.CAdES.detached. poppler pdfsig calls the RSA and ECDSA signatures valid; โ it reports an Ed25519 one as Invalid, while reader/signature and openssl cms -verify accept the same bytes. Since v0.40.0 the signature can be visible: SignOptions.Appearance and pdfops sign -visible x0,y0,x1,y1 [-image file] [-text words] draw a picture and text in a box on the page, inside the signed bytes. โ The text is Latin only (WinAnsi): a Cyrillic or CJK character is refused by name, not dropped. It signs with a .p12 / .pfx file since v0.41.0: SignOptions.LoadPKCS12 and pdfops sign -p12 f.p12 [-p12pass <file or ->] take the key, certificate and chain from one password-protected PKCS #12 file, the password never an argument or an environment variable. โ The certificate is not judged โ no validity dates, key usage or chain to a root are checked. โ Not claimed: a PAdES baseline, timestamps or LTV, or an encrypted file, which is refused. It turns text into paths since v0.43.0: OutlineText and pdfops outlinetext leave a page that looks as it did and holds no font, with /ActualText, /Alt and /E removed too. โ Past a bound it refuses, and vertical writing is refused by name; annotation text is not reached, and counted. It makes a scan searchable since v0.45.0: AddInvisibleText and pdfops ocrtext draw a recogniser’s words (JSON, or Tesseract hOCR) over the page in invisible text, Tesseract’s GlyphLessFont design, and the page renders pixel for pixel as before. โ It does not recognise anything itself, and a redacted page is refused. Every verb is measured on the whole corpus: 118 833 files compressed and read back page for page identical, 35.2 GB down to 33.6 GB.
repository ยท pkg.go.dev
Turns a page into pixels. The transform stack, every painting operator, both winding rules, strokes with caps/joins/miter/dashes, clipping, every colour space, transparency, form XObjects; images at every depth with soft and stencil masks; text from TrueType, OpenType, bare CFF, PostScript Type 1, composite and Type 3 fonts; PDF functions of all four kinds, all seven shadings โ axial, radial, function-based, and the four mesh kinds, triangles and Coons and tensor patches โ and shading and tiling patterns, placed in the space of the form that names them. Rasterises with go-gfx and reads outlines with go-opentype. Builds for js/wasm.
repository ยท pkg.go.dev
What a document says about a font โ not the outlines, which are the program’s business. Which codes a string holds, how wide each is, what each is called, and what text each stands for, through /ToUnicode and the encodings. It refuses one guess: a symbolic font read through an assumed encoding gives the wrong letter with nothing to say so. The glyph-name table is checked against the documents themselves โ 63 515 names, 99.31% agreement.
repository ยท pkg.go.dev
Pictures into a PDF, and a PDF back into pictures โ or into SVG. Reads PNG, JPEG, GIF, BMP, TIFF, WebP and PSD, and writes all of those but PSD โ which it refuses by name, because writing a layered document is a different job and a PNG under a .psd name would be worse than saying no. PDF to SVG (pdfconv to-svg, v0.17.0): text becomes outlines so the file needs no font, one page is name.svg and several are name_svg.zip, and it is all or nothing โ a zip with page 4 of 9 missing would look complete, so no file is left behind. Bounded before it is spent: 1000 pages, 64 MiB a page, 256 MiB and five minutes a run. โ Passwords no longer go on the command line: -password is gone from every verb, replaced by -password-file (a breaking change). WebP writes in both of its codecs: quality 100 is the lossless one, half the size of PNG on a rasterised page of text; below that the lossy one, 12ร smaller again on a detailed page. The content decides a format, never the file’s name. Only the DPI says which page a picture is: 2480ร3508 is A4 at 300 and a page a metre tall at 72. Fitting onto paper uses one scale for both axes and only ever shrinks.
repository ยท pkg.go.dev
Any document into a PDF, from a shell. doc2pdf report.docx โ Word, Excel, PowerPoint, OpenDocument Text, Markdown, reStructuredText, HTML, plain text, CSV, JSON, XML, EPUB, MOBI, FictionBook, RTF and email, through richdoc and document; XPS and OpenXPS (v0.4.0) are read directly into a vector PDF under one 160 MiB memory budget per conversion; HEIC and HEIF pictures (v0.5.0) become one page each (doc2pdf). Pure Go, CGO-free, no TeX. --max-input BYTES refuses an input over the limit before reading it (16 MiB for RTF, 256 MiB for every other format), and the output is written atomically. It exists because thirteen libraries were finished, tested, released and unusable from a shell: measured across thirty repositories of this fleet, four shipped a command and twenty-five did not, and a reader nothing can call is in a different state from an unfinished one โ easy to mistake for it. โ Nothing is fetched. A document arrives from something somebody was handed and its images carry URLs the author chose; following them would make every conversion a request to an address of their choosing, from the converting machine. What was refused is printed, because a page with holes in it must not be silent. A failure names the reader โ thirteen libraries stand behind it and “cannot read it” sends you to the wrong one โ and every reader in the table is held by a test that converts a real file of that format.
repository ยท pkg.go.dev
Reads a page back: the text with where each piece of it sits, the pictures with the box each covers, and the grids its text lines up into. A page holds instructions for drawing glyphs, not text โ so where the document says nothing about what they mean, this says so rather than guessing. A column boundary is a stretch of page every row leaves empty, and three things that look like columns are not: a bullet, a column nothing was drawn in, and a page number. On one 213-page document those three took the count from 588 tables to 40, which are the real ones; a prose report in the same run reports none. Over the whole corpus: 121 946 pages, 34 million characters, 1.89% of runs that nothing in the document could name, 300 685 pictures located, no panics.
repository ยท pkg.go.dev
A PDF read back as a document rather than as text โ headings, paragraphs, lists and tables, into the richdoc model, which gets Markdown, reST and HTML out of a PDF through code the fleet already has. A page has no headings: it has glyphs at places, and everything above that is an inference. A heading is text set larger than the body and rare with it โ measured over six real documents, heading sizes hold 0.01% to 5.76% of the characters and a second body size holds a third, and taking “larger” alone gave a nine-page report 131 headings of which 130 were prose. What it will not read is published too: ruled lines, columns of a multi-column layout, and footnotes.
repository ยท pkg.go.dev
A PDF several people edit at once. What is shared is not the file โ merging two piles of bytes cannot be done โ but the plan: which pages, from which files, in which order, turned and cropped how, with which bookmarks over them. A list, a tree and a handful of fields, which a CRDT merges without asking anybody. Checked with 25 editors making random edits for 40 rounds, merged in a random order, all agreeing on the same document.
repository ยท pkg.go.dev
Read, fill and draw an AcroForm โ the boxes somebody types into, the squares they tick, the lists they choose from. A field’s value is not what gets drawn: what gets drawn is a little content stream beside it, so a reader that fills a field and does not rewrite that stream leaves the page blank. An AcroForm dictionary with an empty field list is not a form โ 561 of the 118 833 figure-corpus files are exactly that, left behind by a producer. Builds for js/wasm.
repository ยท pkg.go.dev
The form inside a PDF whose pages are blank. Of 2 240 real government forms, 560 carry an XFA package and 546 are static โ a second, proprietary copy of a form already drawn on the pages, which forms fills without help. The other fourteen are dynamic: their pages hold a panel reading Please wait… your PDF viewer may not be able to display this type of document, and the document exists only as XML. Adobe removed the format from PDF 2.0, and no browser lays one out.
repository ยท pkg.go.dev
Static HTML to VECTOR PDF, zero C. No headless browser and no screenshot-then-slice: it drives go-webengine’s own layout tree straight into pdfkit’s text, rect and stroke calls, so the text in the PDF is real text โ selectable, searchable, small โ rather than a picture of text. v0.4.0: Options.Fetch and html2pdf.Offline render with no network access at all (a refused stylesheet or image is left out, counted through OnRefused; data: images still render; --offline on the command), a second barrier for a server that renders HTML built from untrusted text. v0.3.0: list markers painted (::marker, every list-style-type), CSS escapes and counters; @page margin boxes with counter(page) / counter(pages) for page numbers, target-counter() for a table of contents, and a html2pdf command (cobra, POSIX flags, --title, --author, --subject, --keywords).
repository ยท pkg.go.dev
The other direction: reconstruct LaTeX source from a PDF. A PDF that came from TeX does not contain a document; it contains the marks TeX made putting one on paper โ glyphs at absolute positions, from fonts whose names are the only surviving record of what the author asked for. Reconstruct gives back the .tex, and writes out the pictures its includegraphics commands name.
repository ยท pkg.go.dev
Where all of the above is judged by implementations that are not ours, over corpora of real PDFs. A file our own reader reads back perfectly can draw nothing anywhere else โ that has happened here: a rebuilt cross-reference stream our reader was delighted with, and macOS drew a blank page. So these tools ask poppler rather than asking ourselves. A figure is only as honest as the population it came from, so the corpora are chosen and stated rather than collected.
repository ยท pkg.go.dev
A PDF workbench that runs in a browser tab and nowhere else. Open a file, turn its pages, rotate one, drop one, lay it out two to a sheet, write across it, save it back out โ and none of it leaves the machine, because there is nowhere for it to go. Its commands are a ribbon of seven tabs: the ribbon carries the verbs and a panel beside the page carries what each verb is told, so choosing a tab opens the settings that tab’s verbs read. Down the left, a rail you can widen: the document’s own table of contents above its minipages, and the links it carries when it has no outline โ which most documents do not, so a contents view offered only to the minority is one nobody finds. Each link’s row says the words it sits on, which is the only name a link has; one that leaves the document is shown and not followed, because nothing leaves this tab and that includes you. The status line names the build it is running, because an old binary and a missing feature are otherwise the same screen. Widen the rail and the minipages are re-rendered at their new width when you let go. The whole tool is one wasm binary the browser downloads once and a service worker then keeps. Driven in CI by a real Chrome over the DevTools protocol, pressing each control where the workbench says it is, dragging the divider the way a hand does โ press, move while held, let go โ and reading the canvas pixels back. That last part is new, and it found two defects on its first run: everything the check did before was a press, and a press is one point, so the one control that answers only to a gesture had never been exercised at all.
repository ยท pkg.go.dev
The document builder: pages, vector graphics, and text set in embedded, subsetted fonts. TrueType and OpenType/CFF embed as Type0 (Identity-H) composite fonts with a /ToUnicode CMap; JPEG and raster images place directly; a widget bridge prints a go-widgets tree onto a page, rasterised or as selectable vector text. With the zero Options the output has no timestamps and a content-derived /ID, so identical inputs produce byte-identical PDFs.
repository ยท pkg.go.dev
The gap against BentoPDF, counted row by row and reported with its denominator.
repository ยท pkg.go.dev