DEV Community

venn
venn

Posted on AI-assisted

Detecting two-column resumes in the browser with pdf.js

A lot of resume advice says "don't use two columns, the ATS can't read them." That's mostly true, but it's hard to show someone. Their PDF looks fine on screen. So while building a small in-browser resume checker, I wanted to answer two concrete questions:

  1. Does this PDF actually have a side column?
  2. What would a naive parser produce from it?

Everything below runs client-side. The file never leaves the browser.

Step 1: get positioned text out of the PDF

pdf.js gives you text items with a transform matrix. The last two numbers are the x/y position (PDF coordinates, so y grows upward):

const page = await pdf.getPage(n);
const { width, height } = page.getViewport({ scale: 1 });
const { items } = await page.getTextContent();
const words = items
  .filter(it => it.str.trim())
  .map(it => ({ str: it.str, x: it.transform[4], y: it.transform[5], w: it.width, h: it.height }));
Enter fullscreen mode Exit fullscreen mode

Step 2: what a naive parser sees

The simplest way to turn that into text is to sort top-to-bottom, then left-to-right, and glue items that share a baseline into one line:

const sorted = words.slice().sort((a, b) => b.y - a.y || a.x - b.x);
Enter fullscreen mode Exit fullscreen mode

On a one-column resume this works. On a two-column one it reads straight across the page, so a line from your Skills sidebar ends up glued to a line from your job history:

HubSpot      Grew organic signups 38% in 12 months
Google Ads   Responsible for social media.
Enter fullscreen mode Exit fullscreen mode

That is the failure people warn about, and it's exactly what I show users. Seeing their own lines mixed up makes the point far better than a warning.

Step 3: find the gutter

To detect a column split, I scan vertical lines across the middle of the page (from 15% to 85% of the text's width, every 2pt). For each x position I count how many characters belong to text items that cross it. A real gutter is a run of x positions where almost nothing crosses:

for (let s = minX + span * 0.15; s <= minX + span * 0.85; s += 2) {
  let crossing = 0;
  for (const it of words) {
    if (it.x < s - 1 && it.x + it.w > s + 1) crossing += it.str.trim().length;
  }
  if (crossing <= totalChars * 0.01) { /* extend or start an empty run */ }
  else { /* close the run */ }
}
Enter fullscreen mode Exit fullscreen mode

I allow 1% because a single long heading or a horizontal rule label often spans the whole page. Then I try the widest empty run first and take its midpoint as the split.

Step 4: reject the false positives

An empty vertical strip doesn't always mean two columns. The common false positive is a normal one-column resume with dates right-aligned:

Marketing Manager                     Mar 2021 – Present
Enter fullscreen mode Exit fullscreen mode

There's a big gap between the title and the date, so the gap looks like a gutter. Three checks filter these out. Each side must:

  • have at least 4 lines and 20 words,
  • be mostly not dates or short locations (fewer than half its lines can be date-ish),
  • sit beside the other side: I bucket y positions into 6pt bands, and at least 30% of the bands must have text on both sides.

The date filter is the one that matters most. Without it, almost every resume with right-aligned dates gets flagged.

Step 5: read it in a sensible order

Once a split is accepted, the side with more characters is treated as the main column and read first, then the sidebar. That reading order is used for the rest of the checks (section detection, contact info, and so on), and also for the "fixed" one-column file the user can download.

DOCX is easier and harder

For Word files I unzip the package and read the XML directly. Layout problems are explicit there: w:cols with num > 1 means Word columns, a table holding most of the text means a layout table, and text boxes and header/footer parts are separate elements. It's easier to detect than PDF, but it turns up more ways to hide text, like contact details that only exist in the page header, which some parsers skip.

What I learned

  • Showing the mixed-up text beats any explanation.
  • Most of the work is in rejecting false positives, not in finding the gutter.
  • Keep the rules fixed and the scoring visible. The same file should always get the same result, and users should be able to see why.

If you want to try it on your own resume, it's at atsresumechecker.app. It's free and runs in the browser. I'd love to hear about PDFs that break the column detection.

I used AI to help write this post. The approach and the code are from the actual project.

Top comments (0)