Frage

Our web application provides ability to download pdf.

When user clicks on download link we open the pdf in a new tab.

My firefox uses pdfjs as a pdf viewer and I can save pdf through it's interface.

Everything was fine in Firefox 19, but version 24 download file which looks like corrupted (it displays that file, but can't download it correctly).

I noticed that result size of file is a nearest power of 2, for example if my original pdf size is 97kb then after downloading it through Firefox's pdfjs its size becomes 128kb and my desktop pdf viewers (like acrobat) can't open it.

I tested it on the same version of our app.

update

Demo pdf file - everything is fine with downloading through linux google chrome viewer and linux firefox 21 (pdfjs), but the same problem with linux firefox 23.0.1

Is something wrong with pdfjs or with our server?

update #2

I looked at binary contents of broken and not-broken file:

$ git diff not-broken.dump broken.dump 
diff --git a/not-broken.dump b/broken.dump
index 3621089..5de337c 100644
--- a/not-broken.dump
+++ b/broken.dump
@@ -336,5 +336,7 @@
 000014f0  b8 d0 3d 76 85 f8 76 9d  e6 50 74 df e7 a7 bd b0  |..=v..v..Pt.....|
 00001500  00 f1 6e 05 63 0a 65 6e  64 73 74 72 65 61 6d 0a  |..n.c.endstream.|
 00001510  65 6e 64 6f 62 6a 0a 73  74 61 72 74 78 72 65 66  |endobj.startxref|
-00001520  0a 35 32 31 33 0a 25 25  45 4f 46 0a              |.5213.%%EOF.|
-0000152c
+00001520  0a 35 32 31 33 0a 25 25  45 4f 46 0a 00 00 00 00  |.5213.%%EOF.....|
+00001530  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
+*
+00010000
War es hilfreich?

Lösung

What we have here is a genuine bug. I filed: https://github.com/mozilla/pdf.js/issues/3634

Since the data transfer does not specify a content-length, but uses chunked transfer encoding, pdf.js will use an initial buffer of 64kb that is doubled each time it would overflow. However, once the transfer is complete pdf.js will not shrink that buffer to the actual size, nor will it remember the actual size, so that upon download the whole over-sized buffer (still the initial 64kb in your example) will be transferred.

I don't think there is a real work-around, short of not using pdf.js at all (which is a user choice).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top