EzDevInfo.com

pdf.js

PDF Reader in JavaScript

How to Use pdf.js [closed]

I am considering using pdf.js (an open source tool that allows embedding of a pdf in a webpage). There isn't any documentation on how to use it.

I assume what I do is make an html page with the script referenced in the header, and then in the body, I put some sort of function call with an array of the file name and location. Can anyone help me out here?


Source: (StackOverflow)

pdf.js not working with Safari

We're testing out pdf.js and while it seems like an awesome project we can't get it working in Safari.

(Tested on PDF.JS version = 0.8.229 (latest) / Safari 5.1.9 - 6.0.4 / Mac OSX 10.6.8 - 10.8.3)

EXAMPLE:

This is an example of the demo code served from our server with a sample PDF that works on Chrome/FFox but not Safari: http://test.appgrinders.com/pdf_js/test.html

Console output:

Warning: Setting up fake worker. 
Error: Invalid XRef stream (while reading XRef): 
Error: Invalid XRef stream pdf.js:850undefined 
Warning: Indexing all PDF objects 
Error: Invalid XRef stream (while reading XRef): 
Error: Invalid XRef stream pdf.js:850undefined

More tests:

The following is a list of sample PDFs we tested (They were all served from our server, and all worked in Chrome/FFox/Android). The only one that worked with Safari was the PDF file served from the pdf.js project itself:

FAILS IN SAFARI:
http://samplepdf.com/sample.pdf
http://forums.adobe.com/servlet/JiveServlet/previewBody/2041-102-1-2139/Sample.pdf
https://github.com/prawnpdf/prawn/raw/master/data/pdfs/form.pdf

WORKS IN SAFARI:
http://cdn.mozilla.net/pdfjs/helloworld.pdf
(NOTE: This is a sample PDF from the pdf.js project and the only one we ever got working)


We've submitted a bug report, but the developers do not seem to have an answer, so I'm hoping someone here might...

How can we get pdf.js working with Safari?


Source: (StackOverflow)

Advertisements

Loading PDF at a specific page with pdf.js viewer

I'm using pdf.js and the included viewer to display pdfs on my website. I added a menu to the viewer, where users can choose a specific bookmark of different pdf files. If a users is clicking on a menu item the file should be opened and jumping to a specific page.

So far I managed it to open a new pdf file but I didn't find a way to open it at a specific page. I tried it this way:

PDFView.open(src + "/" + dest.file);
PDFView.page = dest.page;

I know, I can use the #page= hashtag when opening the viewer for the first time, but that's not working when I'm loading other files after the viewer is already opened.

Is there any why to solve this problem? Maybe something like a event-listener I can call after the new file is successfully loaded, so I can jump to the page?


Source: (StackOverflow)

How to use pdf.js with Meteor?

I've been trying to get the helloworld example for pdf.js to run in Meteor. So far I have:

  • Placed index.html, hello.js, and pdf.js under the "clients" directory
  • Enclosed the contents of "hello.js" in a "Meteor.startup()" block
  • Stripped out almost everything from index.html:

    <body>
        <canvas id="the-canvas" style="border:1px solid black;"/>
    </body>
    

I thought this was enough to have the example working, but Meteor ends up complaining about the "!DOCTYPE html" declaration in pdf.js, which doesn't exist inside the file, so I am guessing that it gets imported from somewhere.

It feels like I'm missing something obvious to get this working, is there an easy solution for this?

