PDFreact-print-pdf
DocsBrowser-only alpha

Images

PNG and JPEG img elements are embedded as reusable PDF image XObjects.

Edit this page

<img> elements are treated as image primitives. PNG and JPEG sources are embedded in the PDF instead of being captured as part of a larger screenshot.

Supported sources

SourceStatusNotes
data:image/png;base64,...Supporteddecoded without network
data:image/jpeg;base64,...Supporteddecoded without network
/logo.pngSupportedfetched from same origin
https://.../photo.jpgSupportedCORS must allow browser fetch
blob: URLSupportedfetched by the browser
GIF / WebP / AVIFNot supporteddropped with a warning
SVG image fileNot supported as imageuse raster fallback for SVG regions

Format detection

The emitter sniffs magic bytes before embedding:

  • PNG: 89 50 4E 47
  • JPEG: FF D8 FF

The URL extension is not trusted. If a CDN returns HTML, a 404 page, or WebP behind a .png path, the image is skipped with a warning.

Deduplication

The same image source is embedded once and reused.

<img src="/logo.png" />
<img src="/logo.png" />
<img src="/logo.png" />

Those three DOM nodes produce one PDF XObject.

Sizing

The image is drawn into the DOM box reported by getBoundingClientRect().

<img src="/logo.png" className="h-12 w-12" />

The PDF uses the CSS size, not the intrinsic image size.

CORS

Remote images must be readable by browser fetch().

If an image disappears in the PDF:

  1. Open DevTools network panel.
  2. Confirm the image request succeeds.
  3. Confirm the response has an Access-Control-Allow-Origin policy that allows your app origin.
  4. If not, host the image on your app origin or convert it to a data URL before rendering.

Known gap

object-fit: fill | contain | cover is honored. fill (the CSS default) stretches the image to the box; contain letterboxes it inside the box, keeping aspect ratio; cover fills the box and clips the overflow via a PDF clip path. none and scale-down are not modeled and collapse to fill.

On this page