Extract images at native resolution instead of downscaling to 144 DPI
Summary
When extracting images (--image-output external or embedded), each image region is produced by rasterizing the whole page at a fixed 144 DPI and cropping the region. Any image whose source resolution is higher than 144 DPI is silently downscaled, and there's no way to preserve the original. Ideally extraction would preserve the source image's native resolution by default — no DPI guessing required.
Impact
Figures/diagrams with small labels or fine detail lose fidelity. Examples observed (extracted PNG vs. source embedded image):
- image embedded at 303 ppi → extracted at ~144 ppi
- 512×512 embedded icon → written as ~45×45
- ~1190×600 figure → written at ~675×340
Why this happens
ImagesUtils.createImageFile(...) crops from ContrastRatioConsumer.getPageSubImage(...), and the consumer is constructed with imagePixelSize = null:
StaticLayoutContainers.getContrastRatioConsumer(pdfFilePath, password, false, null);With a null imagePixelSize, veraPDF wcag-algs renders the page at the constant RENDER_DPI = 144, so every cropped image inherits 144 DPI.
Ideal fix — preserve native resolution
For an image region backed by a single embedded raster XObject (the common case), extract that XObject directly at its native resolution (e.g. PDFBox PDImageXObject.getImage()) instead of cropping a 144-DPI page raster. This is lossless and resolution-independent. The XObject(s) under a detected region can be identified by recording image placements during content-stream processing (e.g. a PDFGraphicsStreamEngine capturing each drawn image's CTM + XObject reference).
For regions that genuinely require rasterization — vector-drawn figures, or composites of overlapping images/vector overlays — render at a resolution derived from the region's content rather than a flat 144 DPI.
Environment
- opendataloader-pdf 2.4.7 (Python wrapper + bundled CLI JAR)
- veraPDF wcag-algs 1.31.25
- macOS, Java 17
Repro
- Take any PDF with an image embedded above 144 ppi (or a vector figure).
opendataloader-pdf doc.pdf -o out --image-output external- Compare the extracted PNG's pixel dimensions to the source (
pdfimages -list doc.pdf): the result is ~144 DPI, not the embedded resolution.
Source: opendataloader-project/opendataloader-pdf