(Aside: I am aware of the pdf.js smart package, but since I am doing development on Windows it's not really an option for me because I can't get Meteorite. Although I figure that since a smart package already exists, it's quite doable get the two to work together.)


Source: (StackOverflow)

How to display whole PDF (not only one page) with PDF.JS?

I've created this demo:

http://polishwords.com.pl/dev/pdfjs/test.html

It displays one page. I would like to display all pages. One below another, or place some buttons to change page or even better load all standard controls of PDF.JS like in Firefox. How to acomplish this?


Source: (StackOverflow)

PDF.js viewer pinch to zoom

I'm using PDF.js for rendering my documents on a web app I'm working on.

However I need to enable pinch to zoom on mobile devices for this and it doesn't look like the library itself allows native zooming.

Is there a library that I could use to the code to simulate (at the very least) pinch and zoom on the same scale as the viewers dropdown zoom selection?


Source: (StackOverflow)

PDF.JS: Render PDF using an ArrayBuffer or Blob instead of URL

I know of a similar question to this one: Pdf.js: rendering a pdf file using a base64 file source instead of url. That question was awesomely answered by Codetoffel but my question is different in that my PDF is retrieved via a RESTful call to my Web API implementation. Let me explain...

First, here's a basic way to use PDF.JS to open a PDF via a URL:

PDFJS.getDocument("/api/path/to/my.pdf").then(function (pdf) {
  pdf.getPage(1).then(function (page) {
    var scale = 1;
    var viewport = page.getViewport(scale);
    var canvas = document.getElementById('the-canvas');
    var context = canvas.getContext('2d');
    canvas.height = viewport.height;
    canvas.width = viewport.width;
    page.render({canvasContext: context, viewport: viewport});
  });
});

This works great, but I am using Angular and its $resource service to make the request for the PDF via my RESTful Web API. I do know that PDF.JS allows me to replace passing the URL as a string in the PDFJS.getDocument method (above) with a DocumentInitParams object, which is defined here. Using the DocumentInitParams object works as follows:

var docInitParams = {
    url: "/api/path/to/my.pdf",
    httpHeaders: getSecurityHeaders(), //as needed
    withCredentials: true
};
PDFJS.getDocument(docInitParams).then(function (pdf) {
    ...
});

This also works, but it works around my Angular $resource by requiring me to construct the api URL. But that's OK because PDFJS allows me to give it the PDF data directly, instead of giving it a URL to the PDF, as follows:

var myPdf = myService.$getPdf({ Id: 123 });

//It's an Angular $resource, so there is a promise to be fulfilled...
myPdf.$promise.then(function() {
    var docInitParams = {
        data: myPdf
    };
    PDFJS.getDocument(docInitParams).then(function (pdf) {
        ...
    });
});

This is the one I can't seem to get to work. I can tell the myService.$gtPdf method to return the data as a blob or as an arraybuffer but neither works. I've tried to convert the arraybuffer returned data to an Uint8Array too, but to no avail.

I'm not sure what else to try and could really use a tip.

How do I get the data returned from my service to work with PDFJS?

Thanks in advance.


Source: (StackOverflow)

Why does opening a pdf with pdf.js sometimes leads to the "save as.." dialog instead?

I've set firefox to my standard pdf viewer because I've had mostly good experiences with pdf.js. Unfortunately, some pdfs won't open and the "save as" dialog ins displayed instead. Why does this happen and how can I fix it?


Source: (StackOverflow)

Primefaces extensions DocumentViewer in hyphenated languages not working

I use pe:documentViewer for display documents and set 'locale' like pt (pt_pt, pt_br, pt-pt or pt-br) but nothing happens and the actions continues in english. why?

My code is:

<pe:documentViewer locale="pt" height="#{previewHeight}" value="#{previewComponent.file}"/>

Source: (StackOverflow)

Displaying PDF on website using pdf.js

I want to put a file sample.pdf on my website, and want it to be displayed using pdf.js. What I want is to display my own file like the demo, with a toolbar, zooming in/out, etc. So far I can't do that yet.

I did check out the helloworld example, but it simply shows the file like an image, without toolbar, zooming in/out, etc. When I put another file with many pages instead of helloworld.pdf, it just shows the first page.


Source: (StackOverflow)

Firefox pdf form displays a "4" in checkbox (instead of a checkmark); Works fine in IE & Chrome

I am creating a pdf document (via ColdFusion), but when I preview the rendered pdf in Firefox, I get the number "4" where my checkmarks are supposed to be (see photo below). When I preview the exact same pdf in Chrome or IE, I see the checkmark, and it all works perfectly!

I am pre-populating the pdf form fields (via ColdFusion session variables), and then rendering the pdf using the following markup:

<cfpdfform source="82040.pdf" action="populate">
   <cfpdfformparam name="org" value="">
</cfpdfform>

Here is the resulting pdf form in Internet Explorer:

Note how the checkmark is rendered properly: the checkmark renders normally in IE

Here is the same form previewed in FireFox:

Note how the the checkbox has a "4" instead of a checkmark: In firefox I get a "4" instead of a checkmark

Any help would be greatly appreciated!


Source: (StackOverflow)

Highlight a section inside pdf using Pdf.js

I'm currently using pdf.js for my project for rendering pdf Now there is this tricky task to highlight a section of pdf page given the co-ordinate

example

given a boundary section like [(31,35),(40,35),(40,40),(31,40)] I should highlight the given section with nay primary color of choice

How to write a javascript to actually using pdf.js api to accomplish this task

Is it possible or am I sounding over ambitions


Source: (StackOverflow)

How to render a pdf file using pdf.js?

I created an html file with content as below index.html

<html>
  <head>
    <script type="text/javascript" src="./pdf.js"></script>
    <script type="text/javascript" src="./hello.js"></script>
  </head>
  <body>
    <canvas id="the-canvas" style="border:1px solid black;"/>
  </body>
</html>

hello.js with content

PDFJS.disableWorker = true;
var pf = PDFJS.getDocument('./helloworld.pdf')
pf.then(function(pdf) {
  pdf.getPage(1).then(function(page) {
    var scale = 1.5;
    var viewport = page.getViewport(scale);

    //
    // Prepare canvas using PDF page dimensions
    //
    var canvas = document.getElementById('the-canvas');
    var context = canvas.getContext('2d');
    canvas.height = viewport.height;
    canvas.width = viewport.width;

    //
    // Render PDF page into canvas context
    //
    var renderContext = {
      canvasContext: context,
      viewport: viewport
    };
    page.render(renderContext);
  });
});

But the pdf is not shown correctly when I point the browser to index.html. I want the user to be able to select a pdf file on his computer and show that pdf in browser window.


Source: (StackOverflow)

PDF Rendering in HTML5 Canvas

How can I render PDF in HTML5 canvas?

I came up with pdf.js script https://github.com/mozilla/pdf.js. But its seems this project is still in development.


Source: (StackOverflow)

Refused to get unsafe header "Accept-Ranges" error from pdf.js with amazon urls

I'm trying to use pdf.js with range requests (progressive loading of the pdf document) , but when i'm trying to load the pdfs from amazon s3 urls this error appears in the console :

-Refused to get unsafe header "Accept-Ranges"

and the pdf doesn't load via 206 partial content (range requests) but 200 and then viewed in the viewer.

this is an example of pdf url :

https://kotob.s3.amazonaws.com/book.pdf?Signature=irgVfoAZuPPIp5kpCesni2MzpLo%3D&Expires=1366576877&AWSAccessKeyId=AKIAILBHXSTPUIBTRMSA

any help


Source: (StackOverflow)