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!
source share