Skip to content

modern-pdf-lib


modern-pdf-lib / extractImages

Function: extractImages()

extractImages(doc): ImageInfo[]

Defined in: src/assets/image/imageExtract.ts:169

Extract all image XObjects from a PDF document.

Walks every page's /Resources /XObject dictionary and collects metadata for each image XObject found.

Parameters

doc

PdfDocument

A parsed PdfDocument.

Returns

ImageInfo[]

An array of ImageInfo objects, one per image XObject.

Example

ts
import { loadPdf, extractImages } from 'modern-pdf-lib';

const doc = await loadPdf(pdfBytes);
const images = extractImages(doc);

for (const img of images) {
  console.log(`${img.name}: ${img.width}x${img.height} ${img.colorSpace} (${img.compressedSize} bytes)`);
}

Released under the MIT License.