<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Philipp Staudt</title>
    <description>The latest articles on DEV Community by Philipp Staudt (@staudtit).</description>
    <link>https://dev.to/staudtit</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4151750%2F0808c2aa-270d-4e8d-899b-07232e81619e.jpg</url>
      <title>DEV Community: Philipp Staudt</title>
      <link>https://dev.to/staudtit</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/staudtit"/>
    <language>en</language>
    <item>
      <title>Redacting a PDF so the text is really gone</title>
      <dc:creator>Philipp Staudt</dc:creator>
      <pubDate>Thu, 19 Nov 2026 09:32:06 +0000</pubDate>
      <link>https://dev.to/staudtit/redacting-a-pdf-so-the-text-is-really-gone-4dom</link>
      <guid>https://dev.to/staudtit/redacting-a-pdf-so-the-text-is-really-gone-4dom</guid>
      <description>&lt;p&gt;A black box over a name looks final. In a PDF it is often nothing more than a rectangle drawn on top of the text. The text is still in the file, in the order a viewer reads it, and anyone who selects the line and pastes it into an editor gets it back.&lt;/p&gt;

&lt;p&gt;That is not a beginner's mistake from the early days of PDF. It keeps happening to people whose job is to get it right.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three times the text came back
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;December 2025.&lt;/strong&gt; Among the documents the US Justice Department released in December were some from a civil suit against the executors of Jeffrey Epstein's estate, filed in the US Virgin Islands in 2021. According to The New York Times, some of them were "not properly redacted digitally": blacked-out text could be read by copying it into another file. A Justice Department spokesperson said the failed redactions had been applied by the parties in the civil case and that the department had reproduced the materials (&lt;a href="https://gvwire.com/2025/12/24/redacted-material-in-some-epstein-files-is-easily-recovered/" rel="noopener noreferrer"&gt;The New York Times, republished by GV Wire&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;January 2019.&lt;/strong&gt; Paul Manafort's lawyers filed a response to the special counsel's allegations that he had lied after agreeing to plead guilty. The Associated Press could read passages of it "because it wasn't properly blacked out". They said prosecutors accused Manafort of lying about sharing polling data from the 2016 campaign with Konstantin Kilimnik, an associate accused of ties to Russian intelligence. The lawyers later filed a corrected version (&lt;a href="https://www.wgbh.org/news/national/2019-01-08/filing-manafort-accused-of-lying-about-sharing-poll-data" rel="noopener noreferrer"&gt;AP, republished by GBH&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;May 2005.&lt;/strong&gt; The US military published its report on the shooting of the Italian intelligence officer Nicola Calipari in Iraq as a PDF with large parts blacked out. A copy and paste of the document into a word processor "revealed the report in full", the names of the soldiers involved included (&lt;a href="https://www.theregister.com/2005/05/03/military_report_secrets" rel="noopener noreferrer"&gt;The Register&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Twenty years apart, the same thing happened each time: a box was drawn, and the text under it stayed.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a redaction has to remove
&lt;/h2&gt;

&lt;p&gt;Taking the words off the page is the first part. A PDF keeps text in more places than the page, and a redaction that misses one of them has not removed anything:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The page itself.&lt;/strong&gt; The characters under the box have to leave the content of the page, not just disappear from view. The same goes for a picture: its pixels under the box have to change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Copies elsewhere in the file.&lt;/strong&gt; The document's title and other metadata, its bookmarks, the values of its form fields, comments and their pop-ups, the address of a link, and files attached to it. A tagged PDF can also carry the words a screen reader speaks instead of the page's text, an ActualText, which is a second copy of the same words.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Earlier versions.&lt;/strong&gt; A PDF can be saved by appending the changes to the end of the file, and the version before the change stays inside it, readable with the right tool.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Text that is a picture.&lt;/strong&gt; A scanned page holds a photograph of the words, often with an invisible text layer from the scanner's recognition over it. Both have to go.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How Formfeed redacts
&lt;/h2&gt;

&lt;p&gt;Formfeed's &lt;a href="https://formfeed.dev/features/pdf-tools?utm_source=devto&amp;amp;utm_content=redacting-a-pdf" rel="noopener noreferrer"&gt;PDF tools&lt;/a&gt; redact a PDF by rectangles of the page or by the texts to remove, through the API, the command line and the MCP server for AI agents. The removing is done by litho, the PDF engine of Gotenberg 9, which takes out every character a region touches. Two things we measured shaped the rest:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;litho takes a character by a box that reaches up to the font's ascent, so a region the height of a line also took the line below. A found text is therefore cut by a thin band through the middle of its characters, and the black box is drawn over it separately.&lt;/li&gt;
&lt;li&gt;On the day the tools went live in production, a box over a region that held nothing to remove came back as an update appended to the untouched file: two versions in one PDF. Production refused that file, and since then such a result is written anew before anything else reads it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then the result is read again, and nothing is delivered while text lies under a rectangle, while a named text, or a single letter of it, still stands on a page, while a named text stands in the metadata, bookmarks, attachments, form or annotations, while a copy survives that cannot be cleared (such as an ActualText), or while the file keeps an earlier version. The answer is then &lt;a href="https://docs.formfeed.dev/errors/redaction-incomplete" rel="noopener noreferrer"&gt;&lt;code&gt;422 redaction_incomplete&lt;/code&gt;&lt;/a&gt;: no file, nothing charged, and the problem names the regions and texts by their number, never by their words. The texts themselves are never stored or logged.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh1nqcawysr6mp1gjas9h.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh1nqcawysr6mp1gjas9h.webp" alt="The first lines of the site's sample agreement before redaction, with the second party's name and address" width="799" height="294"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5y5pbc6ijbr2rkdm6wn5.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5y5pbc6ijbr2rkdm6wn5.webp" alt="The same lines after formfeed pdf redact, with black boxes where the name and the address stood" width="799" height="294"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The letter we left behind
&lt;/h2&gt;

&lt;p&gt;"A single letter" was not in that list until this week. While we checked every claim of this post against our own files, we copied the text out of the redacted sample agreement on our PDF tools page. It read:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2. O a company registered in England and Wales under number 00000000, whose
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"Olvarest Ltd" was gone, except its first letter, which stood under the black box. Nothing on the page showed it.&lt;/p&gt;

&lt;p&gt;The cause was a measurement we had generalised. Chrome wrote the agreement's fonts into the PDF as Type3 fonts, and litho takes a character of a Type3 font not by its own width but by the font's bounding box placed at the character. We had measured that on another document, whose boxes reached about an em, and written down 0.85 em for every such font. In the agreement, the regular font's box reaches from −0.074 to 0.995 em, so the space before the name reaches into the "O"; the bold font's box ends at 0.698 em, before the "O" itself does. To leave the space alone, the cut started just past it, three quarters of a point after the box of the "O" ended.&lt;/p&gt;

&lt;p&gt;The check did not catch it because it asked two questions: can the whole text still be found, and does a letter still stand under the cut? "Olvarest Ltd" could not be found, and the "O" stood beside the cut, not under it. Neither question was whether every letter of the text was gone.&lt;/p&gt;

