Pdf.js passes the first pixel test

    In June, Andreas Gal and colleagues from Mozilla introduced the pdf.js engine for displaying PDF using HTML5 / JavaScript. In the initial version, it worked imperfectly, but the developers got down to business seriously and added functionality literally every day: rendering graphics, GUI, etc. But the most important thing is that the dynamic loading of TrueType fonts is implemented and the loading of PostScript Type 1 fonts is radically improved.

    As a result, now Andreas Gal decided that the first test was passed and pdf.js pixel by pixel * accurately displays the test document ( demo ).

    Now pdf.js has been assigned version number 0.2 and a new task has been set: to render the official specifications of PDF 1.7 (the document contains 1310 pages, file 31 MB).

    * In fact, "perfect" rendering is achieved only in the Firefox Nightly build under Windows 7 (with rendering fonts via Direct2D and DirectWrite), in the rest it is close to ideal or not very close, depending on the browser and OS.

    Each pair of screenshots shows a comparison of the previous version of pdf.js (above) and pdf.js v0.2. Andreas Gal says that the difference in the screenshots above should have been much more noticeable, but they did not dare to roll out the initial version of pdf.js until they made the normal loading of PostScript Type 1 for the main font of the document, in order to focus on the remaining problems. Dynamic loading of Type 1 turned out to be an extremely difficult task. It is difficult to overestimate how important this feature is for pdf.js.







    The second pair of screenshots shows some improvements in pdf.js. The most obvious - the inscriptions on the objects of the figure appeared due to the fact that v0.2 correctly loads TrueType fonts. Shadows behind elements are recognized and displayed as background images. Dotted lines are rendered using the new APIs that have been added to the processing of the canvas element by Firefox, and are currently in the process of standardization. A screenshot with a monospaced font is another proof of how important it was to make the most accurate measurement and loading of Type 1 fonts. Color graphics in the diagram are rendered by separate JS functions, which then pass the pixel values ​​to the canvas







    . These specific columns are calculated by a linear gradient function. The text in the chart caption also began to look better - as already mentioned, pdf.js learned to recognize and load different fonts. The comparison above shows a couple of new features v0.2. Signatures on the diagram appeared due to the loading of TrueType fonts, and dashed columns fill due to the implementation of the function for the corresponding patterns. Well, the last comparison shows improvements in the GUI, including a cool preview function - the panel pops up when you hover over it. In addition, in the bottom screenshot, you can see a piece of the second page, whereas earlier pdf.js could only show one page at a time. Andreas Gal thanks all independent developers









    who joined the project and help the Mozilla team. For example, a new UI with a preview function implemented justindarc . Others made support for encrypted PDFs, embedded JPEGs, the Web Workers backend, and more, which will be included in the functionality of the next version of pdf.js. In particular, when rendering 1310-page specifications, Web Workers will be needed to parallelize the processes and the ability to pause the client’s calculations in the main thread (UI responsiveness).

    The developers believe that within two to three months they will be able to bring pdf.js to such a level that it will be able to display most of the PDF documents on the Web well. In the future, you can expect pdf.js to become a native part of the Firefox browser (the extension will be released first).

    The authors of the project also hope that other browsers will follow suit and implement pdf.js support, the code of which is published under a free license (modified by BSD). In the future, it will be able to work equally well in any browser with HTML5 support.

    Now this is not so: almost every browser / OS combination produces different results. This is the fate of every project that is cutting edge technology in the field of unapproved standards. According to Andreas Gal, pdf.js is now at the stage when a significant part of the issues in reality are bugs - of the engine - rendering - of the browser or missing features , but these holes are gradually filled.

    Also popular now: