title: PDFDocument File save
body: <p>Sorry, If this question is already asked,
  I searched quite lot on this question but not got the solution.</p>
  
  <p>I am developing an android app which generate PDF files using <a href="https://developer.android.com/reference/android/graphics/pdf/PdfDocument.html" rel="nofollow noreferrer">PDFDocument</a> Library of android.</p>
  
  <p>There is some weird problem, After generating PDF File, it is visible in Phone's File Explorer but not visible in Computers File Explorer (Such as Android File Transfer of Mac,My Computer of Windows and File Explorer of Ubuntu), I think I am missing something in the code. Please Help.</p>
  
  <p><strong>Here is my code</strong></p>
  
  <pre><code>    PdfDocument document = new PdfDocument();
  
      PdfDocument.PageInfo pageinfo = new  PdfDocument.PageInfo.Builder(PAGEWIDTH,PAGEHEIGHT,1).create();
  
  
      PdfDocument.Page page = document.startPage(pageinfo);
  
      Canvas canvas = page.getCanvas();
  
      Paint paint = new Paint();
  
  
      paint.setTextSize(getResources().getDimension(R.dimen.textsize));
      paint.setTextAlign(Paint.Align.CENTER);
  
          paint.setColor(ContextCompat.getColor(getApplicationContext(),R.color.colorName));
      canvas.drawText(getResources().getString(R.string.app_name),PAGEWIDTH/2,50,paint);
  
  
      document.finishPage(page);
  
  
      String targetPdf = "/sdcard/documents/myfile.pdf";
      File filepath = new File(targetPdf);
      try {
  
      filepath.createNewFile();
  
      document.writeTo(new FileOutputStream(filepath));
      Toast.makeText(getApplicationContext(),
      getResources().getString(R.string.success),
      Toast.LENGTH_SHORT).show();
  
  
      }
      catch (IOException e){
      e.printStackTrace();
      Toast.makeText(getApplicationContext(),
      getResources().getString(R.string.error) + e.toString(),
      Toast.LENGTH_LONG).show();
      }
  
      document.close();
  </code></pre>
  
  <p><strong>Phone File Explorer Image</strong></p>
  
  <p><a href="https://i.stack.imgur.com/KUjvI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KUjvI.png" alt="enter image description here"></a></p>
  
  <p><strong>Computer File Explorer Image</strong></p>
  
  <p><a href="https://i.stack.imgur.com/PPENv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PPENv.png" alt="enter image description here"></a></p>