&lt;p&gt;Both are fixed. Each character is now cut by its own font's box, read from the PDF: the prediction for the "O" was 82.93 to 90.17 points, litho took it between 83.0 and 90.0 when we moved a thin region across it a quarter point at a time. Where a letter cannot be cut without touching the character beside it, that character goes along, which is mostly a space or a punctuation mark. And the check holds every letter of every place a text was found to being gone, wherever the cut went. The same line now reads &lt;code&gt;2. , a company registered …&lt;/code&gt;. No customer's file was affected: the only redactions in production had been our own tests.&lt;/p&gt;

&lt;p&gt;The lesson is the one the three cases teach: look at what the file holds, not at what it shows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check a redacted PDF yourself
&lt;/h2&gt;

&lt;p&gt;You do not need our tools for this. With poppler's command-line tools and a text editor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# the page text: nothing of the removed words may come back&lt;/span&gt;
pdftotext -layout redacted.pdf - &lt;span class="o"&gt;|&lt;/span&gt; grep -i &lt;span class="s2"&gt;"olvarest"&lt;/span&gt;

&lt;span class="c"&gt;# title, author, subject and keywords&lt;/span&gt;
pdfinfo redacted.pdf

&lt;span class="c"&gt;# attached files&lt;/span&gt;
pdfdetach -list redacted.pdf

&lt;span class="c"&gt;# more than one %%EOF hints at an earlier version kept in the file&lt;/span&gt;
&lt;span class="c"&gt;# (a file saved for fast web view has two as well)&lt;/span&gt;
grep -ac &lt;span class="s1"&gt;'%%EOF'&lt;/span&gt; redacted.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bookmarks, form fields and comments are best looked at in a viewer's side panels. And copy the blacked-out line itself: if a word comes back, so will it for everyone else.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;Redaction is on the Starter plan and above, half a unit a call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;formfeed pdf redact contract.pdf --text &lt;span class="s2"&gt;"Olvarest Ltd"&lt;/span&gt; --text &lt;span class="s2"&gt;"2 Example Road"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It writes &lt;code&gt;contract-redacted.pdf&lt;/code&gt; beside the source. If anything of the texts is left, the command exits with code 1 and writes no file. The &lt;a href="https://docs.formfeed.dev/api/pdf-tools#redact" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; describes the API, the rectangles and every check.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>security</category>
      <category>privacy</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Fonts in headless Chromium: what your PDF really carries</title>
      <dc:creator>Philipp Staudt</dc:creator>
      <pubDate>Thu, 05 Nov 2026 11:45:36 +0000</pubDate>
      <link>https://dev.to/staudtit/fonts-in-headless-chromium-what-your-pdf-really-carries-3b85</link>
      <guid>https://dev.to/staudtit/fonts-in-headless-chromium-what-your-pdf-really-carries-3b85</guid>
      <description>&lt;p&gt;A template looks right in the editor, the PDF comes back, and the text is a little wider, a little rounder, and the line that used to fit now wraps. Nothing failed. There was no error, no warning and no log line. The PDF simply carries a different font from the one the template asked for.&lt;/p&gt;

&lt;p&gt;It can happen with any HTML-to-PDF service that runs Chromium on a Linux server, ours included. We rendered four one-line templates with our render worker (Chromium 153, the image we run in production) and read back which fonts each PDF embedded.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7p1kpu28lcqwyb6qlqkf.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7p1kpu28lcqwyb6qlqkf.webp" alt="Four lines of text rendered by the render worker: the first two look identical, the third is set in Inter, the fourth mixes Inter with other fonts for the check mark, cross and arrow" width="800" height="828"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;The template says&lt;/th&gt;
&lt;th&gt;The PDF carries&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;font-family: "Segoe UI", Helvetica, sans-serif&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Liberation Sans&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;font-family: Inter, sans-serif&lt;/code&gt;, nothing loaded&lt;/td&gt;
&lt;td&gt;Liberation Sans&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;font-family: Inter, sans-serif&lt;/code&gt;, Google Fonts &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Inter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;the same, text with &lt;code&gt;✓&lt;/code&gt;, &lt;code&gt;✗&lt;/code&gt; and &lt;code&gt;→&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Inter, DejaVu Sans for &lt;code&gt;✓&lt;/code&gt; and &lt;code&gt;✗&lt;/code&gt;, Liberation Sans for &lt;code&gt;→&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  A family name is a wish
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;font-family&lt;/code&gt; is a list of names, and the browser takes the first one it has. On a Windows laptop that is Segoe UI. A Linux server has no Segoe UI and no Helvetica, so Chromium goes down the list, arrives at &lt;code&gt;sans-serif&lt;/code&gt;, and the system hands it Liberation Sans. That is not a bad font: it was made with Arial's widths, so a line set for Arial keeps its length. It is just not the font the template names.&lt;/p&gt;

&lt;p&gt;The second row is the one that catches people. &lt;code&gt;Inter&lt;/code&gt; looks like a font the template has. On a designer's machine it is installed, so the editor preview shows Inter and everybody is happy. The server does not have it, and nothing in the template tells Chromium where to get it. The PDF comes out in Liberation Sans, and the first two lines of the picture are the same line.&lt;/p&gt;

&lt;p&gt;The fix is to load every font you name. Either a &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; to Google Fonts or another web font service in the template's head, or an &lt;code&gt;@font-face&lt;/code&gt; rule with the file. For fonts that are yours — a licensed corporate typeface — the same holds: serve the files from somewhere the server can fetch, and give the header and footer the &lt;code&gt;@font-face&lt;/code&gt; rule too, because Chromium prints them from a separate document that never sees the template's stylesheet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the PDF, not the preview
&lt;/h2&gt;

&lt;p&gt;The preview in your browser uses the fonts on your computer, so it cannot tell you what a server lacks. The PDF can. It lists every font it embeds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;pdffonts invoice.pdf&lt;/code&gt; from poppler-utils prints one line per font.&lt;/li&gt;
&lt;li&gt;In Acrobat or Acrobat Reader: &lt;em&gt;File → Properties → Fonts&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;In Chrome's PDF viewer there is no list; open the file in one of the above.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Names come with a six-letter prefix like &lt;code&gt;ABCDEF+Inter-Regular&lt;/code&gt;. That means the PDF carries a subset: only the characters the document uses, which keeps it small. When the list says &lt;code&gt;LiberationSans&lt;/code&gt;, &lt;code&gt;DejaVuSans&lt;/code&gt; or &lt;code&gt;NotoSans&lt;/code&gt; and your template named something else, either a font was never loaded or some characters were not in it (more on that below).&lt;/p&gt;

&lt;h2&gt;
  
  
  What a Google font costs
&lt;/h2&gt;

