pdf.js

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

北城以北 提交于 2019-11-28 21:00:15
问题 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? 回答1: PDFJS has a member variable numPages , so you'd just iterate through them. BUT it's important to remember that getting a page in pdf.js is asynchronous, so the order wouldn't be guaranteed. So you'd need to chain them

How to know if PDF.JS has finished rendering?

不问归期 提交于 2019-11-28 18:44:02
I am using PDF.JS to render pdf pages into different canvas elements. my requirement is to capture the output of the canvas and to display it as an image. Is there some event to know if the rendering of the pdf page in canvas has been finished or not. because when I try to capture the output of canvas it is blank. but the pdf page is rendered properly. it looks like my capture event is being called before the pdf.js finishes the rendering process. here is my code: page.render(renderContext); var myImage = new Image(); myImage.src = document.getElementById('my-canvas-id').toDataURL(); $('body')

Render .pdf to single Canvas using pdf.js and ImageData

孤人 提交于 2019-11-28 18:26:52
I am trying to read an entire .pdf Document using PDF.js and then render all the pages on a single canvas. My idea: render each page onto a canvas and get the ImageData (context.getImageData()), clear the canvas do the next page. I store all the ImageDatas in an array and once all pages are in there I want to put all the ImageDatas from the array onto a single canvas. var pdf = null; PDFJS.disableWorker = true; var pages = new Array(); //Prepare some things var canvas = document.getElementById('cv'); var context = canvas.getContext('2d'); var scale = 1.5; PDFJS.getDocument(url).then(function

PDF.js scale PDF on fixed width

白昼怎懂夜的黑 提交于 2019-11-28 16:44:30
问题 I have a fixed box where I want to display my PDF's in rendered by PDF.js. As PDF.js documentation is not really accessible (spitting through their source files), I'd like to know whether it's possible to scale a rendered PDF on a fixed width. When I set as CSS: canvas { width: 600px; } for the canvas displaying the PDF, the PDF gets stretched, and the quality gets poor. 回答1: I updated the example from the Pdf.js github http://jsbin.com/pdfjs-prevnext-v2/edit#html,live to scale properly to a

Is there a minimalistic PDF.js sample that supports text selection?

末鹿安然 提交于 2019-11-28 16:14:12
I'm trying PDF.js . My problem is that the Hello World demo does not support text selection. It will draw everything in a canvas without the text layer. The official PDF.js demo does support text selection but the code is too complex. I was wondering if somebody has a minimalistic demo with the text layer. I have committed the example to Mozilla's pdf.js repository and it is available under the examples directory. The original example that I committed to pdf.js no longer exists, but I believe it this example showcases text-selection. They have cleaned up and reorganized pdf.js and so the text

Waiting for promise in for loop

大憨熊 提交于 2019-11-28 11:53:41
问题 I have a bit of trouble getting into this whole async stuff. I'm using pdf.js to read the contents of a pdf file. Everything is working, however the execution order is causing me troubles. This is the code I have: function getText(data) { var contents = []; PDFJS.getDocument(data).then(function(pdf) { var numPages = pdf.pdfInfo.numPages; for (var i = 1; i <= numPages; i++) { pdf.getPage(i).then(function(page) { page.getTextContent().then(function(content) { contents.concat(content.bidiTexts);

Printing PDF using pdf.js

六月ゝ 毕业季﹏ 提交于 2019-11-28 11:25:54
I am embedding a single page PDF in a page using pdf.js and I want to be able to print just the PDF, not the whole HTML page. Is this possible? I had previously loaded a pdf document onto a canvas using pdf.js. The canvas only contains one page. So This is what worked for me for a single page: var canvas = document.getElementById('pdfPage'); var win = window.open('', '', ''); var html = "<img src='" + canvas.toDataURL() + "'>"; win.document.write(html); win.document.close(); win.focus(); win.print(); win.close(); I still need to find out what is needed for multiple pages. If I do, I'll edit

Use PDF.js to statically convert a PDF to HTML

删除回忆录丶 提交于 2019-11-28 07:32:07
PDF.js is the latest library from Mozilla, and is a standards-based PDF renderer that is written entirely in Javascript. Currently you cannot access the generated HTML, and the library can only be used as a viewer. Is it possible to use PDF.js to statically convert a PDF to its HTML equivalent? Considering it renders in a browser, it must be HTML+CSS, and the JS would be used only for navigation. After converting it to HTML I plan to use our existing HTML workflow to import/index/consume the page as if it were an ordinary HTML webpage. Note: this is for the original question, as well as for

PDF.JS in Mobile apps Access-Control-Allow-Origin issue

痞子三分冷 提交于 2019-11-28 01:25:57
问题 I am trying to develop an app for mobile devices using Sencha and Cordova. As PDf support is not available in the browsers of Android I decided to use PDF.JS. It is working fine while loading the local PDf files, but when tring to open remote files it is throwing an error http://<remote server pdf location>. Origin file:// is not allowed by Access-Control-Allow-Origin Please let me know how to fix this issue. Is there any way to fix this in PDF.JS. I need PDF.Js files locally only as the app

Load PDF from filesystem into an Ionic (Cordova) + Android + pdf.js application

扶醉桌前 提交于 2019-11-28 00:55:18
问题 I have trouble integrating pdf.js into an Android Ionic application. I want pdf.js to render a pdf to a prepared canvas. The problem occurs when I am trying to load the document using: PDFJS.getDocument(FILE_PATH) which always ends up with an error. I did some research, there are a lot of questions on SO and the internet on loading files to pdf.js but either they discuss loading pdfs from server, not file:// urls, or they propose some changes in native android code, which I would like to