Skip to content
Discussion options

You must be logged in to vote

Totally forgot about this, if anyone still looking for solution, it can be done with canvas.

minimal example
import { createCanvas } from 'canvas'; // npm install canvas
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf.mjs';

const loadingTask = pdfjsLib.getDocument({ data: fileData });
const pdfDocument = await loadingTask.promise;

for (let pageNumber = 1; pageNumber <= pdfDocument.numPages; pageNumber++) {
  const page = await pdfDocument.getPage(pageNumber);
  const viewport = page.getViewport({ scale: 2.0 });

  const canvas = createCanvas(viewport.width, viewport.height);
  const context = canvas.getContext('2d');

  await page.render({ canvasContext: context, viewport }).promise

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by l2ysho
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant