<?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>Forem: Victorien Dussart</title>
    <description>The latest articles on Forem by Victorien Dussart (@victoduss).</description>
    <link>https://forem.com/victoduss</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3758267%2F69cb1fe1-117f-4b23-99f8-2cbcba927032.png</url>
      <title>Forem: Victorien Dussart</title>
      <link>https://forem.com/victoduss</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/victoduss"/>
    <language>en</language>
    <item>
      <title>I stopped trying to make HTML paginate for printing (and it finally worked)</title>
      <dc:creator>Victorien Dussart</dc:creator>
      <pubDate>Sat, 07 Feb 2026 10:56:12 +0000</pubDate>
      <link>https://forem.com/victoduss/i-stopped-trying-to-make-html-paginate-for-printing-and-it-finally-worked-5flp</link>
      <guid>https://forem.com/victoduss/i-stopped-trying-to-make-html-paginate-for-printing-and-it-finally-worked-5flp</guid>
      <description>&lt;p&gt;For several months, I struggled with a problem many developers are familiar with:&lt;br&gt;
&lt;em&gt;printing HTML content correctly across multiple pages without breaking the layout.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Like many others, I tried the usual approaches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CSS page-break-*&lt;/li&gt;
&lt;li&gt;
&lt;a class="mentioned-user" href="https://dev.to/print"&gt;@print&lt;/a&gt; media queries&lt;/li&gt;
&lt;li&gt;headless browsers&lt;/li&gt;
&lt;li&gt;HTML → PDF generators&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They work… up to a point.&lt;/p&gt;

&lt;p&gt;As soon as the content becomes even slightly complex, dynamic, or editable, everything starts to break down: unpredictable page breaks, truncated elements, inconsistent margins, widows and orphans everywhere.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The underlying problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In hindsight, the real issue wasn’t CSS.&lt;/p&gt;

&lt;p&gt;The problem is that HTML was never designed to be paginated.&lt;br&gt;
We try to force a rendering engine built for continuous flow to produce something discrete and deterministic. Inevitably, it fails.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The turning point&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At some point, I stopped trying to “convince” HTML to paginate properly.&lt;/p&gt;

&lt;p&gt;Instead of cutting the content, I inverted the reasoning:&lt;br&gt;
&lt;em&gt;what if each page were simply a window onto a larger, continuous piece of content?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That’s when I separated two responsibilities that are often tightly coupled:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;content rendering&lt;/li&gt;
&lt;li&gt;pagination&lt;/li&gt;
&lt;li&gt;A different approach&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Concretely, the idea is to create a logical A4 page in CSS that acts as a window onto a larger HTML document, and then clone that page as many times as needed.&lt;/p&gt;

&lt;p&gt;Each page dynamically displays a different portion of the same content using vertical offsets, creating the illusion of a unified multipage document.&lt;/p&gt;

&lt;p&gt;The content is never “broken” or arbitrarily split:&lt;br&gt;
&lt;em&gt;it is simply observed through successive windows, whose size and surrounding metadata can be fully controlled.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;What you see on screen is not exactly what gets printed — and that is intentional.&lt;/p&gt;

&lt;p&gt;What this changes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This separation enables:&lt;/li&gt;
&lt;li&gt;stable and predictable multipage output&lt;/li&gt;
&lt;li&gt;documents that remain fully editable before printing&lt;/li&gt;
&lt;li&gt;deterministic pagination, even with complex content&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwk2y4hk89ixu3kgzcvdn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwk2y4hk89ixu3kgzcvdn.jpg" alt=" " width="800" height="577"&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%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fax1l95q3m3yx911fn6fv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fax1l95q3m3yx911fn6fv.jpg" alt=" " width="800" height="1098"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The implementation is intentionally simple from a technology standpoint (plain vanilla JavaScript), but it relies on a fundamentally different way of approaching the problem.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/jpvigaCajMg?si=gIzT4FVzNJAlZcz5" rel="noopener noreferrer"&gt;See results by clicking here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;PS: Please note that this approach is covered by a patent. I prefer to clarify this upfront to avoid any confusion regarding its exploitation.&lt;/em&gt;&lt;/p&gt;

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