/cordova-plugin-html2pdf

This is a phonegap / cordova 3.3.0 plugin which converts the given html to a pdf document and stores it on the device.

Primary LanguageJavaOtherNOASSERTION

Html 2 Pdf

This is a pdf creation plugin for PCordova 6.1.1+ supporting Android (>4.1) 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)

Installation

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:

It has been confirmed to work with cordova 3.3.0+

Usage

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
        );
}