![]() ![]() HTML5 introduced Web Workers, which are used to run code in a separate thread from that of browser’s JavaScript thread. In fact, depending on the nature of the PDF, the parsing and rendering phases might take a bit longer which might result in the blocking of other JavaScript functions. But parsing and rendering PDF is not a simple task. pdf.js is the main library, which essentially has methods to fetch a PDF document from some URL. The two files you downloaded contain methods to fetch, parse and render a PDF document. By downloading files this way, you will always have latest version of the library. The above mentioned URLs point to Mozilla’s live demo of PDF.js. You can use following URLs to download necessary files: If, like me, you don’t feel comfortable with Node.js there is an easier way. After you are done with the gulp generic command, you will have those necessary files. To fetch aforementioned files, if you are a Node.js user, you can follow these steps as mentioned on the GitHub repo. Following are two main files required by PDF.js: The first step is to fetch necessary JavaScript files required by PDF.js to work properly. PDF.js, as it’s name states is a JavaScript library which can be used in browser to render PDF documents. Isn’t this cool? Yes, it is!īasic Integration Downloading the Necessary Files Most importantly, you as a developer have full control over rendering the PDF document’s pages as per your requirements. Luckily, there now exists such a tool, PDF.js, created by Mozilla Labs, which can render PDF documents in your browser. You can use browser’s native PDF rendering capability by using the embed tag, but since you don’t have programmatic access you can’t control the rendering phase to suit your needs. Imagine that because of some business rule in your web app, you wanted to disable the Print button, or display only few pages while others require paid membership. But, that native component is outside of the developer’s control. When it comes to the Web, almost every modern browser supports viewing of PDF documents natively. Thanks to all of SitePoint’s peer reviewers for making SitePoint content the best it can be! This article was peer reviewed by Jani Hartikainen, Florian Rappl, Jezen Thomas and Jeff Smith.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |