Chrome Packaged Apps / pdf.js

I am trying to develop (offline) packaged applications with chrome 23+ that allows the user to create and print a pdf file. I tried various ways to achieve this, but no one works.

Using something like this, the browser / application freezes:

window.html (includes pdf.js (http://code.google.com/p/jspdf/) and genpdf.js (see below)): .... <browser src="about:blank" width="1024" height="768"></browser> genpdf.js: var doc = new jsPDF(); doc.text(20, 20, 'foo'); doc.text(20, 30, 'bar'); document.querySelector('browser').src = window.webkitURL.createObjectURL(new Blob([doc.output()], {type: 'application/pdf'})); 

This would be my preferred way to display the generated PDF file, but when the window was frozen, the user could not print it.

Another way is to save the PDF to your desktop:

 chrome.fileSystem.chooseFile({type: 'saveFile'}, function(writableFileEntry) { writableFileEntry.createWriter(function(writer) { writer.onerror = function(e) { console.log('writeend'); }; writer.onwriteend = function(e) { console.log('writeend'); }; var doc = new jsPDF(); doc.text(20, 20, 'foo'); doc.text(20, 30, 'bar'); writer.write(new Blob([doc.output()], {type: 'application/pdf'})); }, errorHandler); }); 

This works, but the file on the desktop is locked until the application is closed. Is there any api-call that I am missing to free a saved file?

Thanks in advance!

+6
source share
2 answers

In the second solution, I believe that you should specify the size of the buffer, so the writer can find out when the recording ended.

 var docBuffer = doc.output(); writer.write(new Blob([docBuffer], {type: 'application/pdf', 'size': docBuffer.length})); 
+3
source

Take sneak peak to wkhtmltopdf , it creates a PDF file from HTML + CSS page using the WebKit mechanism. I love it, it produces a pixelated result as the page appears in the Chromium browser. There is a version for MS-Windows and Linux, I tried both.

-1
source

Source: https://habr.com/ru/post/925194/


All Articles