Skip to content

Commit 133bfc3

Browse files
donislawdevclaude
andcommitted
format/pdf: exact size, and the padding channel we had written down was wrong
PDF is the third format and the highest fidelity bar in Tier 1. Exact size, byte determinism, pages and page size as properties, label in the footer and in the document title. The interesting part is what measurement overturned. This project had recorded the padding channel as "a comment block before %%EOF, no limit". The reasoning behind it was sound as far as it went - objects and the cross reference table both sit earlier in the file, so a comment at the end moves no offset. What it missed is how a reader finds that table: by scanning backwards from the end of the file for startxref, over a window each reader picks for itself. Xpdf 4.06 reads 1004 bytes of comment there and fails at 1005. The Windows renderer reads any amount. That is worse than a hard limit would be. A file that opens for one tester and not for another is the one outcome a fixture generator must never produce. So the channel moved to a comment after the trailer and before startxref. The tail from startxref to the end stays short whatever the padding size, and startxref still points at the same offset because the table sits earlier. Measured at 64 B, 4 KB, 100 KB, 1 MB, 2 MB and 10 MB against three independent engines - Xpdf, exiftool and the Windows renderer used by the system viewer. All three read the document and report the right page count. This is the third claim written from memory that a few minutes of measurement has disproved, after the 7Z tail and the size units. Registering PDF also made the property test find two defects immediately. The comment splitter could leave exactly one byte over, which cannot form a comment line. And the seed test asked for the declared minimum with the label on, while the declared minimum is the label free one - the message now says so and offers --clean. Fonts are not embedded. Helvetica is one of the fourteen every reader already has, which keeps a font file and its licence out of this for now. Fidelity is declared full and confirmed in three engines, not in Adobe. Acrobat is installed here and stays a manual checklist item. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 5ec5820 commit 133bfc3

5 files changed

Lines changed: 492 additions & 9 deletions

File tree

‎CHANGELOG-DEV.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@ configuration, architectural decisions. Anything a user would notice goes to
66

77
## Unreleased
88

9+
### 2026-08-01 - PDF, and an assumption of ours disproved
10+
11+
- `pdf` is the third generator. Exact size, byte determinism, pages and page
12+
size as properties, label in the footer and in the document title.
13+
- **The padding channel this project had written down was wrong, and
14+
measurement caught it.** The note said "a comment block before %%EOF, no
15+
limit". The reasoning behind it was sound as far as it went - objects and
16+
the cross reference table sit earlier, so a comment at the end moves no
17+
offset. What it missed is that a reader finds the table by scanning
18+
backwards for startxref, and how far back is up to the reader. Xpdf 4.06
19+
reads 1004 bytes of comment there and fails at 1005. The Windows renderer
20+
reads any amount.
21+
- **That is worse than a hard limit**, because the file would open for one
22+
tester and not for another. The channel moved to a comment after the
23+
trailer and before startxref, where the tail stays short whatever the
24+
padding size. Measured at 64 B, 4 KB, 100 KB, 1 MB, 2 MB and 10 MB against
25+
Xpdf, exiftool and the Windows renderer.
26+
- This is the third time a claim written from memory has been disproved by a
27+
few minutes of measurement, after the 7Z tail and the size units.
28+
- **The property test found two defects the moment PDF was registered.** The
29+
comment splitter could leave exactly one byte over, which cannot be a
30+
comment line. And the seed test asked for the declared minimum with a label
31+
on, while the declared minimum is the label free one.
32+
- Fonts are not embedded. Helvetica is one of the fourteen a reader already
33+
has, which keeps a font file and its licence out of the picture for now.
34+
- **Fidelity is declared full but not confirmed in Adobe.** Three engines
35+
read it. Adobe Acrobat DC is installed and stays a manual checklist item.
36+
- Guards: 33, all still green with three formats registered.
37+
938
### 2026-08-01 - review after the second format
1039

1140
Another read through everything, this time with memory measured rather than

‎CHANGELOG.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ because it turns other people's test suites red.
1212

1313
### Added
1414

15-
- `tfg generate` produces **text and PNG files** of an exact size. Ask for
16-
10 485 761 bytes and you get exactly that.
15+
- `tfg generate` produces **text, PNG and PDF files** of an exact size. Ask
16+
for 10 485 761 bytes and you get exactly that.
17+
- PDF takes `--set pages=` and `--set page_size=` (A4, A3, A5, Letter,
18+
Legal). The label goes in the page footer and in the document title.
19+
Checked against Xpdf, exiftool and the Windows PDF renderer.
1720
- PNG carries the label burned into the picture, and its size is made exact
1821
by a private chunk that decoders ignore. Checked against Pillow, FFmpeg,
1922
Tcl/Tk, the Windows Imaging Component and exiftool - all five read the

‎internal/format/all/all.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package all
88

99
import (
1010
// Each format registers itself when its package is loaded.
11+
_ "github.com/donislawdev/TestingFilesGenerator/internal/format/pdf"
1112
_ "github.com/donislawdev/TestingFilesGenerator/internal/format/png"
1213
_ "github.com/donislawdev/TestingFilesGenerator/internal/format/txt"
1314
)

0 commit comments

Comments
 (0)