Free, open‑source script that thickens too‑thin linework in PDF files. It uses the pypdf library to scan each page’s content stream and raise any stroke width set via the PDF “w” operator below a chosen threshold—similar to Adobe Acrobat Pro’s “Fix Hairlines” under Print Production.
Autocad‑produced PDFs that use a 0 lineweight are notoriously hard to read on paper. This tool enforces a minimum stroke width so plotted drawings remain legible.
- Enforces a minimum line width across all pages
- Lossless PDF editing (no rasterization)
- Works locally; no upload required
- Simple Python script; no Acrobat needed
- Parses each page’s content stream with pypdf
- Iterates through content stream operators and operands using pypdf. (Does not use Regex, which can miss edge cases or change things it shouldn't).
- Finds the PDF operator
w(set line width) - If the width is below the configured threshold, replaces it with the threshold value
- Recompresses the content stream and writes a new PDF
Notes:
- Units are PDF user‑space units (points): 1 pt = 1/72 in ≈ 0.3528 mm
- Python 3.8+
- pypdf (install via pip)
PowerShell (Windows):
python -m pip install --upgrade pip
python -m pip install pypdfThis repo contains a single script: PDF-hairline-fix.py with an example call at the bottom.
- Put your PDF next to
PDF-hairline-fix.py - Open
PDF-hairline-fix.pyand change the example line at the bottom:modify_linewidths("your-input.pdf", "your-output.pdf", min_width=3)
- Run it:
python .\PDF-hairline-fix.py
min_width(float): Minimum stroke width to enforce. Example values:- 0.25–0.5 pt for subtle thickening
- 3 pt for clearer plots
- 5 pt for heavier lines
- Only updates explicit
woperators; embedded graphic states, patterns, or transparency groups that define stroke widths are not touched - Does not change dash patterns, colors, or fills, so if your drawing is gray or another light color, print it in monochrome black for best results.
- Some PDFs may have complex content streams; test results visually
- Only modifies vector line widths; does not affect images or raster content
Steps to build the standalone GUI executable (PDFHairlineFix.exe):
python -m venv .venv
.venv\Scripts\Activate.bat
pip install -r requirements.txt
pyinstaller PDFHairlineFix-GUI.specResult: dist\PDFHairlineFix.exe
- What happens to pages without content streams? They are copied unchanged.
- Is the change reversible? Your original PDF is preserved and a new file is created.
- Does this reduce quality? No rasterization is performed; only line widths are adjusted.
MIT License. See LICENSE for details.

