question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Determining when to use disableFontFace

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:5

github_iconTop GitHub Comments

1reaction
SantiagoM92commented, Nov 7, 2021

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 image

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;

image

This way it works fine for both.

Same PDF with workaround

image

1reaction
tristansokolcommented, Dec 5, 2020

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Determining when to use disableFontFace #11311 - GitHub
I'm attempting to OCR invoices, and some of them render correctly with disableFontFace:false and others with disableFontFace:true , if you ...
Read more >
JSDoc: Module: pdfjsLib
Determines if we can use `OffscreenCanvas` in the worker. Primarily used to improve performance of image ... disableFontFace, boolean, <optional>
Read more >
System Administration Made Easy(er) - MKS Toolkit
This article will demonstrate ways in which you can automate the task of user administration using the MKS Toolkit system administration products.
Read more >
network.http.spdy.use-alternate-protocol - ADMX Help
Registry Hive, HKEY_LOCAL_MACHINE. Registry Path, Software\Policies\Mozilla\lockPref. Value Name, network.http.spdy.use-alternate-protocol.
Read more >
JSDoc: Source: display/api.js
If PDF data is; * BASE64-encoded, use atob() to convert it to a binary string first. ... @property {boolean} [disableFontFace] - By default...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found