&lt;p&gt;The worker has to fetch a web font before it can print, and it waits for &lt;code&gt;document.fonts.ready&lt;/code&gt;, so a font that has not arrived is never skipped. That fetch takes time. We started a fresh worker three times, each with an empty cache, printed a plain page once to warm Chromium up and three more times to measure it, then printed the Inter template once and three more times. The worker reports its own render time.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Render time (median)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Page without web fonts&lt;/td&gt;
&lt;td&gt;58 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inter, first render, empty cache&lt;/td&gt;
&lt;td&gt;318 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inter, every render after&lt;/td&gt;
&lt;td&gt;72 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The first render fetched Google's stylesheet and the font files; the ones after found both in the worker's disk cache and cost 14 ms more than a page with no web font at all. In production that cache lives on a disk that outlasts restarts and deployments and keeps a file for a week, so the fetch happens once per server and week, not once per document. Organisation fonts come from our own storage and go through the same cache.&lt;/p&gt;

&lt;p&gt;Those are the numbers of a laptop in Germany talking to Google, with nothing heavy running beside it; next to three busy builds the same runs took four to five times as long, in the same proportions. The point is the shape, not the milliseconds. A service without such a cache pays the first line on every render.&lt;/p&gt;

&lt;h2&gt;
  
  
  A checkmark from a third font
&lt;/h2&gt;

&lt;p&gt;The last row is the subtle one. Inter was loaded, the words are Inter, and still the PDF embeds three fonts. The Inter files Google served for this request do not contain &lt;code&gt;✓&lt;/code&gt; and &lt;code&gt;✗&lt;/code&gt;, so Chromium looked for each character in the fonts installed on the server and found them in DejaVu Sans; the arrow came from Liberation Sans. Look at the picture: the check mark is heavier than the letters next to it, the arrow sits lower.&lt;/p&gt;

&lt;p&gt;Chromium decides this per character, silently, and the result depends on what the server has installed — our image ships DejaVu, Liberation and the Noto families, so nothing falls out as an empty box, but it may well be a different design. Three ways out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pick a font that has the symbols you use, and load it.&lt;/li&gt;
&lt;li&gt;Load a second font just for them (Noto Sans Symbols 2, say) and name it after your text font: &lt;code&gt;font-family: Inter, "Noto Sans Symbols 2", sans-serif&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Draw status marks as inline SVG, which no font decides.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  In short
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Name only fonts you load, and load every font you name.&lt;/li&gt;
&lt;li&gt;Read the font list of the PDF, not the look of the preview.&lt;/li&gt;
&lt;li&gt;The first render with a web font is slower; after that a cache should make it free.&lt;/li&gt;
&lt;li&gt;Symbols fall back one character at a time. If they matter, bring a font that has them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The four PDFs are here to check for yourself: &lt;a href="https://formfeed.dev/blog/fonts-in-headless-chromium/segoe.pdf" rel="noopener noreferrer"&gt;Segoe UI&lt;/a&gt;, &lt;a href="https://formfeed.dev/blog/fonts-in-headless-chromium/inter-not-loaded.pdf" rel="noopener noreferrer"&gt;Inter not loaded&lt;/a&gt;, &lt;a href="https://formfeed.dev/blog/fonts-in-headless-chromium/inter-google.pdf" rel="noopener noreferrer"&gt;Inter from Google Fonts&lt;/a&gt;, &lt;a href="https://formfeed.dev/blog/fonts-in-headless-chromium/inter-symbols.pdf" rel="noopener noreferrer"&gt;with symbols&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>css</category>
      <category>chromium</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Snapshot tests for documents</title>
      <dc:creator>Philipp Staudt</dc:creator>
      <pubDate>Mon, 02 Nov 2026 12:10:31 +0000</pubDate>
      <link>https://dev.to/staudtit/snapshot-tests-for-documents-28i6</link>
      <guid>https://dev.to/staudtit/snapshot-tests-for-documents-28i6</guid>
      <description>&lt;p&gt;A broken document template rarely throws an error. The API returns &lt;code&gt;200&lt;/code&gt;, a PDF is generated, and everything looks fine from the application's point of view. But the document is different from last week's: the reverse-charge note is missing, the footer contains outdated bank details, or the total uses the wrong tax rate. The people who notice are the ones receiving the document.&lt;/p&gt;

&lt;p&gt;That's why testing document templates means checking what they produce, not just whether they render successfully.&lt;/p&gt;

&lt;p&gt;This post shows how we use snapshot tests to catch unintended changes in generated documents, how to choose the right test data, and what we discovered about our own testing tool along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to compare
&lt;/h2&gt;

&lt;p&gt;Not the PDF itself. Its bytes can change with every render — at the very least because of the creation and modification dates in its metadata. A byte comparison therefore fails for reasons unrelated to the document's content. And even when two PDFs differ, the comparison doesn't tell you what changed.&lt;/p&gt;

&lt;p&gt;What is worth comparing is the document before it gets printed: the HTML assembled by the template engine from a template and a set of data.&lt;/p&gt;

&lt;p&gt;HTML is deterministic, readable, and easy to diff. A difference in the HTML is a difference you can inspect.&lt;/p&gt;

&lt;p&gt;That's what &lt;code&gt;formfeed test&lt;/code&gt; does. It renders every data set in &lt;code&gt;templates/&amp;lt;slug&amp;gt;/data/*.json&lt;/code&gt; offline, using the same engine as the render servers, and compares the output with the approved snapshot in &lt;code&gt;templates/&amp;lt;slug&amp;gt;/tests/__snapshots__/&amp;lt;data set&amp;gt;.html&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To approve intentional changes, run &lt;code&gt;formfeed test -u&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;There is one important detail: dates taken from the clock break determinism. A &lt;code&gt;date('now')&lt;/code&gt; expression, or a &lt;code&gt;date&lt;/code&gt; filter applied to a field left empty in the data set, produces different output over time. Give every data set explicit dates instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which data sets deserve a snapshot?
&lt;/h2&gt;

&lt;p&gt;A snapshot can only check what its input data actually exercises.&lt;/p&gt;

