Determining when to use disableFontFace
See original GitHub issueI’m running into issues similar to #4244 but am interested in knowing if there is a way to programmatically determine if I should use disableFontFace
.
I’m attempting to OCR invoices, and some of them render correctly with disableFontFace:false
and others with disableFontFace:true
, if you supply a pdf the wrong disableFontFace
you end up with a pdf that is void of text, or has boxes as is documented in other issues.
My question is, Is there a way to determine (via the pdfDocument
metadata or any other means) if I should use the disableFontFace
option when calling .getDocument()
?
I have tried getting text content and looking at fonts, but I’m not sure if I can just say “oh this text content seems to be all in Helvetica, so I know that I need to use disableFontFace:true
” That information and a list of system fonts seems like the only path forward based on the other issues I’ve read.
Thank you.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:5
Top GitHub Comments
I had a similar problem. In my case the problem occurs when, PDF files have an embedded font. When PDF files do not have an embedded font they render fine. For Example
With embedded font
For this I made a workaround, manipulating the disableFaceFont property. Because when the FaceFont is active, it tries to look for the embedded font and if it doesn’t find it, it renders wrong.
Whereas, if the FaceFont is inactive and the file has no embedded font, it doesn’t render.
To do this when I call open the PDF, I set the “disableFaceFont” property to true
PDFViewerApplication.open(uint8Array,{disableFontFace: true});
And in the “CanvasGraphics.paintChar” method of “pdf.js” I make the following control:
If the PDF has embedded font, then disable FaceFont “disableFaceFont:true” and if it does not have embedded font, then enables FaceFont “disableFaceFont:false”.
font.disableFontFace = !font.missingFile || font.mimetype;
This way it works fine for both.
Same PDF with workaround
@sayo96 as far as I am aware there is not a way to determine which setting you need, and depending on your pdfs you may need the effects of both setting to correctly render.