I'm Currently attempting to include a PDF export feature for my Android Application. This involves populating a Url, putting that into a WebView, then writing the contents of that WebView to a PDF using adapted code from here: public Bitmap viewToBitmap(View view) < Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas); return bitmap; >
public void deleteRecursive(File fileOrDirectory) < if (fileOrDirectory.isDirectory()) for (File child : fileOrDirectory.listFiles()) deleteRecursive(child); fileOrDirectory.delete(); >public void bmpToPdfMail(Bitmap bitmap) < String GVCode = String.valueOf(System.currentTimeMillis() + "_InvoiceTest"); String root = Environment.getExternalStorageDirectory().toString(); File myDir = new File(root + "/Invoices"); if (myDir.exists()) < deleteRecursive(myDir); >myDir.mkdirs(); String fname = GVCode + ".jpg"; File file = new File(myDir, fname); if (file.exists()) < deleteRecursive(file); >try < FileOutputStream out = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); >catch (Exception e) < e.printStackTrace(); >Document document = new Document(); String input = Environment.getExternalStorageDirectory().toString() + "/Invoices/" + GVCode + ".jpg"; String output = Environment.getExternalStorageDirectory().toString() + "/Invoices/" + GVCode + ".pdf"; String stringPrintDirectory = Environment.getExternalStorageDirectory().toString() + "/Invoices/"; File myDirPdf = new File(stringPrintDirectory); if (!myDirPdf.exists()) < myDirPdf.mkdirs(); >try < FileOutputStream fos = new FileOutputStream(output); PdfWriter writer = PdfWriter.getInstance(document, fos); writer.open(); document.open(); Image img = Image.getInstance(input); document.setPageSize(img); document.newPage(); img.setAbsolutePosition(0, 0); document.add(img); document.close(); writer.close(); >catch (Exception e) < e.printStackTrace(); >>
How to create PDF from WebView, which is hidden part? However when the PDF is generated, I am only getting the visible area of the WebView, so information off-screen is being cut off. How to get Whole Content like (Visible or not Visible Part) in WebView to export PDF File From My Android Application.