npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cerfaparse

v1.2.1

Published

Convert flat CERFA PDFs into fillable AcroForm PDFs with structured field definitions

Downloads

362

Readme

English | Français

cerfaparse

Convert flat (non-interactive) French CERFA PDF forms into fillable AcroForm PDFs with JSON field definitions.

What it does

  1. Extracts character cells and checkboxes from the PDF geometry (via SVG)
  2. Extracts labels from the PDF text layer
  3. Maps labels to field groups to generate meaningful field names
  4. Injects AcroForm fields (combed text fields + checkboxes) into the PDF
  5. Outputs a .fields.json with all field definitions (name, type, label, position, maxLength)

Prerequisites

  • Node.js >= 20
  • Poppler CLI tools (pdftocairo, pdftotext, pdfinfo)
# macOS
brew install poppler

# Debian/Ubuntu
sudo apt-get install poppler-utils

Install

npm install cerfaparse

CLI Usage

npx cerfaparse convert <input.pdf> [-o <output.pdf>]

Example:

npx cerfaparse convert docs/pdf-cerfa_cs8_bleu-recto-verso-140x202mm.pdf -o /tmp/cs8-fillable.pdf

This produces:

  • /tmp/cs8-fillable.pdf — the original PDF with overlay AcroForm fields
  • /tmp/cs8-fillable.fields.json — JSON field definitions

JSON Output Format (ngx-formly compatible)

The output JSON uses ngx-formly-compatible field definitions (key, type, props) with spatial metadata embedded in props:

{
  "pages": [
    {
      "pageNumber": 1,
      "fields": [
        {
          "key": "p1_nom",
          "type": "input",
          "props": {
            "label": "Nom :",
            "maxLength": 9,
            "page": 1,
            "pdfRect": { "x": 50.4, "y": 505.6, "width": 104.1, "height": 10.9 }
          }
        },
        {
          "key": "p1_oui",
          "type": "checkbox",
          "props": {
            "label": "Oui",
            "page": 1,
            "pdfRect": { "x": 288.1, "y": 472.3, "width": 8.0, "height": 8.0 }
          }
        }
      ]
    }
  ]
}

Field types

| Type | Description | Props | |------|-------------|-------| | input | Text input — rendered as free-form in formly, mapped to one-char-per-box (combed) in PDF when maxLength is set | maxLength, label, page, pdfRect | | checkbox | Checkbox | label, page, pdfRect |

Library Usage (Node.js)

import { convert } from 'cerfaparse';

const { pdfOut, jsonOut, fields } = await convert('input.pdf', 'output.pdf');

Or use individual functions:

import { extractBoxes } from 'cerfaparse';
import { extractSvg } from 'cerfaparse';

Using with Angular / ngx-formly

The JSON output is directly compatible with ngx-formly. Run convert at build time, then use the JSON fields as-is:

// Load the generated JSON
import fieldDefs from './assets/cerfa-cs8.fields.json';

// Fields are already formly-compatible — just flatten across pages
const formlyFields = fieldDefs.pages.flatMap(page => page.fields);
// Each field has: { key, type, props: { label, maxLength?, page, pdfRect } }

Fields use standard formly types (input, checkbox). The maxLength prop constrains input length in the form; when filling the PDF, maxLength triggers combed rendering (one character per cell).

To fill the PDF client-side with pdf-lib (works in the browser):

import { PDFDocument } from 'pdf-lib';

const pdfBytes = await fetch('/assets/cerfa-cs8-fillable.pdf').then(r => r.arrayBuffer());
const pdfDoc = await PDFDocument.load(pdfBytes);
const form = pdfDoc.getForm();

for (const [key, value] of Object.entries(formValues)) {
  const field = fieldDefs.pages.flatMap(p => p.fields).find(f => f.key === key);
  if (!field) continue;
  if (field.type === 'input') {
    form.getTextField(key).setText(String(value));
  } else {
    const cb = form.getCheckBox(key);
    value ? cb.check() : cb.uncheck();
  }
}

const filledBytes = await pdfDoc.save();
// Trigger download or display

Tests

npx vitest run

How it works

  1. pdftocairo converts each PDF page to SVG
  2. SVG <path> elements with white fill are classified as character cells (white stroke, stroke-width ~1) or checkboxes (dark stroke, stroke-width ~0.5)
  3. SVG affine transform matrices (including ancestor <g>/<use> transforms) are composed to convert from SVG content coordinates to PDF coordinates (bottom-left origin, Y-up)
  4. Boxes are grouped into rows by Y-proximity, then split into fields by X-gaps
  5. pdftotext bbox output provides label text and positions, matched to field groups by spatial proximity
  6. pdf-lib injects AcroForm fields with transparent backgrounds at the computed PDF coordinates