title: Save a PDF from bitmap into internal store or send as intent
body: <p>I want to generate PDF from my bitmap, but I don't want to use external storage (in all examples how to do it they using external storage, but I don't want force users to have a SD card in phone). I want to share my PDF via intent, to send it via email or store in GoogleDrive/Phone storage. I'm using <a href="https://github.com/itext/itextpdf" rel="nofollow noreferrer">Itext library</a>. </p>
  
  <p>For now, I cannot save it on internal storage (I've got an "Error opening file: src" Toast when try to save ), moreover the google drive and mail sending also failed (got message that file cannot be upload/attached)</p>
  
  <p>code:</p>
  
  <pre><code>    Bitmap bitmap = loadBitmapFromView(view);
      //Now create the name of your PDF file that you will generate
      File pdfFile = new File(CreatePDFActivity.this.getFilesDir(), "myPdfFile.pdf");
  
      try {
          Document document=new Document();
  
          PdfWriter.getInstance(document,new FileOutputStream(pdfFile.getAbsolutePath())); //  Change pdf's name.
          document.open();
          ByteArrayOutputStream stream = new ByteArrayOutputStream();
          bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
          Image img =Image.getInstance(stream.toByteArray());  // Change image's name and extension.
  
          float scaler = ((document.getPageSize().getWidth() - document.leftMargin()
                           - document.rightMargin() - 0) / img.getWidth()) * 100; // 0 means you have no indentation. If you have any, change it.
  
          img.scalePercent(scaler);
          img.setAlignment(Image.ALIGN_CENTER | Image.ALIGN_TOP);
  
  
          document.add(img);
          document.close();
  
  
          Intent intent = new Intent(Intent.ACTION_SEND);
  
          intent.putExtra(Intent.EXTRA_SUBJECT, "Test ");
          Uri uri = Uri.fromFile(new File( CreatePDFActivity.this.getFilesDir(), "myPdfFile.pdf"));
          intent.putExtra(Intent.EXTRA_STREAM, uri);
          intent.addFlags( Intent.FLAG_GRANT_READ_URI_PERMISSION );
          intent.setType("application/pdf");
          intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          startActivity(intent);
      }
      catch (Exception e){
          e.printStackTrace();
      }
  </code></pre>