What is a PDF file?
A PDF file is a set of numbered objects (pages, fonts, content streams) plus a cross-reference table that gives the byte offset of each object, and a trailer that points at the document catalog. Readers jump to the end, read the xref, then load what they need.
Because everything hangs on byte offsets, small faults have big effects: an xref off by a few bytes, a missing %%EOF, a truncated download or a corrupt compressed stream. Each damage option breaks exactly one of these, so you know what your reader is recovering from.
Anatomy of a PDF file
%PDF-1.4The header and version1 0 obj … endobjNumbered objects: catalog, pages, fonts, streamsstream … endstreamPage content, optionally Flate-compressedxrefByte offset of every objecttrailerSize, root, info, file ID and encryptionstartxref / %%EOFWhere the xref starts, and the end marker
What you can generate
- 1 to 1,000 pages of Helvetica text, A4, US Letter or A5
- Bookmarks (outline), links, a rotated page and mixed page sizes
- Accented WinAnsi text and strings with ( ) and \ escaped
- Flate-compressed or plain content streams
- Password protection: RC4 128-bit, password test
- Broken on purpose: missing xref, wrong xref offsets, truncated at 60%, corrupt content stream, missing %%EOF
How to make one
- Open the PDF generator, or start from a preset above.
- Set the size and switch on the edge cases you need; the preview and size estimate follow every change.
- Generate, then download. The file is made in your browser, and the same preset and seed always give you the same file.
Questions
Yes. Every xref offset points at its object, and the tests open each file with pdf.js and read the page count, text and bookmarks.
With the standard security handler, revision 3: RC4 with a 128-bit key. The user password is test. pdf.js refuses it without the password and opens it with it. AES encryption is on the list for later.
Missing xref drops the table, wrong offsets shifts every entry by 13 bytes, truncated cuts the file at 60%, corrupt stream overwrites the start of page 1's compressed content, and missing %%EOF removes the end marker.
The standard Helvetica and Helvetica-Bold fonts with WinAnsi encoding, which every reader has, so no font is embedded.