You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attach (recommended) or Link to PDF file here: sample.pdf
Configuration:
node v18.18.2
Ubuntu Linux 5.4.0-171-generic #189-Ubuntu SMP Fri Jan 5 14:23:02 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
pdfjs-dist version is 4.0.379
No, this is not a browser extension.
Steps to reproduce the problem:
The code for reproducing the above bug. Example code taken from here:
import{strictasassert}from"assert";importCanvasfrom"canvas";importfsfrom"fs";import{getDocument}from"pdfjs-dist/legacy/build/pdf.mjs";classNodeCanvasFactory{create(width,height){constcanvas=Canvas.createCanvas(width,height,'svg');constcontext=canvas.getContext("2d");return{
canvas,
context,};}reset(canvasAndContext,width,height){canvasAndContext.canvas.width=width;canvasAndContext.canvas.height=height;}destroy(canvasAndContext){canvasAndContext.canvas.width=0;canvasAndContext.canvas.height=0;canvasAndContext.canvas=null;canvasAndContext.context=null;}}// Some PDFs need external cmaps.constCMAP_URL="./node_modules/pdfjs-dist/cmaps/";constCMAP_PACKED=true;// Where the standard fonts are located.constSTANDARD_FONT_DATA_URL="./node_modules/pdfjs-dist/standard_fonts/";constcanvasFactory=newNodeCanvasFactory();// Loading file from file system into typed array.constpdfPath="./sample.pdf"constdata=newUint8Array(fs.readFileSync(pdfPath));console.log('read pdf file')// Load the PDF file.constloadingTask=getDocument({
data,cMapUrl: CMAP_URL,cMapPacked: CMAP_PACKED,standardFontDataUrl: STANDARD_FONT_DATA_URL,
canvasFactory,});try{constpdfDocument=awaitloadingTask.promise;console.log('pdf document read')constpage=awaitpdfDocument.getPage(1);console.log('page 1 fetched')constviewport=page.getViewport({scale: 1.0});constcanvasAndContext=canvasFactory.create(viewport.width,viewport.height);constrenderContext={canvasContext: canvasAndContext.context,
viewport,};constrenderTask=page.render(renderContext);awaitrenderTask.promise;constimage=canvasAndContext.canvas.toBuffer();fs.writeFile("output.svg",image,function(error){if(error){console.error("Error: "+error);}else{console.log("Finished converting first page of PDF to output.svg");}});page.cleanup();}catch(reason){console.log(reason);}
What is the expected behavior? (add screenshot)
The code should output an SVG file. It crashes at the await renderTask.promise line.
What went wrong? (add screenshot)
Code crashes.
Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):
No viewer. Just running this code from command line.
The text was updated successfully, but these errors were encountered:
Crash when running the example with a PDF file containing an image
Attach (recommended) or Link to PDF file here:
sample.pdf
Configuration:
v18.18.2
Linux 5.4.0-171-generic #189-Ubuntu SMP Fri Jan 5 14:23:02 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
4.0.379
Steps to reproduce the problem:
The code for reproducing the above bug. Example code taken from here:
What is the expected behavior? (add screenshot)
The code should output an SVG file. It crashes at the
await renderTask.promise
line.What went wrong? (add screenshot)
Code crashes.
Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):
No viewer. Just running this code from command line.
The text was updated successfully, but these errors were encountered: