So, I'm trying to create a PDF from Webview. Right now I can create an image from a web view, but I am having problems decomposing a document on many pages.
First I create a bitmap from webview:
public static Bitmap screenShot(View view) { Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.WHITE); view.draw(canvas); return bitmap; }
Secondly, I create and display the PDF:
public void criaPdf(){ Bitmap bitmap = Utils.screenShot(mContratoWebview); Document doc = new Document(); File dir = new File(getFilesDir(), "app_imageDir"); if(!dir.exists()) { dir.mkdirs(); } File file = new File(dir, "contratoPdf.pdf"); try { FileOutputStream fOut = new FileOutputStream(file); PdfWriter.getInstance(doc, fOut); //open the document doc.open(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); Image image = Image.getInstance(byteArray); image.scaleToFit(PageSize.A4.getHeight(), PageSize.A4.getWidth()); doc.newPage(); doc.add(image); } catch (DocumentException de) { Log.e("PDFCreator", "DocumentException:" + de); } catch (IOException e) { Log.e("PDFCreator", "ioException:" + e); } finally { doc.close(); } mPdfView.fromFile(file) .pages(0, 1) // all pages are displayed by default .enableSwipe(true) .load(); mPdfView.setVisibility(View.VISIBLE); }
This is what I got so far:

So my problem is: The content of the web view is too large to fit in the PDF. How can i solve this?
source share