title: Create a PDF from Webview on Android
body: <p>So I am trying to create a PDF from a Webview. Right now I can create an image from the webview, but I am having some problems to split my document in many pages.</p>
  
  <p>First, I create a Bitmap from the webview:</p>
  
  <pre><code>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;
      }
  </code></pre>
  
  <p>Second, I create and I show the PDF:</p>
  
  <pre><code>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);
  }
  </code></pre>
  
  <p>This is what I got so far: </p>
  
  <p><a href="https://i.stack.imgur.com/ZO4zk.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ZO4zk.png" alt="enter image description here"></a></p>
  
  <p>So my problem is: <strong>The content of the Webview is too big to fit in the PDF. How can I solve this?</strong></p>