Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 6 min read

One PDF button reached 39 pages, 157 sheets of A4, and 558 KB of it is a constructor flag

Our free question pages were HTML and nothing else. Search demand around them is not: "printable", "with answers pdf" and "questions and answers printable" hang off nearly every quiz query there is, and a page that only

Our free question pages were HTML and nothing else. Search demand around them is not: "printable", "with answers pdf" and "questions and answers printable" hang off nearly every quiz query there is, and a page that only offers HTML is a page the reader pastes into Word.

So last night one component went into the list renderer that every question page already uses, and 39 pages gained a Download PDF button in a single commit. The output is the questions on their own pages, then the answers on separate ones, so a host can hand the first half round the tables and keep the second.

You can press it yourself on the Christmas set or on the music set. Nothing is uploaded: open the Network tab first and watch the library arrive and the file not leave.

Then I measured what the button actually produces, on all 39 pages.

The fleet, in bytes

Set Questions A4 pages Bytes With compress: true
/quiz-questions/review-of-the-year-2026 60 5 36,995 11,457
/quiz-questions/christmas 47 5 29,009 9,612
/quiz-questions/christmas-movies 37 4 23,268 8,045
/quiz-questions/valentines 34 4 22,844 8,449
/trivia-questions/christmas 33 4 21,918 7,955
/quiz-questions/anagrams 34 4 20,247 6,763
/quiz-questions/true-or-false 24 3 16,036 6,195
All 39 1,347 157 864,266 305,478

157 sheets of A4 is the whole published library as paper: 39 downloads, every one of them two documents stapled together, 4 pages for a typical set of 34 questions.

The right hand column is the finding. jsPDF writes its content streams raw unless you ask it not to, and compress: true is one word in the constructor. Across the 39 files it is 558,788 bytes, or 64.7 per cent of everything the button produces.

I have written this exact paragraph before. A fortnight ago I measured the poster tool's QR code and found a 1,085,526 byte PDF whose 99.5 per cent was one unfiltered bitmap, where the same flag was worth 157x. The cheapest fix from that post was: set it on both constructors. Instead a third constructor shipped without it.

Text compresses less dramatically than a bitmap, so this one is only 2.83x. It is also the one a reader on a phone in a pub car park actually downloads.

The numbers are the live file, not a local approximation

Measuring a browser-generated file by rebuilding it in Node is only honest if the two are the same bytes. They are. I clicked the button in a real Chrome, saved the download, rebuilt the same document with the same library in Node, and normalised the two fields that cannot match:

/CreationDate (D:20261127121200+01'00')
/ID [ <...> ]

Both files are 29,009 bytes. After normalising those two fields, 28,925 bytes each and byte-identical. So every number in the table above is the file a reader gets.

Three other facts out of those bytes, all consistent with what the poster PDF turned out to be: zero occurrences of /Filter, 14 base-14 fonts declared in the resources of every page, and zero embedded font files.

The title is read off the page at click time

The button takes the question data as a prop, because it is rendered by the list component that already has it. It does not take the title. It reads that:

const title = printable(
    document.querySelector("main h1")?.textContent?.trim() || document.title
)

That looks like laziness and is actually the cheaper correctness argument. The page's <h1> is rendered from one field in the content registry, which is the same field that produces the <title>, the canonical and the breadcrumb leaf. Reading the DOM means the PDF's heading cannot drift from the heading the page is already committed to, and 39 call sites do not each have to repeat a string. The filename comes from the same place, slugged:

  • Christmas quiz 2026: questions and answers becomes christmas-quiz-2026-questions-and-answers.pdf
  • Valentine's quiz questions with answers becomes valentine-s-quiz-questions-and-answers.pdf

That second one is the slug rule meeting a curly apostrophe. Every non-alphanumeric run collapses to one hyphen, so the apostrophe survives as a hyphen between valentine and s. Nobody will notice, and it is still the wrong file name.

The longest filename across the 39 is 46 characters. The poster tool, measured in the same batch as the QR code, could produce a 492 character download name, because that one takes a user-typed string. These titles come from a registry we wrote, so the input is bounded by review rather than by code. That is worth being honest about: it is not a cap, it is an absence of attackers.

The sanitiser that almost never fires

jsPDF's built-in fonts are Latin-1. Hand them a curly quote or an em dash and you get garbage glyphs rather than an error, so the component maps the typography to plain equivalents, strips accents it cannot represent, and falls back to a question mark:

text.replace(/[β€˜β€™]/g, "'")
    .replace(/[β€œβ€]/g, '"')
    .replace(/[\u2013\u2014]/g, "-")
    .replace(/…/g, "...")
    // then: strip accents outside Latin-1, else "?"

I ran every string the 39 pages pass through it. 2,938 strings, 99,053 characters of question and answer text, and 33 characters above ASCII:

Character Count What the sanitiser does
Γ© 11 passes through, it is Latin-1
Γ‘, Γ« 5 each passes through
Γ­ 3 passes through
Γ», Γ₯, ΓΌ, Γ¨, Γ³, ΓΆ, Γ―, Γ‰ 1 each passes through
Ε‘ 1 decomposed and stripped to o

Zero characters become ?. The accent-stripping branch fires exactly once in the whole library, on one Hungarian name, and the result is a plain o that no reader will complain about.

The quote-mapping branch is stranger. The questions contain 336 straight apostrophes and zero curly ones, so it never fires on a question. It fires on two titles, because the registry's headings for Valentine's and St Patrick's were typed with the proper apostrophe and the question text was not. One file, two typographic conventions, and the only code path that notices is a PDF sanitiser.

Geometry, and the one place it shows

A4 portrait, 18 mm margins, 12 mm reserved for the footer, 5.2 mm per line, body text at 10.5 pt. A numbered question gets 164 mm of width after the number's 10 mm indent, and a splitTextToSize call decides where it wraps.

Measured against Helvetica's metrics, 98 of the 1,347 questions are wider than 164 mm and wrap to a second line. They cluster: the Valentine's set has 10 of them, the 2000s set 9, the review of the year 9, while 16 sets have none at all. Long questions are a house style per page, not a property of the library.

The page breaks are decided by a function that asks whether the next block fits and starts a new sheet if it does not, so the only hard-coded page break in the whole component is the deliberate one between the questions and the answers.

What this does not tell me

Whether anybody prints them. I can measure the bytes, the sheets and the glyphs, and I cannot see a single download: the generation is entirely client side, which is the same property that makes the "nothing is uploaded" claim above checkable in your Network tab. The only signal we will ever get is indirect, and it is the one the page was built for: whether these pages start ranking for queries with the word "printable" in them.

I also cannot tell you the ink cost of a near-black heading on 157 sheets of white paper, because the PDF is drawn in grey values rather than in the site's own dark palette. Printing the HTML page instead is a different and worse story, which deserves its own measurements.

The fixes, in order of cheapness

  1. compress: true, one word, 558,788 bytes across the fleet.
  2. Cap the slug, or at least stop the apostrophe becoming a hyphen.
  3. Decide on one apostrophe for the whole content file, then delete half of the sanitiser's first branch.
  4. Keep the accent fallback. It costs nothing and it is the only reason one Hungarian name is legible.

Press the button on any question page and you get the current, uncompressed version. The next deploy will be about 30 per cent of the size, and the sheets will be identical.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.