OptionalmimeType: stringimport 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 />
Decodes or converts encoded image bytes. Return PdfRawImage for RGBA/BGRA pixels, or return encoded bytes/a
Blobin a format the runtime can decode (JPEG is accepted directly by PDFium). Returnnullto 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.