Describe the feature
Suggestion:
Expose createIsomorphicCanvasFactory as a public function, i.e. export the function and re-export it in index.ts.
Existing Code:
renderPageAsImage uses internal function createIsomorphicCanvasFactory to create a canvas and render the page on it.
Use Case:
Very similar to renderPageAsImage, but access raw pixel data of the rendered canvas with CanvasRenderingContext2D.getImageData().
For example something along these lines:
import { createIsomorphicCanvasFactory, getDocumentProxy } from 'unpdf';
const CanvasFactory = await createIsomorphicCanvasFactory(() => import('@napi-rs/canvas'));
const pdf = await getDocumentProxy(data, { CanvasFactory });
const page = await pdf.getPage(pageNumber);
const viewport = page.getViewport({ scale });
const canvasAndContext = pdf.canvasFactory.create(viewport.width, viewport.height);
await page.render({
canvas: canvasAndContext.canvas as HTMLCanvasElement,
canvasContext: canvasAndContext.context as CanvasRenderingContext2D,
viewport,
}).promise;
const imageData = canvasAndContext.context.getImageData(x, y, w, h);
Additional information
Describe the feature
Suggestion:
Expose createIsomorphicCanvasFactory as a public function, i.e.
exportthe function and re-export it in index.ts.Existing Code:
renderPageAsImageuses internal function createIsomorphicCanvasFactory to create a canvas and render the page on it.Use Case:
Very similar to
renderPageAsImage, but access raw pixel data of the rendered canvas with CanvasRenderingContext2D.getImageData().For example something along these lines:
Additional information