Table of contents
Decide whether you need extraction or a page pictureExtract locally with PyMuPDFCheck what was recoveredDecide whether you need extraction or a page picture
An embedded photo is a raster image object inside a PDF. Extracting it can recover its stored resolution and encoding without rendering surrounding text. A page may instead contain vector drawings, multiple image tiles, masks, or an entire scan. There may be no single photo object that matches what you see.
For a whole-page preview, use [PDF to JPG](/pdf-to-jpg). For an isolated stored photo, use the local workflow below. A crop of a rendered page is a new raster image, not a lossless substitute for extraction.
Need the whole page instead?
Use page export when you want the PDF layout as a single image.
Extract locally with PyMuPDF
Install Python and PyMuPDF in a virtual environment: python -m venv .venv, then activate it using the instructions for your operating system and run python -m pip install pymupdf. Review the library’s license if distributing a derived application. The official extraction recipe explains image references and transparency masks.
Save the [extraction script](/samples/extract-images.py) beside your PDF. Run python extract-images.py input.pdf output-images. The output directory must be new, preventing accidental overwrites. The script visits page-referenced raster objects, deduplicates repeated references, and writes the stored image data using the extension returned by extract_image. It restores a separate transparency mask to PNG when present; that PNG is reconstructed rather than byte-identical to the source.
An encrypted PDF needs an authorized unlocked copy. The script reports unreadable objects, stops with a clear error for invalid documents, and reports the number of recovered files. It does not upload the document. For inline images, image tiles, or complex compositing, see the official Page API and its image blocks; page-reference extraction may not recover everything.
Check what was recovered
Open each output and compare it with the PDF: pixel dimensions, color, transparency, and completeness. Repeated use of a photo may produce one file; mask restoration may produce PNG instead of the original encoding. Vector logos are drawing instructions and are not recovered as photos by this script.
Try the [safe sample PDF](/samples/pdfpixel-example.pdf). Its embedded test image can be compared with the [source PNG](/samples/source-pattern.png). These files contain generated shapes and labels only. Consult the Document.extract_image reference for returned image metadata and limitations.
Use recovered images only with permission. The ability to extract an object does not establish ownership or permission to publish it.
Keep extraction and page export separate
Use the script for embedded raster objects, or PDFPixel for a rendered page preview.
FAQ
Does PDFPixel extract embedded photos?
No. PDFPixel renders whole PDF pages as JPG. Use the local extraction script for page-referenced embedded raster images.
Does cropping preserve original image quality?
No. It uses the page render’s pixel grid and compression, and may discard detail from the embedded source.
Why are there no images or too many?
Vector artwork is not a raster image; scans may be full-page images; tiles, masks, reused objects, and inline images need special handling.