Pdf.js: Error when loading PDF that uses system fonts

Created on 4 Feb 2014  路  27Comments  路  Source: mozilla/pdf.js

Test file: https://dl.dropboxusercontent.com/u/16283445/PORTRAIT.pdf

File was produced by Muhimbi PDF converter.

Main text (that uses embedded Tahoma font) renders ok; it is the trial message on top of the file that causes the error. After some debugging, I've found that this message references system Helvetica font, and somehow glyphs for it are missing at the time of error.

Error log:

Error: Requesting object that isn't resolved yet Helvetica_path_T pdf.js:205
    at error (http://[skipped]/pdfjs/pdf.js:207:15)
    at Object.PDFObjects_get [as get] (http://[skipped]/pdfjs/pdf.js:4640:9)
    at Object.FontFace.getPathGenerator (http://[skipped]/pdfjs/pdf.js:7675:23)
    at Object.CanvasGraphics.paintChar (http://[skipped]/pdfjs/pdf.js:6105:26)
    at Object.CanvasGraphics_showText [as showText] (http://[skipped]/pdfjs/pdf.js:6291:18)
    at Object.CanvasGraphics_nextLineShowText [as nextLineShowText] (http://[skipped]/pdfjs/pdf.js:6381:12)
    at Object.CanvasGraphics_executeOperatorList [as executeOperatorList] (http://[skipped]/pdfjs/pdf.js:5600:22)
    at Object.InternalRenderTask__next [as _next] (http://[skipped]/pdfjs/pdf.js:4807:39)
    at Object.pdfViewcContinueCallback [as continueCallback] (http://[skipped]/pdfjs/viewer.js:4261:9)
3-pdf-broken 4-font-conversion

Most helpful comment

with pdfjs-dist": "^2.2.2 set disableFontFace: false fixed this issue on me.

pdfjs.getDocument( { url: pdfUrl, disableFontFace: false, }

All 27 comments

This fails because the font isn't loaded when we attempt to fetch it in font_loader.js#L313.
The issue appears to be that it's never actually loaded at all, given evaluator.js#L284, since font.data is undefined in this case. The reason for this is that the font in question doesn't have an embedded font file, which means that in fonts.js we return before defining font.data. See fonts.js#L2256 and fonts.js#L2303.
The reason that this isn't a bigger problem in practice for us, is that it only seems to affect PDFs (like this issue) where the font resource is contained inside e.g. an XObject dictionary.

I unfortunately don't know how we could address this issue, since building font.data without a font file seems difficult in the current code. Perhaps this would get solved "for free" if we embedded the standard fonts in PDF.js?

P.S. I also noticed that fixing this issue would address one (or two) of the files listed in http://bthorben.github.io/pdfRepo/#crashed.

Can there be a solution like one of these:

1 - option to allow use some default font or some font what already been used for exact file
2 - option to allow skip rendering of this item
this can help to continue work with pdf file if some font are absent, and output only as warning, not as breaking error.

What do you think?

We prefer the first option, however we don't embed any fonts yet and rely on system to contain those for some functions. We can certainly ignore, once we find how to properly stub it (For these font, we can generate empty letters outlines when requested)

At least open the possibility to .catch(...) this error instead of just stopping everything until you can find a better solution. Unfortunately this problem breaks functionality in our live environment which is... bad.

Is there any workaround available? Or some sort of error catching mechanism suggested by @xwcg ?

Hello everyone,
I got the same error.
May I know if there is any temporary work-around for this issue before the formal fix?

Any update on this?, Its from 2014 and still not solved

@diego-lipinski-de-castro FYI, that #9809 merge fixed this if you pass in ignoreErrors: true into the getDocument function. If you use the npm pdfjs-dist it's not updated yet. I just built from source and PDFs that used to complain about fonts now process correctly with canvas output. Everything seems fine.

@sirisian thanks for your update. Looking forward to the release

@sirisian do you know when will be the update for npm pdfjs-dist? and if there is a workaround for npm?
Thanks

Any updates on this fix release for npm pdfjs-dist ?

Hi, I also encounter this error. Is there a way to substitute font that aren't present on the system with a default one?

Hi @timvandermeij when are we likely to see this fix in pdfjs-dist ?

with pdfjs-dist": "^2.2.2 set disableFontFace: false fixed this issue on me.

pdfjs.getDocument( { url: pdfUrl, disableFontFace: false, }

In my opinion, whenever pdf.js fails to load text in a particular font, it should load the same text using a substitute font it _could_ show (e.g., the default fonts set by the user in the font preferences), rather than stop rendering the page and throw an error. This was the behavior in Firefox 61 and earlier when the option "Allow pages to choose their own fonts, instead of your selections above" is disabled. In my opinion, showing text in a substitute font is better than showing nothing at all.

with pdfjs-dist": "^2.2.2 set disableFontFace: false fixed this issue on me.

pdfjs.getDocument( { url: pdfUrl, disableFontFace: false, }

This one solved my issue, I'm using pdfjs-dist ^2.0.943
Thank you

I'm working on a project where IE 11 is a requirement and the security settings (managed by the IT team) do not allow custom fonts to be downloaded. This results in a PDF rendering this is mostly blank when rendering, only showing a few headlines and italic characters.

setting disableFontFace: true causes the inverse in IE 11 (and all other browsers actually). Most fonts then render but it introduces a litany errors such that look like this:

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

The errors all indicate different characters in the Times_path_* portion of the message. The document loads most content but headlines, italics, and other variations are visually missing (although the empty text can be selected due to the transparent text layer on top)

So, I'm stuck between having full font rendering in all browsers except this managed version of IE 11 (due to the administrator enforced security setting regarding fonts) or semi-broken font rendering everywhere due to trying to implement a fix for IE 11.

Any suggestions?

any news on that ?

hi team,
I tried all the possible things, nothing can make solve the bug.
have any updates ?

This is a major impact to us. Why is the workaround to set disableFontFace=false? My understanding is that with disableFontFace=true, it doesn't matter what embedded fonts there are (or aren't) in the pdf. Is that incorrect?

any news on that ?

6 years ago @AllSeeingEye was having a problem and today this library has 594 unresolved issues. Nobody gives a f* about this bug or what ? A bug that is for me a no-go, will need to look for other libs like pdf-lib maybe.

Good day everyone!

Faced some similar issues while trying to solve the text layer render issue with disableFontFace params.

On disableFontFace: false some documents looks like this:
image

While on disableFontFace: true the previous document render well, there is an issue with a different document:
image

All these cells were not empty.
Some docs render well in one way, some - in other way.
How should I act?

I'm having a similar issue as @Hatgor
Is there a fix or somehting that can be done in order to get this right? The above solutions don't work. :|

I'm having the exact same issue. Trying to run it in a lambda on Node12, which runs amazonlinux2 - meaning no fonts installed by default. It would be REALLY nice if we could embed the standard 14 fonts into pdfjs by default, or expose an API for loading them rather than relying on them being installed in the base system. Thus far my efforts to install the fonts to the system have been... less than successful.

At this point I'm thinking I might pre-process every PDF with another library, like pdf-lib, explicitly to embed the 14 standard fonts, THEN pass it to this library for rendering. A bit excessive and annoying, but if it resolves the problem....

After tinkering for literal hours with amazonlinux2 to install fonts, I CAN get the non-included fonts to render by setting disableFontFace to false explicitly, but then the embedded fonts from the PDF fail with the same symbol seen in @Hatgor 's comment.

OK, so far no dice in pre-processing PDFs to embed fonts. Is there, perhaps, a way to inject a font that's not embedded in the PDF? I can host the necessary .ttf(s) somewhere else, but I'm not seeing anything in the API to load an arbitrary font.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aaronshaf picture aaronshaf  路  3Comments

liuzhen2008 picture liuzhen2008  路  4Comments

dmisdm picture dmisdm  路  3Comments

smit-modi picture smit-modi  路  3Comments

anggikolo11 picture anggikolo11  路  3Comments