&lt;p&gt;Consider this condition in our sample invoice template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% if invoice.reverse_charge %}&amp;lt;p class="note"&amp;gt;Steuerschuldnerschaft des Leistungsempfängers.&amp;lt;/p&amp;gt;{% endif %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the project only has an ordinary invoice as test data, this line is never rendered. The snapshot cannot tell you whether it works.&lt;/p&gt;

&lt;p&gt;That's why the sample project has two data sets: &lt;code&gt;default&lt;/code&gt; and &lt;code&gt;reverse-charge&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When the wording of the note changes, &lt;code&gt;formfeed test&lt;/code&gt; reports the difference:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gd"&gt;--- invoice/reverse-charge (approved)
&lt;/span&gt;&lt;span class="gi"&gt;+++ invoice/reverse-charge (current)
&lt;/span&gt;@@
  &amp;lt;/table&amp;gt;
  &amp;lt;p class="total"&amp;gt;Gesamt 960,00 €&amp;lt;/p&amp;gt;
&lt;span class="gd"&gt;- &amp;lt;p class="note"&amp;gt;Steuerschuldnerschaft des Leistungsempfängers.&amp;lt;/p&amp;gt;
&lt;/span&gt;&lt;span class="gi"&gt;+ &amp;lt;p class="note"&amp;gt;Steuerschuldnerschaft des Leistungsempfängers (§ 13b UStG).&amp;lt;/p&amp;gt;
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;  &amp;lt;/body&amp;gt;
&lt;span class="p"&gt;1 passed, 1 failed, 0 without snapshot, 0 written
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ordinary invoice passes. The reverse-charge invoice fails because its snapshot has changed.&lt;/p&gt;

&lt;p&gt;The practical rule: create a data set for every meaningful branch of your template.&lt;/p&gt;

&lt;p&gt;For an invoice, that might mean:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An invoice with one line and one with many lines.&lt;/li&gt;
&lt;li&gt;A customer with and without a VAT ID.&lt;/li&gt;
&lt;li&gt;An ordinary invoice and a credit note.&lt;/li&gt;
&lt;li&gt;Each language you support.&lt;/li&gt;
&lt;li&gt;Special tax cases, such as reverse charge.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal isn't to create as many data sets as possible. It's to cover the different documents your template can actually produce.&lt;/p&gt;

&lt;p&gt;In our case, the editor uses the same data sets for its preview, so maintaining them rarely means doing the same work twice.&lt;/p&gt;

&lt;h2&gt;
  
  
  When the finance team changes the footer
&lt;/h2&gt;

&lt;p&gt;Now consider a change that happens sooner or later in almost every company: finance updates the bank details in the footer and adds the BIC.&lt;/p&gt;

&lt;p&gt;There was a problem, though. Chromium renders PDF headers and footers from separate templates in the page margins, outside the document body.&lt;/p&gt;

&lt;p&gt;When we ran the tests while preparing this post, they passed. &lt;code&gt;formfeed test&lt;/code&gt; compared only the document body, so a change to &lt;code&gt;footer.html&lt;/code&gt; went unnoticed.&lt;/p&gt;

&lt;p&gt;In other words, we had a test that passed even though an important part of the document was no longer covered.&lt;/p&gt;

&lt;p&gt;We fixed that. Since &lt;code&gt;formfeed&lt;/code&gt; 0.3.7, snapshots include the header and footer as well, each separated by a marker line.&lt;/p&gt;

&lt;p&gt;The same change now produces a diff like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gd"&gt;--- invoice/default (approved)
&lt;/span&gt;&lt;span class="gi"&gt;+++ invoice/default (current)
&lt;/span&gt;@@
  &amp;lt;!-- formfeed:footer --&amp;gt;
  &amp;lt;div style="width:100%;padding:0 18mm;font-size:8px;color:#555;display:flex;justify-content:space-between"&amp;gt;
&lt;span class="gd"&gt;-   &amp;lt;span&amp;gt;Fennlor Studio GmbH · IBAN DE36 0000 0000 0000 0000 00&amp;lt;/span&amp;gt;
&lt;/span&gt;&lt;span class="gi"&gt;+   &amp;lt;span&amp;gt;Fennlor Studio GmbH · IBAN DE36 0000 0000 0000 0000 00 · BIC XXXXDEXXXXX&amp;lt;/span&amp;gt;
&lt;/span&gt;    &amp;lt;span&amp;gt;Seite &amp;lt;span class="pageNumber"&amp;gt;&amp;lt;/span&amp;gt; von &amp;lt;span class="totalPages"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;
  &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The footer appears in every invoice snapshot, so the change is visible in each relevant data set.&lt;/p&gt;

&lt;p&gt;One migration detail: if your templates use headers or footers and you're upgrading from &lt;code&gt;formfeed&lt;/code&gt; 0.3.6 or earlier, the first &lt;code&gt;formfeed test&lt;/code&gt; will fail once because the snapshots don't contain those sections yet. Run &lt;code&gt;formfeed test -u&lt;/code&gt; and commit the updated snapshots.&lt;/p&gt;

&lt;h2&gt;
  
  
  In the pull request
&lt;/h2&gt;

&lt;p&gt;When someone changes a template, they run &lt;code&gt;formfeed test -u&lt;/code&gt; and commit the resulting snapshots alongside the template changes.&lt;/p&gt;

&lt;p&gt;The pull request then shows both sides of the change: the edited &lt;code&gt;footer.html&lt;/code&gt; and every snapshot affected by it.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;templates/invoice/footer.html                             | 2 +-
templates/invoice/tests/__snapshots__/default.html        | 2 +-
templates/invoice/tests/__snapshots__/reverse-charge.html | 2 +-
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A reviewer can see not only what changed, but which documents are affected.&lt;/p&gt;

&lt;p&gt;And sometimes the most useful finding is a snapshot that changes even though nobody intended it to.&lt;/p&gt;

&lt;h2&gt;
  
  
  From HTML diffs to actual PDFs
&lt;/h2&gt;

&lt;p&gt;Reading HTML is not the same as looking at the finished invoice. A snapshot tells you that the markup changed, but not whether the resulting document still looks right.&lt;/p&gt;

&lt;p&gt;That's why our pipeline also renders the PDFs.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;formfeed ci preview&lt;/code&gt; renders templates changed since the base branch through the API, using a test key. It saves the resulting PDFs and generates a summary that can be posted to the pull request.&lt;/p&gt;

&lt;p&gt;Here's the output from the run for this post, against our local stack:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;## Formfeed preview&lt;/span&gt;

Templates changed against &lt;span class="sb"&gt;`main`&lt;/span&gt;: 1

| Template | Data set | Pages | Output |
| --- | --- | --- | --- |
| &lt;span class="sb"&gt;`invoice`&lt;/span&gt; | default | 1 | &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;invoice.pdf&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&gt;…signed&lt;/span&gt; link…) |

Rendered with a Formfeed test key; links expire.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The GitHub Action in the &lt;a href="https://docs.formfeed.dev/cli/ci" rel="noopener noreferrer"&gt;CI documentation&lt;/a&gt; runs &lt;code&gt;formfeed validate&lt;/code&gt; and &lt;code&gt;formfeed test&lt;/code&gt; on every pull request. If configured with a test key as its &lt;code&gt;api-key&lt;/code&gt;, it also runs &lt;code&gt;formfeed ci preview&lt;/code&gt; and posts the summary as a comment that gets updated with each run.&lt;/p&gt;

&lt;p&gt;Test keys are not metered, so these previews don't add to your API usage.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a snapshot does not see
&lt;/h2&gt;

&lt;p&gt;A snapshot checks markup, not layout.&lt;/p&gt;

&lt;p&gt;If a row moves to the second page because a line above it becomes longer, the diff shows the longer line and nothing more: the row's own markup stays exactly the same, and nothing in the snapshot says that it now starts page two.&lt;/p&gt;

