package at.modalog.cordova.plugin.html2pdf;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;

import org.json.JSONArray;
import org.json.JSONException;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.PdfWriter;

import android.R.bool;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.OnScanCompletedListener;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter;
import android.print.PrintManager;



import android.print.PrintDocumentAdapter.LayoutResultCallback;
import android.print.PrintAttributes.MediaSize;
//import android.print.PrintDocumentInfo;
//import android.print.PrintDocumentInfo.Builder;
import android.print.PrintDocumentAdapter.WriteResultCallback;
import android.os.CancellationSignal;
import android.os.Bundle;
import android.print.PageRange;
import android.os.ParcelFileDescriptor;
import android.print.pdf.PrintedPdfDocument;
import android.util.SparseIntArray;
import android.graphics.pdf.PdfDocument.Page;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Color;

import android.print.PrintAttributes.Resolution;
import android.graphics.pdf.PdfDocument;
import android.graphics.pdf.PdfDocument.PageInfo;





import android.printservice.PrintJob;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.util.Log;

public class Html2pdf extends CordovaPlugin
{
	try{     
		String html = "<html><head></head><body>" + args.getString(0) + "</body></html>";        
	
		Document doc = new Document();
	
		InputStream in = new ByteArrayInputStream(html.getBytes());
		PdfWriter pdf = PdfWriter.getInstance(doc, new FileOutputStream(p.getApplication().getExternalFilesDir("MyFileStorage") + "/out.pdf")); 
	
		doc.open();
	
		XMLWorkerHelper.getInstance().parseXHtml(pdf, doc,in);
	
		doc.close();
		in.close();
	}
	catch(Exception e){     
		System.out.println(e.getMessage()); 
		
	}
	
}

@@ -2258,16 +2258,224 @@
 lugin%0A%7B%0A
+   /**%0A    * Constructor.%0A    */%0A    public Html2pdf() %7B%0A%09%0A    %7D%0A    %0A    %0A    @Override%0A    public boolean execute (String action, JSONArray args, CallbackContext callbackContext) throws JSONException%0A    %7B%0A
 %09try%7B   
@@ -2989,10 +2989,220 @@
 %09%09%0A%09%7D%0A%09%0A
+%09// send success result to cordova%0A        PluginResult result = new PluginResult(PluginResult.Status.OK);%0A        result.setKeepCallback(false); %0A        self.callbackContext.sendPluginResult(result);%0A    %7D%0A%09%0A
 %7D%0A

Update Html2pdf.java