<?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: Oleksandr (Alex) Huzei</title>
    <description>The latest articles on DEV Community by Oleksandr (Alex) Huzei (@bestkolobok).</description>
    <link>https://dev.to/bestkolobok</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%2F4276567%2F223ad329-6b23-4c17-8e93-51e404c12a21.jpg</url>
      <title>DEV Community: Oleksandr (Alex) Huzei</title>
      <link>https://dev.to/bestkolobok</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bestkolobok"/>
    <language>en</language>
    <item>
      <title>Paginating a résumé in the browser so the PDF matches the preview</title>
      <dc:creator>Oleksandr (Alex) Huzei</dc:creator>
      <pubDate>Tue, 01 Dec 2026 14:18:54 +0000</pubDate>
      <link>https://dev.to/bestkolobok/paginating-a-resume-in-the-browser-so-the-pdf-matches-the-preview-76h</link>
      <guid>https://dev.to/bestkolobok/paginating-a-resume-in-the-browser-so-the-pdf-matches-the-preview-76h</guid>
      <description>&lt;p&gt;I build Fayna, a job-search workspace where each application gets its own résumé and cover letter. People edit a résumé on the left and watch it as real A4 pages on the right. Whatever they see there has to be exactly what the exported PDF contains: same page breaks, same columns, nothing hidden at the bottom of a page.&lt;/p&gt;

&lt;p&gt;That turned out to be the hardest front-end problem in the product. Here is how the preview pagination works and the bugs that taught us its rules. The stack is Nuxt and Vue, but most of it applies to any framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why CSS page breaks were not enough
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;break-inside: avoid&lt;/code&gt; and print media queries work for a single column of text. A résumé is not that. We have two-column layouts where the left and right columns fill independently, a header that can sit over one column, section headings that must never be the last line of a page, and experience entries whose bullets may split between pages but whose job title may not be left alone.&lt;/p&gt;

&lt;p&gt;The preview also has to show pages on screen, live, while the user types. Print CSS only applies when you print. So we paginate ourselves, and the PDF renderer prints the pages we already built.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pipeline
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Blocks.&lt;/strong&gt; The résumé data becomes a list of blocks: a section heading, an experience entry header, one bullet, one skill group.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fragments with a break policy.&lt;/strong&gt; Each block becomes one or more fragments, the smallest unit allowed to move between pages. Every fragment carries a policy: &lt;code&gt;section-heading-with-first-fragment&lt;/code&gt;, &lt;code&gt;entry-header-with-first-fragment&lt;/code&gt;, &lt;code&gt;group-heading-with-first-item&lt;/code&gt;, whether it is atomic, and whether it may sit alone on a page if it is taller than a page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure.&lt;/strong&gt; A hidden measurer renders the same presenter components the live preview uses, and reads each fragment's box with &lt;code&gt;getBoundingClientRect()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assemble pages.&lt;/strong&gt; A packer fills page 1 (top area, left column, right column) before anything spills to page 2. Pages are the primary object; columns are slots on a page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Render.&lt;/strong&gt; The live preview draws the assembled pages. For export, the server stores the payload under a short-lived token, a headless browser opens the same preview page with it, and prints it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The break policy is the authority. The packer never looks at how a component happens to group its DOM.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 1: the measurer and the live preview must render the same DOM
&lt;/h2&gt;

&lt;p&gt;The packer finds each fragment in the measured DOM by a &lt;code&gt;data-block-id&lt;/code&gt; attribute. It compares the set of ids it expects with the set it finds, and the preview reports ready only when they match.&lt;/p&gt;

&lt;p&gt;That comparison has to hold in both directions, and it fails silently. If a component drops an element with an id, or renders one the pipeline did not emit, the preview never reports ready and the user sees a loader that never ends. No exception, nothing in the console.&lt;/p&gt;

&lt;p&gt;The bug that made us write this down: a skills group with a blank name. The fragment layer only emits a heading fragment for a group with a name. The component counted groups itself, came to a different number, and dropped a heading id. Endless loader.&lt;/p&gt;