&lt;p&gt;That's why snapshot tests are only one part of document testing. For layout issues, there's the rendered preview in the pull request, the paged preview in the editor, and &lt;strong&gt;True render&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For the rest of the testing setup, see the &lt;a href="https://docs.formfeed.dev/devkit/testing" rel="noopener noreferrer"&gt;testing guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And if you're wondering why document templates belong in a repository in the first place, we covered that in &lt;a href="https://formfeed.dev/blog/templates-belong-in-git?utm_source=devto&amp;amp;utm_content=snapshot-tests-for-documents" rel="noopener noreferrer"&gt;an earlier post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The important distinction is simple: a successful render doesn't mean a correct document. Snapshot tests catch changes in what your templates produce; rendered previews help catch changes in how those documents look. Together, they give you a much better chance of catching a broken invoice before someone sends it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Run on 21 September 2026 with the &lt;code&gt;formfeed&lt;/code&gt; CLI on a sample project; the outputs above are copied from that run.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>git</category>
      <category>testing</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The preview that lies, and the one that doesn't</title>
      <dc:creator>Philipp Staudt</dc:creator>
      <pubDate>Thu, 29 Oct 2026 09:37:36 +0000</pubDate>
      <link>https://dev.to/staudtit/the-preview-that-lies-and-the-one-that-doesnt-1je7</link>
      <guid>https://dev.to/staudtit/the-preview-that-lies-and-the-one-that-doesnt-1je7</guid>
      <description>&lt;p&gt;Every document editor has a preview, and the PDF is always made somewhere else. The question worth asking of any preview is not whether it looks right, but whether page 1 ends where the PDF's page 1 ends. A browser window has no pages at all. Switching it to print styles (&lt;code&gt;@media print&lt;/code&gt;) changes the styles and still has no pages. The browser's print dialog does paginate, but with its own margins and, unless you untick them, its own header and footer — not the ones your API renders.&lt;/p&gt;

&lt;p&gt;Our editor has a flow preview for writing and a paged preview for layout. The paged one uses &lt;a href="https://pagedjs.org" rel="noopener noreferrer"&gt;Paged.js&lt;/a&gt;, which paginates HTML in the browser following the CSS paged-media rules; the PDF comes from headless Chromium on our render servers. So we measured whether the two agree.&lt;/p&gt;

&lt;h2&gt;
  
  
  The test
&lt;/h2&gt;

&lt;p&gt;One short report: a heading, a banner, and 24 cards. Each card is &lt;code&gt;height: 22mm&lt;/code&gt; with &lt;code&gt;padding: 5mm&lt;/code&gt; and a border, the way a template sets a box to a height — and each is kept whole with &lt;code&gt;break-inside: avoid&lt;/code&gt;. A4 with margins of 20 mm at the top and bottom and 18 mm at the sides, and a page-number footer. We printed it with our render worker, laid it out in Chromium with Paged.js as it ships and with our paged preview, and counted the cards on every page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnrf9tc180waohpoxikl3.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnrf9tc180waohpoxikl3.webp" alt="Page 1 three times: Paged.js as shipped with nine short cards, the paged preview with six, the PDF with six" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Cards per page&lt;/th&gt;
&lt;th&gt;Pages&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Paged.js as it ships (left)&lt;/td&gt;
&lt;td&gt;9 · 10 · 5&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Our paged preview (middle)&lt;/td&gt;
&lt;td&gt;6 · 7 · 7 · 4&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The &lt;a href="https://formfeed.dev/blog/preview-that-matches-the-pdf/cards.pdf" rel="noopener noreferrer"&gt;PDF&lt;/a&gt; (right)&lt;/td&gt;
&lt;td&gt;6 · 7 · 7 · 4&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The preview and the PDF agree card for card. Paged.js as it ships gets every page wrong and the page count too.&lt;/p&gt;

&lt;h2&gt;
  
  
  The rule that made the difference
&lt;/h2&gt;

&lt;p&gt;The two previews differ in one thing. Paged.js's own stylesheet contains &lt;code&gt;.pagedjs_pagebox * { box-sizing: border-box }&lt;/code&gt;. It is meant for the boxes Paged.js builds around each page, but the selector reaches everything inside a page, your template included. Under &lt;code&gt;border-box&lt;/code&gt;, a height includes the padding and the border; under the browser's default &lt;code&gt;content-box&lt;/code&gt;, which Chromium uses when it prints, they come on top. So each card is 22 mm tall in Paged.js as it ships and a little over 32 mm in the PDF, and Paged.js fits nine where the PDF fits six.&lt;/p&gt;

&lt;p&gt;Our preview rewrites that one rule as the stylesheet arrives, before anything is laid out, so that it applies only to Paged.js's own boxes (&lt;code&gt;[class*="pagedjs_"]&lt;/code&gt;). Your elements keep the box model they will have in the PDF. The same thinking applies to our print reset: the preview's header and footer boxes are left out of it, because Chromium's header and footer templates get none of it either.&lt;/p&gt;

&lt;h2&gt;
  
  
  The case no preview can show
&lt;/h2&gt;

&lt;p&gt;Now make the banner "full width" the usual way: &lt;code&gt;width: 100%&lt;/code&gt; plus its &lt;code&gt;padding: 5mm 10mm&lt;/code&gt;. Under &lt;code&gt;content-box&lt;/code&gt; that is 20 mm wider than the space between the margins.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7and1xndcp6dlno0q4je.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7and1xndcp6dlno0q4je.webp" alt="Page 1 from three sources: Paged.js as shipped fits the banner, the Formfeed preview lets it run past the right margin, and in the PDF everything is smaller and six cards became seven" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each picture in this post is page 1 of the same document, from three sources — not three pages. Paged.js as it ships does not even show the problem: under its &lt;code&gt;border-box&lt;/code&gt; rule the padding counts inside the 100 %, and the banner fits. Our preview shows what the document asks for: the banner runs past the right margin. The &lt;a href="https://formfeed.dev/blog/preview-that-matches-the-pdf/wide-banner.pdf" rel="noopener noreferrer"&gt;PDF&lt;/a&gt; does something else. Chromium scales the whole document down until its widest element fits the page — here to 89.7 %, so the 10 pt card titles come out at 8.97 pt — and does it on every page, not only the one with the banner. Smaller pages hold more: 7 · 8 · 8 · 1 cards instead of 6 · 7 · 7 · 4.&lt;/p&gt;

&lt;p&gt;No preview that lays out at 100 % can reproduce that, ours included. What it can do is find the cause, and ours now says it in words: the preview measures the widest element after every layout, and when one reaches past the margin, the editor lists it under Problems — how many millimetres too wide, and to what size the PDF will shrink (here 20 mm and 89.7 %) — with a link to the tag in the template. Give such an element &lt;code&gt;box-sizing: border-box&lt;/code&gt;, or leave its width alone — a block is as wide as its container without being told.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we take from it
&lt;/h2&gt;

