Fitting a resume to the page automatically, without breaking it for ATS parsers
This is a layout problem, not an AI problem. Every HTML-to-PDF generator eventually runs into it: the last page that holds only a couple of lines.
I'll cover how we hit it, the options we weighed, why predicting page breaks is a dead end, and the trick we ended up using, which is to let the browser measure the layout instead of guessing it. If you generate PDFs from HTML, some of this should be directly reusable.
The situation
I'm the founder of CV by JD. We rewrite resumes for specific job descriptions, and when you're happy with the result, you download it as a PDF.
A resume PDF has two readers. One is a person, often a recruiter skimming a stack of applications. The other is an ATS (applicant tracking system), the software employers use to pull the text out of a resume and search it. A good PDF has to look finished to the first reader and stay easy to parse for the second.
How we got here
We render PDFs on our server with headless Chrome, a copy of the Chrome browser with no window, controlled by code (puppeteer-core with a serverless Chromium build). The PDF uses exactly the same HTML and CSS as the preview in the app, so what you see is what you download:
In your browser On our server
─────────────── ─────────────
Resume preview ── "Download" ─▶ The same HTML and CSS, opened in
(HTML + CSS) headless Chrome and printed to PDF
◀── resume.pdf ──
We offer five templates, each with its own fonts, spacing and margins. The templates were designed for a "typical" resume. Real resumes aren't typical. Some are half a page, some are four pages, and they almost never end neatly at the bottom of a page.
The problem
My own resume was the test case. In one template it ran to four pages, and page four held two lines from the education section followed by white space all the way down. Nothing was wrong with the content. It just looked unfinished, and that's the first impression a reader gets.
The usual fix is manual: open the file in Word, use "Shrink One Page", nudge the margins, and export again. We wanted every export to fit its pages well, automatically, for every template, without ever looking cramped and without changing what an ATS reads.
What we researched
We started by looking at how existing tools handle this. Word's "Shrink One Page" reduces font sizes until the document loses a page. Some resume builders give you sliders for spacing, margins and font size, and leave it to you.
Both approaches confirmed the same toolbox: vertical spacing, line height, margins and font size. Both also showed the risk. Shrink too far and the page looks crammed, and text at 8pt is hard to read.
Thinking through how to do this automatically, three constraints narrowed the design:
- Free knobs can combine badly. If spacing, line height, margins and font size can each move freely, some combinations fit the page but look wrong, like tiny text inside wide margins.
- Word counts don't predict page breaks. Headings that won't sit alone at the bottom of a page, list items that won't split and long URLs all move where a page ends. Two resumes with the same word count can end on different pages.
- Rendering real PDFs to search for a setting is slow. The first PDF render after a serverless function starts up takes a few seconds. Trying many settings for every download would keep users waiting.
The options we found
For what to adjust:
| Option | Problem |
|---|---|
| Shrink only the font, as Word does | Gets small quickly, and does nothing for a page that's too empty |
| Search four independent knobs | Finds strange combinations, and is hard to test or explain |
| One "fit level" that moves all four together, within limits | Fewer possible outcomes, but every one of them looks designed |
For how to decide:
| Option | Problem |
|---|---|
| Estimate from word count | Wrong too often, because page breaks depend on layout |
| Render real PDFs at several settings and pick one | Accurate, but takes many seconds per download |
| Have the browser lay the document out as pages and measure it, without printing | Needs a clever setup, but it's accurate and fast |
What we chose, and why
One number per document
Each document gets one fit level, a whole number from −8 to +8. Think of it as a single dial: negative values tighten the layout, positive values loosen it. Level 0 is the template exactly as designed.
Each other level is a fixed mix of small changes:
- vertical spacing, between 70% and 130% of the original
- line height, within fixed bounds
- side margins, between 0.35 and 0.58 inches
- font size, never below 9.5pt for body text
The four settings change together in a fixed order, so none of them runs out of room before the others. When shrinking, spacing tightens first and font size changes last. When growing, margins widen last, because wider margins frame a short page well. If a template's text is already small, we never shrink it further.
We chose this because 17 levels is a small, testable set, and every level looks like a deliberate design rather than an accident.
Let the browser measure the pages
This is the part I'd most like other people to reuse. Printing and CSS columns split content the same way. Content flows down a box of fixed height, and when the box is full it continues in the next one. In Chrome, both use the same layout engine.
So if you put the resume in a hidden container whose columns are exactly the size of one printed page's content area, Chrome breaks it into "pages" for you, side by side on screen:
┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐
│ page 1 │ │ page 2 │ │ page 3 │ │ page 4 │
│ ██████ │ │ ██████ │ │ ██████ │ │ ██ │◀ 4 columns = 4 pages,
│ ██████ │ │ ██████ │ │ ██████ │ │ │ and the last one is
│ ██████ │ │ ██████ │ │ ██████ │ │ │ only about 10% full
└────────┘ └────────┘ └────────┘ └────────┘
The CSS is short:
/* simplified */
.measure {
column-width: var(--page-content-width);
height: var(--page-content-height); /* one page's content area */
column-fill: auto;
}
Count the columns and you have the page count. Measure how far the content reaches down the last column and you know how full the last page is. This happens in an ordinary layout pass, with no PDF rendering.
Most documents are settled by measuring level 0 alone. When they aren't, a small script inside the page applies each of the 17 levels' styles in turn, lets Chrome lay the document out again, and reads the page count and fill each time, which still takes a fraction of the time of a single PDF render.
One detail matters a lot here. Chrome rounds the printed page's content height up to a whole pixel. On US Letter paper with our margins, the content area works out to 979.2 CSS pixels tall, but Chrome prints it as 980. If you measure with 979.2, a nearly full page gets predicted as spilling onto the next one, and you pick the wrong level. Round up the same way and the predictions match.
A simple rule for choosing the level
With the page count and the fullness of the last page measured at level 0:
| What we see | What we do |
|---|---|
| One page | Leave it alone |
| More than four pages | Leave it alone. The content needs cutting, not squeezing |
| Last page 30% full or less | Shrink just enough to remove that last page, picking the mildest level that does it. The new last page must stay under about 97% full, so it doesn't look crammed, and shrinking mustn't leave a big blank at the bottom of an earlier page because a block that can't be split, such as a job entry, got pushed onto the next page. If no level qualifies, leave it |
| Last page between 30% and 60% full | Grow slightly so the pages fill more evenly, but only if it keeps the same page count and actually helps |
| Fuller than that | Leave it alone |
The thinking behind the thresholds: below 30%, the leftover content is small enough that a modest shrink usually absorbs it. Between 30% and 60%, losing the page would need too much squeezing, so evening out the pages looks better. We tuned these thresholds by rendering 150 test resumes of different lengths at every level as real PDFs and comparing the results.
For my resume, that turned four pages, the last one almost empty, into three pages with the last one nearly full.
Check the real output
In the user's browser, the preview runs the same measurement and picks a level, so what you see matches what you'll download. When you click Download, the server measures again in headless Chrome, prints the PDF, and then counts the pages in the actual file. If the count doesn't match the prediction, it prints again at level 0. We'd rather send the template as designed than a surprise.
Protect the second reader
Fitting must not change what an ATS extracts. Two rules guarantee that:
- A document at level 0 is byte-for-byte unchanged. At level 0 we don't add the fitting styles at all, so Chrome receives exactly the HTML it did before this feature existed.
- The extracted words never change. Our tests render every template at every level, extract the text with
pdftotext, and check that the words match level 0 exactly.
That second test caught a real bug. One template used letter-spacing in em units on its uppercase section headings. At a larger font size the spacing grew enough that pdftotext read "SUMMARY" as "S U M M A R Y", seven one-letter words. An ATS could read it the same way, and a keyword search for "summary" would miss it. We now set heading letter-spacing in pixels.
What you can take from this
If the browser can lay it out, the browser can measure it. Multi-column layout makes a surprisingly good page simulator, and it's far faster than rendering PDFs.
One bounded setting beats several free ones. It's easier to test, easier to explain, and it can't produce strange combinations.
Match the browser's rounding, or your predictions will be off on exactly the pages that matter most: the nearly full ones.
Check the real output and keep a safe fallback for when the prediction is wrong.
If machines read your documents, test what they extract, not just what people see.
Have you used CSS layout as a measuring tool for something else? I'd like to know what else it's good for.
Comments
No comments yet. Start the discussion.