&lt;p&gt;What we do now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A component never decides how to display something by counting the blocks it receives. It gets a slice of blocks for one page, so its count differs from the count the fragment layer used. The decision is resolved once, at the top, and passed down.&lt;/li&gt;
&lt;li&gt;Filtering happens in the fragment layer, never with a &lt;code&gt;v-if&lt;/code&gt; in a component that hides an element carrying an id.&lt;/li&gt;
&lt;li&gt;When the two sides disagree, we make them agree. Forcing the simpler layout usually "fixes" parity, and quietly deletes real headings from the PDF.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Rule 2: measure in layout pixels, not drawn pixels
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;getBoundingClientRect()&lt;/code&gt; returns the box as drawn, after transforms. On phones the preview opens in a full-screen modal that animates in from &lt;code&gt;scale(0.95)&lt;/code&gt;. A measurement taken during the animation saw every block 5 % shorter than it is. Desktop paginated fine; on phones page 1 ran about 40 px past the bottom of the sheet.&lt;/p&gt;

&lt;p&gt;Any rect we read under the measurer is now divided by the measured scale of its container, and a unit test pins it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 3: the measured tops must only go down
&lt;/h2&gt;

&lt;p&gt;The packer computes a page's height from measured rects: the bottom of the last fragment minus the top of the first one on that page. That only works if, in DOM order, each fragment's &lt;code&gt;top&lt;/code&gt; is greater than or equal to the previous one.&lt;/p&gt;

&lt;p&gt;CSS multi-column breaks that. The second column starts again at the top of the block, so the sequence of tops becomes a sawtooth. The parity check does not notice (it compares ids, not geometry), the loader does not stall, and the page breaks are simply wrong in both directions: on a skills section with 45 items in two columns we measured 173 px of empty space on one page and 54 px of overflow on the next.&lt;/p&gt;

&lt;p&gt;So CSS multi-column is not allowed in résumé components. A container is either a single vertical flow, or a grid where each cell is exactly one measured fragment. A new container gets checked with one line over the measurer's rects in DOM order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;tops&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;every&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;tops&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&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;h2&gt;
  
  
  Rule 4: some bugs exist only in the printed PDF
&lt;/h2&gt;

&lt;p&gt;Chromium's paged layout, the one &lt;code&gt;page.pdf()&lt;/code&gt; uses, does not resolve the grid-area containing block of an absolutely positioned grid item. It falls back to the initial containing block. In one design, the date column of every work entry was an absolutely positioned grid item. On screen everything was correct, the preview reported ready, the unit tests passed. In the PDF, every date in the résumé was painted in a pile at the top left of page 1.&lt;/p&gt;

&lt;p&gt;The fix was to keep that element in normal flow as a plain grid item with &lt;code&gt;height: auto&lt;/code&gt;. An absolutely positioned child of a positioned block element prints fine; a grid item does not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 5: watch for CSS that is dropped without a word
&lt;/h2&gt;

&lt;p&gt;In Vue, &lt;code&gt;:deep()&lt;/code&gt; only works inside &lt;code&gt;&amp;lt;style scoped&amp;gt;&lt;/code&gt;. In a non-scoped block it reaches the browser unchanged, the browser rejects the selector, and the whole rule is discarded. No warning from the build. We found five such rules that had been doing nothing for four months. Removing them changed the measured block offsets by zero.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would tell someone starting this
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Make one component tree render both the measurer and the live preview. Two trees drift.&lt;/li&gt;
&lt;li&gt;Give every movable piece of content a stable id and check the full id set, both ways.&lt;/li&gt;
&lt;li&gt;Write break rules as data on the fragment, not as structure in the template.&lt;/li&gt;
&lt;li&gt;Test the geometry you rely on (monotonic tops, layout pixels) with a one-line assertion, because a DOM without a layout engine in unit tests cannot see page breaks.&lt;/li&gt;
&lt;li&gt;Look at the actual PDF after any CSS change to a printed component. Screen and print layout are different engines.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to see the result, you can open &lt;a href="https://fayna.ai/" rel="noopener noreferrer"&gt;Fayna&lt;/a&gt; and preview your own résumé in any of its designs without signing up. I am happy to answer questions about the pipeline in the comments.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>nuxt</category>
      <category>webdev</category>
      <category>css</category>
    </item>
  </channel>
</rss>