&lt;p&gt;A preview earns trust by breaking where the PDF breaks, and that is a property you can measure: same document, same page size, count what lands on each page. Ours does, until a template asks Chromium to shrink. For the last word, the editor's &lt;strong&gt;True render&lt;/strong&gt; sends the draft through the same worker that printed the PDFs above, and costs nothing.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://docs.formfeed.dev/getting-started/editor-tour" rel="noopener noreferrer"&gt;editor tour&lt;/a&gt; shows the preview modes and True render, and the &lt;a href="https://formfeed.dev/examples/invoice?utm_source=devto&amp;amp;utm_content=preview-that-matches-the-pdf" rel="noopener noreferrer"&gt;invoice example&lt;/a&gt; is a document to try them on.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Measured on 21 September 2026 with Chromium 153.0.8010.12 on the render worker and Paged.js 0.4.3.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>css</category>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Let the agent write the data, not the HTML</title>
      <dc:creator>Philipp Staudt</dc:creator>
      <pubDate>Mon, 05 Oct 2026 10:53:23 +0000</pubDate>
      <link>https://dev.to/staudtit/let-the-agent-write-the-data-not-the-html-24pe</link>
      <guid>https://dev.to/staudtit/let-the-agent-write-the-data-not-the-html-24pe</guid>
      <description>&lt;p&gt;There are two ways to let an AI agent produce an invoice. You can ask it for the invoice: it writes HTML, something prints it, and a PDF comes out. Or you can hand it an invoice template someone has already reviewed and ask it only for the facts — who, what, how many, at what rate — as JSON.&lt;/p&gt;

&lt;p&gt;The first way works in a demo. The second one is the one that survives a second run.&lt;/p&gt;

&lt;h2&gt;
  
  
  A document is a promise to look the same
&lt;/h2&gt;

&lt;p&gt;A model writes by sampling. Ask it twice for "an invoice for these two line items" and nothing ties the second answer to the first: the column order, the wording of the VAT line, whether the payment terms mention a due date, whether the legal footer is there at all. Each run is a new draft that nobody reviewed. For a birthday card that is charming. For an invoice, which in Germany has to carry a list of mandatory details, it means reviewing every single one the agent sends — at which point the agent saved nobody any work.&lt;/p&gt;

&lt;p&gt;A template turns that around. The layout, the legal lines, the arithmetic and the payment code are written once, looked at by a person, versioned and published. What varies between runs is the data, and the data is the part a model is actually good at: pulling a customer name out of an email, the quantities out of a spreadsheet, the rate out of a contract.&lt;/p&gt;

&lt;p&gt;The shape that works has four parts, and our &lt;a href="https://formfeed.dev/integrations/mcp?utm_source=devto&amp;amp;utm_content=let-the-agent-write-the-data" rel="noopener noreferrer"&gt;MCP server&lt;/a&gt; has a tool for each:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Costs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Find the template&lt;/td&gt;
&lt;td&gt;&lt;code&gt;list_templates&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;nothing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Learn what it expects&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;get_template_schema&lt;/code&gt; — the JSON Schema of the data, plus the sample data it was designed with&lt;/td&gt;
&lt;td&gt;nothing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Check the data&lt;/td&gt;
&lt;td&gt;&lt;code&gt;validate_template&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;nothing: the API checks a stored template without rendering it; ad-hoc HTML is checked inside the MCP server&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Render&lt;/td&gt;
&lt;td&gt;&lt;code&gt;render&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;nothing with a test key; with a live key one unit per started five PDF pages&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Test keys (&lt;code&gt;ff_test_…&lt;/code&gt;) render the same templates through the same pipeline and are never metered; their outputs are kept for 24 hours, and on the Free plan they carry a watermark.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the data still goes wrong
&lt;/h2&gt;

&lt;p&gt;Giving the model the data to write does not make the data right. So we took a short invoice template and fed &lt;code&gt;validate_template&lt;/code&gt; the data an agent tends to produce, then rendered each version. We passed the template itself as HTML, which the tool checks offline, inside the MCP server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;table&amp;gt;
  {% for line in invoice.lines %}
  &amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;{{ line.description }}&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;{{ line.qty }}&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;{{ line.price | money }}&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;{{ line.total | money }}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;
  {% endfor %}
&amp;lt;/table&amp;gt;
{% set net = invoice.lines | sum('total') %}
{% set vat = net * invoice.vat_rate / 100 %}
&amp;lt;p&amp;gt;Gesamt {{ (net + vat) | money }}&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the data it was written for, validation reports nothing and the invoice ends in &lt;strong&gt;Gesamt 3.760,40 €&lt;/strong&gt;. Then the agent's versions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The agent leaves out the line totals&lt;/strong&gt;, expecting the template to multiply quantity by price. This one does not. &lt;code&gt;validate_template&lt;/code&gt; answers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"ok"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"diagnostics"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"severity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"warning"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"unknown-variable"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;line.total&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; is not present in the sample data"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"line"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"column"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the rendered invoice ends in &lt;strong&gt;Gesamt 0,00 €&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The agent calls the list &lt;code&gt;items&lt;/code&gt;&lt;/strong&gt;, because that reads as well as &lt;code&gt;lines&lt;/code&gt; to a model that did not look at the schema. Validation warns five times, once for &lt;code&gt;invoice.lines&lt;/code&gt; and once for each field under it, again with &lt;code&gt;"ok": true&lt;/code&gt;. The rendered invoice has no lines and totals &lt;strong&gt;0,00 €&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The agent writes the rate as &lt;code&gt;"19 %"&lt;/code&gt;&lt;/strong&gt;, the way it appears on the contract it read. The offline check reports nothing: it knows which names the template reads, not what kind of value belongs in them. When we first ran this, the rendered invoice ended in &lt;strong&gt;Gesamt NaN&lt;/strong&gt;. That was a bug in our &lt;code&gt;money&lt;/code&gt; helper, and it is fixed: &lt;code&gt;money&lt;/code&gt;, &lt;code&gt;number&lt;/code&gt; and &lt;code&gt;numToWords&lt;/code&gt; now stop the render with &lt;code&gt;money: got NaN, the result of a calculation with a value that is missing or not a number&lt;/code&gt; rather than print &lt;code&gt;NaN&lt;/code&gt; on a document. Text that is not a number, such as &lt;code&gt;"on request"&lt;/code&gt;, still prints as it is.&lt;/p&gt;

&lt;h2&gt;
  
  
  The check that knows the values
&lt;/h2&gt;

&lt;p&gt;An agent rarely brings its own HTML. It fills a template stored in Formfeed, and for a stored template &lt;code&gt;validate_template&lt;/code&gt; does not check offline: it asks the API, free and without rendering, to check the version a render would use. That check runs the template once with the data, so the &lt;code&gt;"19 %"&lt;/code&gt; above comes back as an error before anything is printed, and it compares the data with the template's stored JSON Schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"severity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"data-validation"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"data.invoice.vat_rate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"data.invoice.vat_rate: must be number"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The schema check needs a stored schema. Every template has one inferred from its sample data, which is what &lt;code&gt;get_template_schema&lt;/code&gt; hands the agent, but only a schema you stored decides what counts as wrong — an inferred one would reject data for leaving out a field the sample happened to have. In the editor, &lt;strong&gt;Store as contract&lt;/strong&gt; in the data and schema panel stores one; with the CLI, a &lt;code&gt;schema.json&lt;/code&gt; next to the template does. Store one for every template an agent fills.&lt;/p&gt;

&lt;p&gt;Two things follow either way. First, &lt;code&gt;ok: true&lt;/code&gt; means &lt;em&gt;nothing will fail&lt;/em&gt;, not &lt;em&gt;the data is right&lt;/em&gt;: missing data is a warning, because a template may deliberately leave optional fields out. An agent should treat every warning as a question to answer before it renders. Second, a check only knows what it has been told. While you set an agent up, connect it with a test key: every render costs nothing, and reading a handful of results checks what no validation can, such as whether the right customer ended up on the invoice.&lt;/p&gt;

