dreamer
dreamer

Reputation: 901

How to integrate Chromes built in PDF viewer into a webapp

When clicking on PDF links in a webapp, user should be taken to PDF viewer page from where

  1. print request can be made
  2. user should not be able to download the document

Should I be using a browsers builtin PDF viewer for this purpose?

What are the advantages of pdf.js over the built-in browser PDF viewer?

More importantly, do suggest ways to integrate my webapp with Chromes builtin PDF viewer and also on how to satisy above 2 conditions?

Upvotes: 0

Views: 2716

Answers (2)

Riddhesh Sanghvi
Riddhesh Sanghvi

Reputation: 1222

As to the question about benefits of using pdf.js over any bulit in pdf viewers:

  1. The traditional approach to rendering PDFs in a browser is to use a native-code plugin, either Adobe’s own PDF Reader or other commercial renderers, or some open source alternative (e.g. poppler). From a security perspective, this enlarges the trusted code base, and because of that Google’s Chrome browser goes through quite some pain to sandbox the PDF renderer to avoid code injection attacks. An HTML5-based implementation of pdf.js is completely immune to this class of problems.
  2. PDF.js has a speed advantage over any type of plugin because it starts rendering right away, with inbuilt plugin you have to wait for a plugin to load. Also if the plugin has been disabled by the user then your pdf will not be opened. But this issue will never arise while using pdf.js.

image source: https://hacks.mozilla.org/2014/05/how-fast-is-pdf-js/

  1. The above graph gives us almost all the interesting results at one look. You see a histogram of the time it took to process all the pages in the PDFs in relation to the average time it takes to process the average page of the Tracemonkey Paper (the default PDF you see when opening PDF.js).
  2. PDF.js works on almost all well known web as well as smartphone browsers. Here is the list of the currently supported browsers. Thus compared to what you are trying to do right now(i.e., trying to figure out only for chrome) using pdf.js will widen your scope of users and the browsers they can use for your product.

  3. Printing functionality is already present in pdf.js so that already solves your first requirement.

  4. As to your second need that is to prevent downloading of a pdf. Here(the last comment in the link by ztraboo) where you will find which lines to comment out and what downloading code to be deleted from pdf.js source code so as to remove the download button and the code facilitating the same.

  5. Finally a quick tutorial to getting started with pdf.js is here. Just use your actual server instead of the localhost there.

Upvotes: 3

Eugene
Eugene

Reputation: 2878

PDF.js is the client-side javascript script that provides the following advantages over native plugins:

  • it is not requiring a native code to execute and it is safer (in theory) to use PDF.js comparing to plugin that runs as the native application and so less secure;
  • with pdf.js you may display PDF file even if user turned off all native plugins in Chrome (for security reasons, for example);
  • web developer may instantly provide the updated pdf.js instead of asking user to download and install the newer plugin for the browser;
  • with PDF.js you may access rendered PDF elements from your javascript code but with plugins you are actually running another application (PDF viewer plugin) where you have limited access its properties, methods and UI;

So saying about your question you should better go with PDF.js so you may implement deep integration with your code and the viewer. But with pdf plugin you are not able to access its elements, UI etc except the limited API it provides.

Upvotes: 1

Related Questions