pdfextract API
    Preparing search index...

    Getting started

    Use whole File, Blob, ArrayBuffer or Uint8Array input; Node Buffer works too. Path strings and remote range requests are outside the input contract. Node applications can read a file first, then pass its bytes to "@pdfextract/core".openPdf.

    pnpm add @pdfextract/core @pdfextract/ocr @pdfextract/storage
    

    The libraries support browser ESM and Node ≥22.12.0. Configure browser workers using self-hosted assets before opening a PDF in a bundled application.

    This typechecked Node example returns owned exports that remain usable after close:

    import { openPdf, type PdfInput } from '@pdfextract/core';

    /** Extract native text and independent image exports from a whole PDF. */
    export async function extractNative(input: PdfInput) {
    const pdf = await openPdf(input);
    try {
    const text = await pdf.getStructuredText({ ocr: 'off' });
    const exports = [];
    for (const image of await pdf.getImages()) {
    const full = await pdf.extractImage(image.id);
    const thumbnail = await pdf.extractImage(image.id, { maxWidth: 320, maxHeight: 240 });
    exports.push({ image, full, thumbnail });
    }
    return { text, exports };
    } finally {
    await pdf.close();
    }
    }

    For large documents, upload each full image and thumbnail inside the loop instead of accumulating all exports in an array. The engine decodes on demand; the application controls the lifetime of the resulting bytes.

    The document's four operations are getStructuredText, getImages, extractImage and close. The structured result includes pages, blocks, lines, spans, provenance, warnings and derived fullText. It round-trips through JSON. Detected tables are listed per page in tables and read row by row in the text; see Tables. Blocks inferred to be headings carry a headingLevel.

    For Markdown, with # headings, pipe tables and one line per paragraph, render any structured result:

    import { toMarkdown } from '@pdfextract/core';

    const markdown = toMarkdown(await pdf.getStructuredText());

    Blocks recognized as running headers and footers carry furniture: 'header' | 'footer', and stamps set at a quarter turn along a side edge furniture: 'margin'; toMarkdown(result, { furniture: false }) leaves them out. Line numbers printed beside the text (manuscripts, patents) are left out of the text. lines: 'preserve' keeps the page's lines, and tables: 'pipe' | 'html' writes every table one way.

    For papers typeset with TeX, math: 'latex' writes formulas as $…$ LaTeX rebuilt from their glyphs (scripts, fractions, roots, accents, limits); other pages are unaffected:

    const markdown = toMarkdown(await pdf.getStructuredText({ math: 'latex' }));
    

    Text and Markdown explains the reading order, headings, running headers and footers, the Markdown rendering and LaTeX math, with their limits.

    getImages lists every embedded image by default. To skip icons and other small images, pass a minimum size; the returned list reports how many images were left out:

    // Skip icons, bullets and other small images (default: every image is listed).
    const images = await pdf.getImages({ minWidth: 100, minHeight: 100 });
    console.log(`${images.length} images, ${images.ignoredCount} smaller images ignored`);

    A page with broken content (for example text shown before any font is set) does not stop the list: it is read leniently, and images.warnings names it with IMAGE_INVENTORY_DEGRADED.

    To export an image together with the text, markup or images drawn over it, as it appears on the page, pass composite: true to extractImage (or as an openPdf default) and check overlaid on each occurrence; the core package page explains composites and their limits.

    From the repository root, run pnpm build && pnpm assets && pnpm dev and open http://127.0.0.1:4173/pdfextract-demo/. The default browser adapter uses IndexedDB. Reload the page and load the saved extraction to retrieve its manifest and thumbnails without parsing the PDF again. Select an image to receive the stored full-size File.

    PDFEXTRACT_LANGUAGE_PATH="$PWD/node_modules/@tesseract.js-data/eng/4.0.0" \
    pnpm example:node extract tests/fixtures/mixed.pdf ./pdf-assets
    pnpm example:node load '<printed-manifest-key>' ./pdf-assets

    Set PDFEXTRACT_MIN_IMAGE_WIDTH and/or PDFEXTRACT_MIN_IMAGE_HEIGHT for extract to store only images at least that large; load prints how many were ignored. In the browser example, the host sets window.pdfextractHost.minImageWidth/minImageHeight before loading.

    The source examples are in the repository's browser and Node directories.