&lt;p&gt;The offline results above come from a test in the MCP server's own repository, which runs the real tools with a network stub that fails on any request, so it also shows that ad-hoc HTML and its data never leave the machine the server runs on while they are checked: &lt;a href="https://github.com/formfeed-dev/formfeed/blob/main/packages/mcp/src/lib/validate-agent-data.spec.ts" rel="noopener noreferrer"&gt;validate-agent-data.spec.ts&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to tell the agent
&lt;/h2&gt;

&lt;p&gt;The MCP server already tells a connected agent the order: list, read the schema, validate, render. What it cannot know is how strict to be with your documents. A few lines in the agent's instructions close that gap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before rendering a document:
1. Read the template's schema and sample data with get_template_schema, and use the same field names.
2. Call validate_template with your data. Fix every diagnostic, warnings included.
3. Numbers are numbers: 19, not "19 %"; 1200.5, not "1.200,50".
4. Before handing a document on, compare its totals with the data you sent.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model still writes the part that changes. The part that must not change was written by a person, once, and the agent never gets to touch it.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://formfeed.dev/agents?utm_source=devto&amp;amp;utm_content=let-the-agent-write-the-data" rel="noopener noreferrer"&gt;agents page&lt;/a&gt; has the setup for Claude Code, Cursor, VS Code, Codex and a dozen more clients and frameworks, and the &lt;a href="https://docs.formfeed.dev/integrations/mcp" rel="noopener noreferrer"&gt;MCP documentation&lt;/a&gt; lists every tool with its arguments.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Checked on 5 October 2026. The schema check in &lt;code&gt;validate_template&lt;/code&gt; needs &lt;code&gt;@formfeed/mcp&lt;/code&gt; 0.3.6 or later.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>mcp</category>
      <category>pdf</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Page breaks in tables: what Chromium honours in 2026</title>
      <dc:creator>Philipp Staudt</dc:creator>
      <pubDate>Wed, 30 Sep 2026 08:34:24 +0000</pubDate>
      <link>https://dev.to/staudtit/page-breaks-in-tables-what-chromium-honours-in-2026-258g</link>
      <guid>https://dev.to/staudtit/page-breaks-in-tables-what-chromium-honours-in-2026-258g</guid>
      <description>&lt;p&gt;A table that fits on one page is easy. The trouble starts at the page break: a header that does not come back, a row cut through the middle, a total printed under the first thirty rows, a footer lying on top of the last line. Most advice about this was written for browsers that paginated differently, and gets copied forward.&lt;/p&gt;

&lt;p&gt;So we measured. We rendered 21 small table documents through our render worker — the same headless Chromium, version 153.0.8010.12, that prints every Formfeed PDF — and read the finished PDFs back with pdf.js to see which page every row, header and total landed on. Every case below links to its PDF.&lt;/p&gt;

&lt;h2&gt;
  
  
  The starting point
&lt;/h2&gt;

&lt;p&gt;Every Formfeed document starts with a short print reset. Four of its lines are about tables (in effect; the real rules sit in &lt;code&gt;:where()&lt;/code&gt; so that any rule of the template wins):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;table&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;break-inside&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;border-collapse&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;collapse&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;tr&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;break-inside&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;avoid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;thead&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;table-header-group&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;tfoot&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;table-footer-group&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;tr&lt;/code&gt; line is ours, not Chromium's: without it, Chromium splits a row wherever the page ends. The cases use A4 with 20 mm margins, ten-point text, and a page-number footer from Chromium's footer template unless they say otherwise. Rows are numbered, and a tall row's lines are numbered too (&lt;code&gt;08·5&lt;/code&gt; is the fifth line of row 8), so a split shows.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Chromium keeps
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Case&lt;/th&gt;
&lt;th&gt;CSS&lt;/th&gt;
&lt;th&gt;What the PDF shows&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;60 rows&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;the header row repeats at the top of page 2&lt;/td&gt;
&lt;td&gt;&lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/long-table.pdf" rel="noopener noreferrer"&gt;PDF&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;rows six lines tall&lt;/td&gt;
&lt;td&gt;&lt;code&gt;tr { break-inside: avoid }&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;7 whole rows per page, none split&lt;/td&gt;
&lt;td&gt;&lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/tall-rows.pdf" rel="noopener noreferrer"&gt;PDF&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;the same rows&lt;/td&gt;
&lt;td&gt;&lt;code&gt;tr { break-inside: auto }&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;rows 8, 16 and 24 split across pages&lt;/td&gt;
&lt;td&gt;&lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/tall-rows-auto.pdf" rel="noopener noreferrer"&gt;PDF&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;one row of 90 lines&lt;/td&gt;
&lt;td&gt;&lt;code&gt;tr { break-inside: avoid }&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the row starts a new page and then splits anyway; all 90 lines are printed&lt;/td&gt;
&lt;td&gt;&lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/row-taller-than-page.pdf" rel="noopener noreferrer"&gt;PDF&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;groups of six rows, each its own &lt;code&gt;tbody&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;tbody { break-inside: avoid }&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;page 1 ends after row 30, a group boundary, instead of row 32&lt;/td&gt;
&lt;td&gt;&lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/tbody-groups.pdf" rel="noopener noreferrer"&gt;PDF&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;a heading at the foot of a page&lt;/td&gt;
&lt;td&gt;&lt;code&gt;h2 { break-after: avoid }&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the heading moves to the next page with its table&lt;/td&gt;
&lt;td&gt;&lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/heading-kept.pdf" rel="noopener noreferrer"&gt;PDF&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;the last row alone on a page&lt;/td&gt;
&lt;td&gt;&lt;code&gt;tbody tr:last-child { break-before: avoid }&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;row 8 goes along: 7 rows, then 2&lt;/td&gt;
&lt;td&gt;&lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/last-row-kept.pdf" rel="noopener noreferrer"&gt;PDF&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;the last two rows as their own &lt;code&gt;tbody&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;tbody.tail { break-inside: avoid }&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the same, 7 and 2&lt;/td&gt;
&lt;td&gt;&lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/last-rows-kept-tbody.pdf" rel="noopener noreferrer"&gt;PDF&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;the table inside a flex, grid, &lt;code&gt;overflow: auto&lt;/code&gt;, &lt;code&gt;overflow: hidden&lt;/code&gt; or absolutely positioned wrapper&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;paginates like a bare table, header repeated&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/flex-wrapper.pdf" rel="noopener noreferrer"&gt;flex&lt;/a&gt; · &lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/grid-wrapper.pdf" rel="noopener noreferrer"&gt;grid&lt;/a&gt; · &lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/overflow-auto-wrapper.pdf" rel="noopener noreferrer"&gt;auto&lt;/a&gt; · &lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/overflow-hidden-wrapper.pdf" rel="noopener noreferrer"&gt;hidden&lt;/a&gt; · &lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/absolute-wrapper.pdf" rel="noopener noreferrer"&gt;absolute&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The last row surprised us most, because every one of those wrappers turns up in advice on why a table stopped paginating. In Chromium 153 none of them stops it.&lt;/p&gt;

