title: Access PDF files from 'res/raw' or assets folder programmatically to parse with given methods
body: <h1>Access PDF files from 'res/raw' or assets folder programmatically to parse with given methods</h1>
  <h2>Explanation:</h2>
  <p>Right now this program accesses a file from a file manager that takes the selected files path and sets it to the 'mFilename' EditText field. The show PDF button listener below shows the String 'pdffilename' gets assigned the String contained in the 'mFilename' EditText field. The PdfViewerActivity is started and the String 'pdffilename' is passed as an Extra. In the onCreate() the intent is checked if null or not. This is where I think the change can/should be made. The String 'pdffilename' is assigned what you see below. What I want to do is store the PDF files in one of two ways... int the 'res/raw/example_folder/example.pdf' or in the assets folder. I want to assign 'pdffilename' programmatically with the path for where I am storing these PDF files. I have tried many different approaches all of which have either did not compile, caused errors, or caused a &quot;file: res/raw/example_folder/example.pdf does not exist!&quot;.</p>
  <p><strong>So Basically...</strong></p>
  <ul>
  <li>I want to store PDF files in 'res/raw/folder_example/example.pdf' or the assets folder</li>
  <li>I want to access these files from the code as in I do not need to use a file manager</li>
  <li>Anyway that will solve this would be the biggest help, I am pretty good with Java, but I am by no means a superstar so please explain a little with your code</li>
  </ul>
  <p>Thank you so much and I will be standing by to answer comments and edit this post. I hope this post will be helpful to other users so I will be posting the code for the solution. when completed. Thank you again!</p>
  <p><strong>Show PDF button Listener in PdfFileSelectActivity...</strong></p>
  <pre><code>OnClickListener ShowPdfListener = new OnClickListener()
  {
      public void onClick(View v)
      {
          mFilename = (EditText) findViewById(R.id.filename);
          String pdffilename = mFilename.getText().toString();
          Intent intent = new Intent(PdfFileSelectActivity.this,
          PdfViewerActivity.class)
          .putExtra(EXTRA_PDFFILENAME, pdffilename);
          startActivity(intent);
      }
  };
  </code></pre>
  <p><strong>PdfViewerActivity's onCreate() invoked from show PDF Listener above...</strong></p>
  <pre><code>Intent intent = getIntent();
   
  if (intent != null)
  {
      if (&quot;android.intent.action.VIEW&quot;.equals(intent.getAction()))
      {
          pdffilename = storeUriContentToFile(intent.getData());
      }
      else {
          pdffilename = getIntent().getStringExtra(PdfFileSelectActivity.EXTRA_PDFFILENAME);
      }
  }
  
  if (pdffilename == null)
      pdffilename = &quot;no file selected&quot;;
  
  setContent(null);
  </code></pre>
  <p><strong>setContent() called from above (if needed) ...</strong></p>
  <pre><code>private void setContent(String password)
  {
      try {
          parsePDF(pdffilename, password);
      }
      catch (PDFAuthenticationFailureException e)
      {
          System.out.println(&quot;Password needed&quot;);
      }
  }
  </code></pre>
  <p><strong>parsePDF() called from above (if needed) ...</strong></p>
  <pre><code>    private void parsePDF(String filename, String password) throws PDFAuthenticationFailureException
      {
          long startTime = System.currentTimeMillis();
          try {
              File f = new File(filename);
              long len = f.length();
              if (len == 0) {
                  mGraphView.showText(&quot;file '&quot; + filename + &quot;' not found&quot;);
              }
              else {
                  mGraphView.showText(&quot;file '&quot; + filename + &quot;' has &quot; + len + &quot; bytes&quot;);
                  openFile(f, password);
              }
          }
          catch (PDFAuthenticationFailureException e)
          {
              throw e;
          } catch (Throwable e) {
              e.printStackTrace();
              mGraphView.showText(&quot;Exception: &quot;+e.getMessage());
          }
          long stopTime = System.currentTimeMillis();
          mGraphView.fileMillis = stopTime-startTime;
  
     }
  </code></pre>
  <p><strong>Thank you again!</strong></p>