pdfrx_web
    Preparing search index...

    Type Alias PdfImageDecoder

    PdfImageDecoder: (
        bytes: Uint8Array,
        mimeType?: string,
    ) => Promise<PdfImageDecoderResult | null> | PdfImageDecoderResult | null

    Decodes or converts encoded image bytes. Return PdfRawImage for RGBA/BGRA pixels, or return encoded bytes/a Blob in a format the runtime can decode (JPEG is accepted directly by PDFium). Return null to decline the input and use the built-in browser decoder.

    pdfrx can import images as PDF pages and, through @pdfrx/react, as image annotations. Encoded formats that the current browser cannot decode (HEIC is a common example) cannot be imported by default. Applications can add support for those formats without adding a pdfrx dependency on a particular codec: provide this callback and convert the input to JPEG/PNG or decoded RGBA8888/BGRA8888 pixels.

    Type Declaration

    import heic2any from 'heic2any';
    import type { PdfImageDecoder } from '@pdfrx/engine';
    import { PdfrxViewerApp } from '@pdfrx/react';

    const decodeImage: PdfImageDecoder = async (bytes, mimeType) => {
    if (!mimeType || !/^image/hei[cf](?:-sequence)?$/.test(mimeType)) return null;
    const result = await heic2any({
    blob: new Blob([bytes], { type: mimeType }),
    toType: 'image/jpeg',
    });
    return Array.isArray(result) ? result[0]! : result;
    };

    <PdfrxViewerApp imageDecoder={decodeImage} enableFileOpen enablePageEditing />