&lt;p&gt;The two keep-together rules are the ones worth having in every template. Without them, the heading stays behind on its own:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fasfs3hq1mg8aketznjw5.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fasfs3hq1mg8aketznjw5.webp" alt="A section heading alone at the foot of page 1, its table starting on page 2" width="800" height="704"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and the last row of a table ends up alone on a page of its own:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr1ekltiq0i6khvtysgun.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr1ekltiq0i6khvtysgun.webp" alt="Rows 1 to 8 on page 1, row 9 alone under a repeated header on page 2" width="800" height="704"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;break-before: avoid&lt;/code&gt; on the last row, Chromium takes the row before it along, so no page holds a single row:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fld7nk6d5zgdfjxgt3kg5.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fld7nk6d5zgdfjxgt3kg5.webp" alt="Rows 1 to 7 on page 1, rows 8 and 9 on page 2" width="800" height="704"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this is what a tall row looks like when nothing asks Chromium to keep it together — the amount stays on page 1 and the last two lines of the description go to page 2:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnhc3mmewhxlg9lwnsv8m.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnhc3mmewhxlg9lwnsv8m.webp" alt="Row 8 split across two pages, its lines 5 and 6 under the repeated header on page 2" width="800" height="704"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Three ways to get it wrong
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The total on every page
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;tfoot&lt;/code&gt; looks like the place for a total. But a &lt;code&gt;tfoot&lt;/code&gt; is a footer group, and Chromium repeats it at the foot of every page the table reaches, just as it repeats &lt;code&gt;thead&lt;/code&gt; at the top. The grand total turns up under row 31 on page 1:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh5hl9efdjw12uufl6x39.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh5hl9efdjw12uufl6x39.webp" alt="The total 7,200.00 printed at the foot of page 1, after row 31 of 60" width="800" height="704"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two fixes. Put the total in a last &lt;code&gt;tbody&lt;/code&gt; of its own. Or keep the &lt;code&gt;tfoot&lt;/code&gt; and turn it into an ordinary row group, &lt;code&gt;tfoot { display: table-row-group; }&lt;/code&gt; — then it prints once, on the last page, &lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/tfoot-once.pdf" rel="noopener noreferrer"&gt;as long as it comes after the &lt;code&gt;tbody&lt;/code&gt; in the markup&lt;/a&gt;. HTML also allows the &lt;code&gt;tfoot&lt;/code&gt; before the &lt;code&gt;tbody&lt;/code&gt;; with the override, such a total &lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/tfoot-first-once.pdf" rel="noopener noreferrer"&gt;prints above the first row&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The repeat cannot carry a running subtotal either. What Chromium repeats is a copy of the same content, so a "carried forward" line that sums the rows above it on each page is not something a &lt;code&gt;tfoot&lt;/code&gt; can do.&lt;/p&gt;

&lt;h3&gt;
  
  
  A row cut in half
&lt;/h3&gt;

&lt;p&gt;Wrap the table in &lt;code&gt;display: inline-block&lt;/code&gt; — a common way to centre it or shrink it to its content — and Chromium stops paginating the table inside. It prints the box across the page edge as it is: row 33 is cut through the middle, and page 2 has no header.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffcbbqp6oqhumsi9nxjm2.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffcbbqp6oqhumsi9nxjm2.webp" alt="Row 33 sliced horizontally at the foot of page 1, its lower half at the top of page 2, no header on page 2" width="800" height="704"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A block wrapper does not do this. &lt;code&gt;thead { display: block; }&lt;/code&gt;, which some scrolling-table CSS sets, keeps the rows whole but &lt;a href="https://formfeed.dev/blog/page-breaks-in-tables/thead-display-block.pdf" rel="noopener noreferrer"&gt;loses the repeated header&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The row under the footer
&lt;/h3&gt;

&lt;p&gt;A footer made with &lt;code&gt;position: fixed; bottom: 0&lt;/code&gt; does repeat on every page. The table does not know it is there. Row 32 slides underneath, and since the table thinks row 32 fitted, page 2 carries on with row 33 — row 32 is never printed whole:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh61r87z8u87gt0q0raig.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh61r87z8u87gt0q0raig.webp" alt="A fixed footer covering the lower half of row 32; page 2 starts at row 33" width="800" height="704"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The clean fix is not to put the footer in the page at all. Chromium's own footer template is printed in the bottom margin, where content never reaches; every other case in this post has one, and none lost a row to it. If the footer has to live in the page, the repeat that caused the first problem solves this one: an empty &lt;code&gt;tfoot&lt;/code&gt; row as tall as the footer repeats on every page and keeps the rows clear of it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;tfoot&amp;gt;&amp;lt;tr&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"reserve"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;td&lt;/span&gt; &lt;span class="na"&gt;colspan=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/tfoot&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;tr&lt;/span&gt;&lt;span class="nc"&gt;.reserve&lt;/span&gt; &lt;span class="nt"&gt;td&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10mm&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdb82wp73sqab558tsiwc.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdb82wp73sqab558tsiwc.webp" alt="Row 31 is the last on page 1, clear of the fixed footer; page 2 starts at row 32" width="800" height="704"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The short version
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Keep rows whole with &lt;code&gt;tr { break-inside: avoid }&lt;/code&gt;, and groups of rows with a &lt;code&gt;tbody&lt;/code&gt; each and &lt;code&gt;break-inside: avoid&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Keep headings with their table: &lt;code&gt;h2 { break-after: avoid }&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Keep the last row company: &lt;code&gt;tbody tr:last-child { break-before: avoid }&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Put totals in a last &lt;code&gt;tbody&lt;/code&gt;, or make the &lt;code&gt;tfoot&lt;/code&gt; a &lt;code&gt;table-row-group&lt;/code&gt; after the &lt;code&gt;tbody&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;inline-block&lt;/code&gt; around a table, no &lt;code&gt;display: block&lt;/code&gt; on its &lt;code&gt;thead&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Footers go in the footer template, not in &lt;code&gt;position: fixed&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  In Formfeed
&lt;/h2&gt;

&lt;p&gt;The print reset above is on by default and every line of it can be overridden. The Footer tab of the editor is Chromium's footer template, so a footer made there sits in the margin. The editor's paged preview is built to lay out like the PDF, and &lt;strong&gt;True render&lt;/strong&gt; sends the template through the same worker these cases went through. The &lt;a href="https://docs.formfeed.dev/templates/writing-templates#page-breaks" rel="noopener noreferrer"&gt;page-break section of the docs&lt;/a&gt; has the reset, and the &lt;a href="https://formfeed.dev/examples/report?utm_source=devto&amp;amp;utm_content=page-breaks-in-tables" rel="noopener noreferrer"&gt;report example&lt;/a&gt; is a two-page document with a chart and a table of monthly figures.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Rendered and measured on 21 September 2026 with Chromium 153.0.8010.12. Chromium's layout changes between versions; we re-run the cases when the worker's Chromium does.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>css</category>
      <category>html</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
