pdf.js

PDF.js scale PDF on fixed width

♀尐吖头ヾ 提交于 2019-11-29 21:03:45
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. halex I updated the example from the Pdf.js github http://jsbin.com/pdfjs-prevnext-v2/edit#html,live to scale properly to a fixed canvas width. See http://jsfiddle.net/RREv9/ for my code. The important line is var viewport =

How to correctly extract text from a pdf using pdf.js

霸气de小男生 提交于 2019-11-29 19:21:13
问题 I'm new to ES6 and Promise. I'm trying pdf.js to extract texts from all pages of a pdf file into a string array. And when extraction is done, I want to parse the array somehow. Say pdf file(passed via typedarray correctly) has 4 pages and my code is: let str = []; PDFJS.getDocument(typedarray).then(function(pdf) { for(let i = 1; i <= pdf.numPages; i++) { pdf.getPage(i).then(function(page) { page.getTextContent().then(function(textContent) { for(let j = 0; j < textContent.items.length; j++) {

PDF downloading directly in Google Chrome — how to display in browser window instead? [closed]

牧云@^-^@ 提交于 2019-11-29 19:12:04
问题 I have been using Google Chrome and recently I have re-installed my browser. I found that whatever PDF links I open are directly downloading. However, I want them to be view on browser. How can I do this? Chrome is an updated version. 回答1: For Chrome to open a PDF inline, in the browser window itself, several requirements have to be met, one for the browser itself, the other for the remote server offering the PDF: There must be a PDF viewer enabled for Chrome, either the external PDF.js one

Waiting for promise in for loop

一世执手 提交于 2019-11-29 18:14:00
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); }) }); } }) } This is working as intended, however, I would like to pass contents when all pages are

PDF.js Inserting Images

末鹿安然 提交于 2019-11-29 15:53:24
I've started using PDF.js , an excelent work, by the way. But now I want to insert an image (from a canvas element) on the pdf page. Here's my code: var image = myCanvas.getContext('2d').getImageData(0,0,400,300), doc = new pdf(); doc.setProperties({ title: fileName, author: 'VirtuaLab®', creator: 'pdf.js' }); doc.addPage(); data = doc.output(); But I haven't found anything about inserting images on PDF.js pages. Maybe doc.image() or doc.addImage ? Disclaimer: I work for Bytescout Unfortunately PDF.js not working with images and that is why we developed PDF Generator SDK for Javascript (free

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

£可爱£侵袭症+ 提交于 2019-11-29 07:45:28
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 needs offline capability also. Thanks in advance Ratheesh Rather than calling PDFJS.getDocument with a

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

こ雲淡風輕ζ 提交于 2019-11-29 07:11:20
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 avoid: if possible I am looking for a pure JS cordova solution, or a plugin. I tried experimenting with

Extract text from pdf file using javascript

喜你入骨 提交于 2019-11-29 01:55:13
问题 I want to extract text from pdf file using only Javascript in the client side without using the server. I've already found a javascript code in the following link: extract text from pdf in Javascript and then in http://hublog.hubmed.org/archives/001948.html and in: https://github.com/hubgit/hubgit.github.com/tree/master/2011/11/pdftotext 1) I want please to know what are the files which are necessary for these extraction from the previous ones. 2) I don't know exactly how to adapt these codes

How to search with pdf.js?

大憨熊 提交于 2019-11-28 23:39:05
I'm displaying a pdf file with pdf.js in my Ionic App. I do not use viewer.js and viewer.html, because I need a totally different layout. Now I have a custom search bar and I want to highlight terms in my pdf file. Is there a function I can invoke to do this? I'm rendering the file like this: $scope.renderPages = function(pdfDoc) { $scope.pdfFile = pdfDoc; for(var num = 1; num <= pdfDoc.numPages; num++){ pdfDoc.getPage(num).then($scope.renderPage); } } $scope.renderPage = function(page) { var viewport = page.getViewport(1); scale = document.getElementById('viewer').clientWidth / viewport.width

Extract text from pdf file using javascript

南楼画角 提交于 2019-11-28 23:03:49
I want to extract text from pdf file using only Javascript in the client side without using the server. I've already found a javascript code in the following link: extract text from pdf in Javascript and then in http://hublog.hubmed.org/archives/001948.html and in: https://github.com/hubgit/hubgit.github.com/tree/master/2011/11/pdftotext 1) I want please to know what are the files which are necessary for these extraction from the previous ones. 2) I don't know exactly how to adapt these codes in an application, not in the web. Any answer is welcome. Thank you. here is a nice example of how to