title: 'Is poppler installed and in PATH' - Running pdf2Image script in android
body: <p>I have a custom python script using pdf2Image which I am trying to run on an android phone. I have  tried these two ways</p>
  <ol>
  <li>Use an android app that can run python scripts on android.</li>
  <li>Create an android app and integrate my python code (using <a href="https://chaquo.com/chaquopy/doc/current/android.html" rel="nofollow noreferrer">chaquopy</a>).</li>
  </ol>
  <p>But in both the cases, I am getting</p>
  <p><code>W/System.err: com.chaquo.python.PyException: PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?</code></p>
  <p>My scripts are running seamlessly on ubuntu terminal (using <code>python &lt;scriptFileName.py&gt;</code>) but when I try to do it on android, it is giving me the above issue</p>
  <p>My trouble is that I am not able to understand how can I install poppler, or add it to PATH in android.</p>
  <p>Following is my script that converts the PDF into JPEG images (Module name = pdf2Img.py):</p>
  <pre class="lang-py prettyprint-override"><code>from pdf2image import convert_from_bytes
  import sys
  import os
  import shutil
  import io
  
  def extractImagesFromPdf(fileContents):
  
      BASE_DIR = 'in_pdfs'
      EXTENSION = '.pdf'
      OUT_DIR = 'images'
      IMG_EXT = '.jpg'
      sep = &quot;/&quot;
  
      if not os.path.exists(getDirectoryPath(BASE_DIR)):
          os.mkdir(getDirectoryPath(BASE_DIR))
  
      pages = convert_from_bytes(fileContents)
  
      if os.path.exists(getDirectoryPath(OUT_DIR)):
          shutil.rmtree(getDirectoryPath(OUT_DIR))
          os.mkdir(getDirectoryPath(OUT_DIR))
  
      page_num = 1
      for page in pages:
          page.save(getDirectoryPath(OUT_DIR) + sep + str(page_num) + IMG_EXT, 'JPEG')
          page_num = page_num + 1
  
  def getDirectoryPath(dir):
      base_path = os.path.dirname(__file__)
      return base_path + &quot;/&quot; + dir
  
  </code></pre>
  <p>This is how I am invoking it</p>
  <pre class="lang-java prettyprint-override"><code>public class MainActivity extends AppCompatActivity {
  
      private static final int PICK_PDF_FILE = 2;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      public void selectAndUploadFile(View view) {
          Intent intent= new Intent(Intent.ACTION_OPEN_DOCUMENT);
          intent.addCategory(Intent.CATEGORY_OPENABLE);
          intent.setType(&quot;application/pdf&quot;);
  
          startActivityForResult(intent, PICK_PDF_FILE);
      }
  
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
          super.onActivityResult(requestCode, resultCode, resultData);
          if (requestCode == PICK_PDF_FILE
                  &amp;&amp; resultCode == Activity.RESULT_OK) {
              Uri inPDF = null;
              if (resultData != null) {
                  inPDF = resultData.getData();
                  Log.i(&quot;SelectAndUpload&quot;, &quot;onActivityResult: &quot; + inPDF);
  
                  if (!Python.isStarted()) {
                      Python.start(new AndroidPlatform(MainActivity.this));
                  }
  
                  Python py = Python.getInstance();
                  PyObject module = py.getModule(&quot;pdf2Img&quot;);
  
                  try {
                      InputStream iStream =   getContentResolver().openInputStream(inPDF);
                      byte[] inputData = getBytes(iStream);
                      PyObject result = module.callAttr(&quot;extractImagesFromPDF&quot;, inputData);
  
                  } catch (Exception e) {
                      Log.i(&quot;Ex&quot;, &quot;Exception!!!&quot;);
                      e.printStackTrace();
                      Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
                  }
  
              }
          }
      }
  
      public byte[] getBytes(InputStream inputStream) throws IOException {
          ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
          int bufferSize = 1024;
          byte[] buffer = new byte[bufferSize];
  
          int len = 0;
          while ((len = inputStream.read(buffer)) != -1) {
              byteBuffer.write(buffer, 0, len);
          }
          return byteBuffer.toByteArray();
      }
  }
  </code></pre>
  <p>And the error is coming at line</p>
  <pre><code>    pages = convert_from_path(BASE_DIR + sep + fileName + EXTENSION)
  </code></pre>
  <p>Few references:</p>
  <ol>
  <li><a href="https://chaquo.com/chaquopy/doc/current/android.html" rel="nofollow noreferrer">Chaquopy getting started documentation</a></li>
  <li><a href="https://stackoverflow.com/questions/10296734/image-uri-to-bytesarray/10297073#10297073">Converting uri to byte[]</a></li>
  <li><a href="https://pdf2image.readthedocs.io/en/latest/reference.html" rel="nofollow noreferrer">pdf2Image (python library) reference documentation</a></li>
  </ol>