dichovsky / pdf-to-png-converter

Library Convert PDF to PNG
MIT License
118 stars 26 forks source link

Fallback fonts #28

Open jakubmirejovsky opened 1 year ago

jakubmirejovsky commented 1 year ago

Hi, is there any correct way to tell the converter to fallback fonts if the glyphs can't be rendered - per glyph? Related issues:

Example of file which renders poorly: https://drive.google.com/file/d/1Z-cF3Vba1rbFCM6Qj5iDttqs9aquYGJi/view?usp=share_link

I tried disableFontFace true, false, useSystemFonts both true and false. No combination returned a correct render.

Any help will be appriciated! :)

troyqa commented 1 year ago

Hi there, @jakubmirejovsky, I have exactly the same problem, did you found solution for this?

lbhmygod commented 1 year ago

Hi, hope my experience can help you.

I use this package to convert pdf, but recently I found some pdf texts are missing after conversion. So I tried to debug this, and set verbosityLevel to 5 to show all logs. And I found this error in log:

Warning: fetchStandardFontData: failed to fetch file "LiberationSans-Regular.ttf" with "UnknownErrorException: Unable to load font data at: ../node_modules/pdfjs-dist/standard_fonts/LiberationSans-Regular.ttf".

Warning: getPathGenerator - ignoring character: "Error: Requesting object that isn't resolved yet Helvetica_path_T.".

After several hours no-use trying to add missing font, I realized this error is thrown by its dependent pdf.js package, and as they said, they have fixed this issue by adding default font, but we need to reference correctly https://github.com/mozilla/pdf.js/issues/4244#issuecomment-1232548915

So I change this line const standardFontDataUrl = '../node_modules/pdfjs-dist/standard_fonts/'; in my local, and it works! Everything renders correctly! You can either change it to const standardFontDataUrl = './node_modules/pdfjs-dist/standard_fonts/'; or const standardFontDataUrl = join(__dirname, '../../../node_modules/pdfjs-dist/standard_fonts/');

fabianobonomini commented 1 year ago

Same problem here. I got a blank white pdf.

ngekoding commented 2 months ago

Hi, hope my experience can help you.

I use this package to convert pdf, but recently I found some pdf texts are missing after conversion. So I tried to debug this, and set verbosityLevel to 5 to show all logs. And I found this error in log:

Warning: fetchStandardFontData: failed to fetch file "LiberationSans-Regular.ttf" with "UnknownErrorException: Unable to load font data at: ../node_modules/pdfjs-dist/standard_fonts/LiberationSans-Regular.ttf".

Warning: getPathGenerator - ignoring character: "Error: Requesting object that isn't resolved yet Helvetica_path_T.".

After several hours no-use trying to add missing font, I realized this error is thrown by its dependent pdf.js package, and as they said, they have fixed this issue by adding default font, but we need to reference correctly mozilla/pdf.js#4244 (comment)

So I change this line const standardFontDataUrl = '../node_modules/pdfjs-dist/standard_fonts/'; in my local, and it works! Everything renders correctly! You can either change it to const standardFontDataUrl = './node_modules/pdfjs-dist/standard_fonts/'; or const standardFontDataUrl = join(__dirname, '../../../node_modules/pdfjs-dist/standard_fonts/');

Works for me! Thank you.

dichovsky commented 2 months ago

Please try v3.3.0