title: How to render PDF on Android using PdfRenderer
body: <p>I'm failing on this task in both cases:  </p>
  
  <p><strong>1.</strong> Trying to open it from the phone memory<br>
  <strong>2.</strong> Trying to open it from the assets</p>
  
  <p>I have <em>render()</em> method which is in <em>1st</em> case looking like this:           </p>
  
  <pre><code>private void render() {
      try {
          imageView = (ImageView) findViewById(R.id.page);
  
          int REQ_WIDTH = 1;
          int REQ_HEIGHT = 1;
          REQ_WIDTH = imageView.getWidth();
          REQ_HEIGHT = imageView.getHeight();
  
          Bitmap bitmap = Bitmap.createBitmap(REQ_WIDTH, REQ_HEIGHT, Bitmap.Config.ARGB_4444);
  
          File file = new File(Environment.getExternalStorageDirectory() + "/Download/test.pdf");
  
          PdfRenderer renderer = new PdfRenderer(ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY));
  
          if (currentPage &lt; 0) {
              currentPage = 0;
          } else if (currentPage &gt; renderer.getPageCount()) {
              currentPage = renderer.getPageCount() - 1;
          }
  
          Matrix matrix = imageView.getImageMatrix();
          Rect rect = new Rect(0, 0, REQ_WIDTH, REQ_HEIGHT);
  
          renderer.openPage(currentPage).render(bitmap, rect, matrix, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
  
          imageView.setImageMatrix(matrix);
          imageView.setImageBitmap(bitmap);
          imageView.invalidate();
          renderer.close();
          } catch (Exception e) {
              e.printStackTrace();
          }
  }
  </code></pre>
  
  <p>Most interesting part of thrown exception <a href="http://pastebin.com/pUBH8fca" rel="nofollow noreferrer">is here</a>. In case you want to see whole logs <a href="http://pastebin.com/SkdbinUM" rel="nofollow noreferrer">click here</a>.</p>
  
  <p>And yes, I've added needed permission in <code>AndroidManifest.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.john.pdfreader"&gt;
  
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=".BookActivity"&gt;
              &lt;intent-filter&gt;
                      &lt;action android:name="com.example.schoolreader.BookActivity" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Let's take a look on the <em>2nd</em> case(reading from the assets):</p>
  
  <pre><code>// ...previous code
  ParcelFileDescriptor input = getAssets().openFd("test.pdf").getParcelFileDescriptor();
  PdfRenderer renderer = new PdfRenderer(input);
  // ..previous code
  </code></pre>
  
  <p>In this case it says the same, but if I remember correctly there was smth saying <code>cannot create document</code>, but now it's gone and exception looks the same. Anyway, why did I start talking about 2nd case? <a href="https://code.google.com/p/android/issues/detail?id=82841" rel="nofollow noreferrer">There's an open issue</a> saying that  <code>META-INF</code> should be at the end of the apk. Mine is the at the end and it still not working.</p>
  
  <p>Frankly, I've tried even an example from Androidstudio itself. And you know what? It's working! But only with their <code>sample.pdf</code> and when I try to replace it with mine it just crashes. Do you have any idea what I can try to make pdf rendering on my Android?</p>
  
  <p>Everything was tested on Nexus 5, Android 6.0 Marshmallow.</p>