Skip to content

PDFs with zero-width lines render faint/gray instead of black when converting to image #4526

@ShubhamPatil1729

Description

@ShubhamPatil1729

When converting engineering drawing PDFs to images using PyMuPDF (fitz), pages containing lines with zero or very small width render these lines as faint gray instead of solid black, making them nearly invisible. This issue affects drawings printed from AutoCAD to PDF, where the line width in the PDF is set to zero (hairline). Other PDFs with thicker line widths render correctly (lines appear solid black as expected).

This makes technical drawings hard to read and affects downstream processing, as the intent is to preserve the appearance of black lines/curves on a white background.

Technical details:

  • Conversion code:
    pix = page.get_pixmap(dpi=300, colorspace=fitz.csRGB, alpha=False, annots=False)
  • Affected PDFs: Drawings with lines whose width is set to 0 (hairline) in the PDF source
  • Expected: All drawing lines (including hairlines) render as solid black, matching PDF viewers/print
  • Actual: Zero-width lines render as faint gray, sometimes nearly invisible, especially at high DPI
  • Workarounds tried: Higher DPI, post-processing (binarization), different colorspaces – none fully solve the issue
  • This appears to be a limitation of MuPDF's rendering of hairlines/zero-width strokes, as discussed in related issues (see Undetected character styles #4503, cluster_drawings() fails to cluster horizontal and vertical thin lines #4324)

Please advise if there is a way to force hairlines to render solid black in PyMuPDF with increased line width, or if this is a MuPDF limitation. Any workaround, parameter, or planned fix would be much appreciated.


Thank you for your work on PyMuPDF!


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions