This is a pdf creation plugin for Phonegap 3.3.0 / Cordova 3.3.1 supporting Android (>=2.3.3) and iOS(>=6.0). It creates a pdf from the given html and stores it on the device.
There is one method:
- create(html, filePath, successCallback, errorCallback)
You may use phonegap CLI as follows:
➜ phonegap local plugin add https://github.com/moderna/cordova-plugin-html2pdf.git [phonegap] adding the plugin: https://github.com/moderna/cordova-plugin-html2pdf.git [phonegap] successfully added the plugin
This Plugin requires iText.jar to be added to your project. Here is the last open source version (4.2.0) of it:
- GitHub: https://github.com/ymasory/iText-4.2.0
- Download .jar:: https://github.com/ymasory/iText-4.2.0/downloads
It has been confirmed to work with cordova 3.3.0+
document.addEventListener('deviceready', onDeviceReady);
function onDeviceReady()
{
var success = function(status) {
alert('Message: ' + status);
}
var error = function(status) {
alert('Error: ' + status);
}
window.html2pdf.create(
"<html><head></head><body><h1>Some</h1><p>html content.</p></body></html>",
"~/Documents/test.pdf", // on iOS,
// "test.pdf", on Android (will be stored in /mnt/sdcard/at.modalog.cordova.plugin.html2pdf/test.pdf)
success,
error
);
}