5

I'm using react-pdf-viewer 3.9.0 with "pdfjs-dist": "2.15.349".

It seems like the React PDF Viewer still waits until it completely downloads a file, instead of rendering the first page as soon as the minimum requirement is downloaded (the fast web view, or linearization technology). My files are already linearized (byte-streaming) I would like to render the first page, even if the fetching file is in progress. I'd love any direction on how to solve this! Thank you!

Razi Melliti
  • 170
  • 1
  • 4
  • 18
  • 1
    This also depends on the PDF file being linearized correctly. – dirck Jan 30 '23 at 04:11
  • 1
    @RaziMelliti, do you have sample code which you tried to look into? – Naga Sai A Jan 30 '23 at 04:15
  • sorry I did not get your point. could you please explain more? – Razi Melliti Jan 30 '23 at 06:38
  • 3
    PDF file structure is originally designed to be read from the end of file backward. A linearized file is reordered so that it's possible to read the first page quickly without reading the end of the file. The HanoiTower.pdf link example is not linearized. The Linearized key (shown above) is not present. The Linearized key may be visible and the file still not linearized correctly. PDFs are modify-by-append, so you might get the first page right away and then find out later it's not the right first page. – dirck Jan 30 '23 at 17:56

1 Answers1

0

History

From Chromium Bug tracker and dialogs

Adobe include special hints stream into their linerilized PDFs. Format of such stream is black box and understood only by Adobe software. This allows Adobe to load linerilized PDFs more efficiently.

The alternative is server partial byte ranges. Chromium Bugs for read and alter were opened 2011 reputedly in 2014 Adobe posted (source no longer on Adobe site) along the lines of indicate that Google chrome does not support byteserving a PDF. That bug is still open whilst others related were closed "Wont fix"

Thus both methods are problematic for Foxit/Skia (Chromes binary developers) and other 3rd Parties to emulate. try this 2GB Link in Acrobat it should open page 1 before download. Chrome needs to wait for the whole download ! then although Downloaded! My Edge expects to save it in about 10 minutes time. https://s3.amazonaws.com/pdftron/downloads/pl/2gb-sample-file.pdf

One commercial solution :- (A few seconds to display their file)

PDFTron (owner company of Iceni, iText, PDFLib, XODO and many others) PDF.js more specifically a "Pre-Loaded" Express can

Firefox/Mozilla using simpler JavaScript methodologies

It can vary if Firefox viewer can use Linearized files, one of my older legacy viewers does not work with that sample, but the newer inbuilt FireFox enabler does.

Unclear if either can be passed through Mozilla PDF.js based React PDF Viewer, but supposedly was, from 3.3.3 onwards. However the dev viewer as linked above, does not exhibit that behaviour when using simple unserved file open e.g. "drag and drop" However that 1st Page does appear fast (along with others) after the time taken to upload.

NOTE a "/Linearized" PDF file must not have been "adapted" e.g. annotated or simply served (other than as transcoded text) etc. after "Web Optimisation". The viewer must be working with the decimal addressed binary file bytes from server.

K J
  • 8,045
  • 3
  • 14
  • 36