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
Depending on the fonts used for PDFs, some fonts won't render at all when converted to an image.
To fix this issue we can disable the FontFace option and provide a standardFontDataUrl (through getDocument or getDocumentProxy options object) pointing to the standard_fonts folder.
Here is a working fix, since I might not be the only one facing this issue:
import{Buffer}from'node:buffer'import{dirname,resolve}from'pathe'import{configureUnPDF,getDocumentProxy,,renderPageAsImage}from'unpdf'importtype{TypedArray}from'pdfjs-dist/types/src/display/api'exportasyncfunctionconvertPdfToImg(buffer: ArrayBuffer|TypedArray,width){try{awaitconfigureUnPDF({// Use the official PDF.js buildpdfjs: ()=>import('pdfjs-dist'),})constpackagePath=dirname(resolve('node_modules/pdfjs-dist/package.json'))constpdf=awaitgetDocumentProxy(buffer,{isEvalSupported: false,useSystemFonts: false,disableFontFace: true,standardFontDataUrl: `${packagePath}/standard_fonts/`,})constpagenumber=1constresult=awaitrenderPageAsImage(pdf,pageNumber,{canvas: ()=>import('canvas'),
width,})returnresult}catch(error){console.error('Error converting PDF to images:',error)thrownewError(`Failed to convert PDF to images: ${error.message}`)}}
I don't know if pdfjs-dist has to be installed separately for this to work. Maybe @johannschopplich can consider integrating this fix.
Additional information
Would you be willing to help implement this feature?
The text was updated successfully, but these errors were encountered:
Describe the feature
Depending on the fonts used for PDFs, some fonts won't render at all when converted to an image.
To fix this issue we can disable the FontFace option and provide a standardFontDataUrl (through getDocument or getDocumentProxy options object) pointing to the standard_fonts folder.
Here is a working fix, since I might not be the only one facing this issue:
I don't know if pdfjs-dist has to be installed separately for this to work. Maybe @johannschopplich can consider integrating this fix.
Additional information
The text was updated successfully, but these errors were encountered: