Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PDF.js not rendering all the pages and download is corrupted as well.

2,872 views
Skip to first unread message

master...@gmail.com

unread,
Jun 3, 2014, 10:12:55 AM6/3/14
to mozilla-d...@lists.mozilla.org
Hi,
PDF.js is awesome and it works for most of my pdfs. However, I am having two related problems with it.

1. For some pdfs, the viewer is able to display it correctly however, when you use the download option, the downloaded file is corrupted and more than twice the size of original pdf file. I did some research and my library's viewer.js is using typed array instead of buffer as provided on this link.
https://github.com/mozilla/pdf.js/commit/16a1c38c1fd5f3c91af9e3d33e975fba3e2f8316
But the download is still corrupted.

2. For some pdfs, its not able to load all the pages correctly. Like it loads few pages correctly and there is this loading gif on some of the pages.
Is this due to the unsupported font or encryption related ?
Here is the error i am getting at console for these kind of files:-

PDF 9318ae166e81dfd4a7f9da5df656fe6 [1.4 Adobe Central Output Server Print Agent 5.7 / Adobe Central Output Server 5.7] (PDF.js: 1.0.21) viewer.js:3357
Error: Invalid number: Ñ pdf.worker.js:215
at error (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:217:15)
at Object.Lexer_getNumber [as getNumber] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:34149:9)
at Object.Lexer_getObj [as getObj] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:34391:23)
at Object.Parser_shift [as shift] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:33730:32)
at Object.Parser_makeStream [as makeStream] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:33931:12)
at Object.Parser_getObj [as getObj] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:33775:24)
at Object.XRef_fetchUncompressed [as fetchUncompressed] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:6480:30)
at Object.XRef_fetch [as fetch] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:6439:26)
at Object.XRef_fetchIfRef [as fetchIfRef] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:6420:19) pdf.worker.js:217
Warning: Unsupported feature "unknown" pdf.worker.js:200
Warning: Unsupported feature "unknown" pdf.js:183
Error: Invalid number: Ñ pdf.worker.js:215
at error (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:217:15)
at Object.Lexer_getNumber [as getNumber] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:34149:9)
at Object.Lexer_getObj [as getObj] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:34391:23)
at Object.Parser_shift [as shift] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:33730:32)
at Object.Parser_makeStream [as makeStream] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:33931:12)
at Object.Parser_getObj [as getObj] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:33775:24)
at Object.XRef_fetchUncompressed [as fetchUncompressed] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:6489:28)
at Object.XRef_fetch [as fetch] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:6439:26)
at Object.XRef_fetchUncompressed [as fetchUncompressed] (http://localhost:8080/content/layout/standard/pdfjs/js/pdf.worker.js:6486:23)


I would really appreciate if someone can hint or point me to any direction that can fix these problems.

Thank You,
Manish

miztaken

unread,
Jun 3, 2014, 11:25:06 AM6/3/14
to mozilla-d...@lists.mozilla.org
Ok. I have an update. I was having above problem in latest Chrome browser. When i load in firefox it displays all the pages however, the downloaded pdf is still corrupted.
Is this a known issue with pdf.js? I switched to using 1.0.68 i.e. latest release and it has the same problem as 1.0.21.

Any suggestions ?

Yury Delendik

unread,
Jun 3, 2014, 11:35:44 AM6/3/14
to master...@gmail.com
On 6/3/14, 9:12 AM, master...@gmail.com wrote:
> Hi,
> PDF.js is awesome and it works for most of my pdfs. However, I am having two related problems with it.
>

Can you replicate the problem using the viewer hosted at
http://mzl.la/pdf-js ?
Looks like you are using some content management system -- be sure it
handles HTTP range requests right. Checking if it matters when you are
hosting the solution using different web server, e.g. pdf.js development
web server or python's one. Also could you provide access to the custom
solution and example pdf?

Thanks,
Yury

miztaken

unread,
Jun 6, 2014, 2:47:22 PM6/6/14
to mozilla-d...@lists.mozilla.org
Hi Yury,
Thanks for the reply. Unfortunately, company wont allow me to share pdf in the public forum. I tried to isolate the error containing pages from pdf but when I used "Save as PDF" option in chrome, it fixed that error. So I was not able to produce a pdf file that i could share here to demonstrate the problem.

In the mean time, after doing some drilling in the pdf.worker.js code i noticed that for my pdfs it was throwing error only in few cases and when i commented those error() lines it displayed fine and i the download also worked. Nothing was missing from PDF as well.
Here is what i changed in pdf.worker.js
1. Lexer.prototype.getNumber:- I commented the error() on this case.
if (ch < 0x30 || ch > 0x39) { // '0' - '9'
//error('Invalid number: ' + String.fromCharCode(ch));
return 0;
}
2. Lexer.prototype.getObj: I commented out the error() on this case
case 0x29: // ')'
//error('Illegal character: ' + ch);
break;

And doing these two comments, I was able to display and download pdf.

I know this is not an elegant solution but just wanted to share it over here in case other are also having similar problems.

Thank You
miztaken

Yury Delendik

unread,
Jun 6, 2014, 3:02:21 PM6/6/14
to miztaken
On 6/6/14, 1:47 PM, miztaken wrote:

> In the mean time, after doing some drilling in the pdf.worker.js code i noticed that for my pdfs it was throwing error only in few cases and when i commented those error() lines it displayed fine and i the download also worked. Nothing was missing from PDF as well.
> Here is what i changed in pdf.worker.js
> 1. Lexer.prototype.getNumber:- I commented the error() on this case.
> if (ch < 0x30 || ch > 0x39) { // '0' - '9'
> //error('Invalid number: ' + String.fromCharCode(ch));
> return 0;
> }
> 2. Lexer.prototype.getObj: I commented out the error() on this case
> case 0x29: // ')'
> //error('Illegal character: ' + ch);
> break;
>
> And doing these two comments, I was able to display and download pdf.
>
> I know this is not an elegant solution but just wanted to share it over here in case other are also having similar problems.
>

I agree it isn't an elegant solution. We cannot introduce the fix
without knowing more details about why getNumber and getObj are failing
with your PDFs. It will be nice if you could generate a PDF without
sensitive information and send it to us for further investigation -- the
same PDF generator usually generates the similar bad(?) PDFs.

Thanks,
Yury

mele...@gmail.com

unread,
Aug 3, 2015, 7:35:49 PM8/3/15
to mozilla-d...@lists.mozilla.org
Hi,
I used PDF.JS and PDF.WORKWER.JS both version 1.0.68 and version 1.1.215.
With my fonttest.pdf (attached). My app or your test pdf link (http://mzl.la/pdf-js) did not display all the types of fonts. Any ideas why ?
Thanks.
0 new messages