Extract & Save Images From Document
Mine the Images Out of PDFs, DOCX, HTML, and Markdown — Without Leaving ComfyUI
- first_saved_image_preview
- output_folder_path
You've got reference images buried inside a document - a brand PDF with the logo you want to IPAdapter into a generation, a paper's figures you want to upscale, a spec sheet that's really a collection of product shots. Normally that means opening the file in an external viewer and exporting each image by hand. ExtractAndSaveImagesFromDocument skips the middleman: point it at the file, it pulls every embedded image out, saves them to ComfyUI's output folder, and hands the first one back as an IMAGE tensor you can wire straight into the rest of your graph.
It's a tiny, single-node pack from a solo French dev (Orion4D - the README is in French), and it's exactly the kind of "why doesn't this exist as a node" utility that the ecosystem is full of. For a one-off you could write the same thing in PyMuPDF in ten lines. If you're regularly mining documents for conditioning images, having it as a node keeps the whole pipeline in one graph.
How it works
The node dispatches on the file extension, and each format uses the library that actually understands it:
- PDF - PyMuPDF (
fitz). It walks every page withpage.get_images(full=True)and pulls each embedded image out by xref, so it catches images nested in objects and patterns, not just the obvious ones. - DOCX -
python-docx. It iterates the file's relationship map and reads every image blob, which is how Word stores images in the first place. - HTML -
BeautifulSoupwith thelxmlparser. It handlesdata:base64 images and local relative paths; remotehttp(s)images are skipped entirely. - Markdown - converts the
.mdto HTML with themarkdownlibrary, then reuses the HTML extractor, resolving relative image paths against the Markdown file's own folder.
Every extracted image gets filtered by your minimum width and height, then flattened to RGB (alpha composites onto white, palette and grayscale get converted). Survivors are saved as PNGs named {prefix}_p{page:03d}_idx{idx:03d}_num{i:03d}.png into a fresh subfolder - output/{prefix}_{docname}_{timestamp} - so running the same document twice never overwrites anything.
Inputs and outputs that matter
There are only four inputs, all required:
document_path(STRING) - the absolute path to your file. There's no file browser; you paste the path..pdf,.docx,.html/.htm, and.md/.markdownare supported, nothing else.min_width/min_height(INT, default 256, up to 8192) - minimum pixel dimensions to keep. The defaults quietly throw out small icons, logos, and thumbnail crops.filename_prefix(STRING, defaultextracted_doc_img) - used for both the output folder name and every saved file.
Two outputs come back:
first_saved_image_preview(IMAGE) - a normal BHWC float tensor of the first image that got saved. Wire it into a Preview Image node (or into img2img / IPAdapter / ControlNet) to see it in the UI.output_folder_path(STRING) - the full path to the folder, so downstream nodes or your own scripts can find the files.
One quirk: if nothing gets saved, the preview isn't a tensor of nothing - it's a black 64×64 placeholder, and the path output carries a message like no images found or matching criteria or error: file not found.
Installing it
ComfyUI Manager is the easy route: open Manager, search for ComfyUI_extract_imag, install, restart. Or the manual way:
cd ComfyUI/custom_nodes/
git clone https://github.com/orion4d/ComfyUI_extract_imag.git
cd ComfyUI_extract_imag/
pip install -r requirements.txt
Then restart ComfyUI. The heavy lift is pymupdf, python-docx, beautifulsoup4, lxml, and markdown - the other four lines in requirements (Pillow, numpy, torch) are already part of ComfyUI. The node shows up under document_processing as "Extract & Save Images From Document".
Where people get burned
The biggest trap is silent format failure. Every dependency import is wrapped in try/except, so the node loads fine even when a library is missing - then PDF extraction just fails with error: missing dependency surfacing in the path output. If a format returns nothing, check the console: the node logs [ExtractAndSaveImages] lines there, not in the UI.
Beyond that, the usual suspects: forgetting the file must exist on the machine running ComfyUI (not your browser's machine), the 256px minimum silently filtering out the small logo you actually wanted (drop it to 64 if you need icons), and expecting remote HTML images to appear - they won't. And since OUTPUT_NODE is true, every run writes a new timestamped folder; your output dir accumulates them, which is fine until it isn't.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| document_path | STRING | — | |
| min_width | INT | 2561–8192 | — |
| min_height | INT | 2561–8192 | — |
| filename_prefix | STRING | extracted_doc_img | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| first_saved_image_preview | IMAGE | — |
| output_folder_path | STRING | — |