title: How to use the Python pdf2image module (thus poppler) on Google Cloud Function?
body: <p>I tried convert PDF to JPEG on Google Cloud Functions. I used the Python module <code>pdf2image</code>. But I have no idea how to solve the errors <code>No such file or directory: 'pdfinfo'</code> and <code>&quot;Unable to get page count. Is poppler installed and in PATH?</code> on the cloud function.</p>
  <p>The error code is very similar to <a href="https://stackoverflow.com/questions/57588044/poppler-is-installed-why-do-i-get-an-error-using-pdf2image-on-python3">this question</a>. <a href="https://pypi.org/project/pdf2image/" rel="nofollow noreferrer">pdf2image</a> is a wrapper around &quot;pdftoppm&quot; and &quot;pdftocairo&quot; of poppler. But how can I install the poppler package on google cloud function, and add it to PATH? I can't find relevant references for it. It is even possible? If not, what could be done?</p>
  <p>There is also <a href="https://stackoverflow.com/questions/63781912/using-poppler-for-pdf2image-python-library-on-googles-cloud-functions">this question</a>, but it isn't useful.</p>
  <p>The code look something like the following. Entry point is <code>process_image</code>.</p>
  <pre><code>import requests
  from pdf2image import convert_from_path
  
  def process_image(event, context):
      # Download sample pdf file
      url = 'https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf'
      r = requests.get(url, allow_redirects=True)
      open('/tmp/sample.pdf', 'wb').write(r.content)
  
      # Error occur on this line
      pages = convert_from_path('/tmp/sample.pdf')
  
      # Save pages to /tmp
      for idx, page in enumerate(pages):
          output_file_path = f&quot;/tmp/{str(idx)}.jpg&quot;
          page.save(output_file_path, 'JPEG')
          # To be saved to cloud storage
  </code></pre>
  <p>Requirement.txt:</p>
  <pre><code>requests==2.25.1
  pdf2image==1.14.0
  </code></pre>
  <p>This is the error code I get:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/pdf2image/pdf2image.py&quot;, line 441, in pdfinfo_from_path
      proc = Popen(command, env=env, stdout=PIPE, stderr=PIPE)
    File &quot;/opt/python3.8/lib/python3.8/subprocess.py&quot;, line 858, in __init__
      self._execute_child(args, executable, preexec_fn, close_fds,
    File &quot;/opt/python3.8/lib/python3.8/subprocess.py&quot;, line 1706, in _execute_child
      raise child_exception_type(errno_num, err_msg, err_filename)
  FileNotFoundError: [Errno 2] No such file or directory: 'pdfinfo'
  </code></pre>
  <p>During handling of the above exception, another exception occurred:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py&quot;, line 2447, in wsgi_app
      response = self.full_dispatch_request()
    File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py&quot;, line 1952, in full_dispatch_request
      rv = self.handle_user_exception(e)
    File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py&quot;, line 1821, in handle_user_exception
      reraise(exc_type, exc_value, tb)
    File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/_compat.py&quot;, line 39, in reraise
      raise value
    File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py&quot;, line 1950, in full_dispatch_request
      rv = self.dispatch_request()
    File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py&quot;, line 1936, in dispatch_request
      return self.view_functions[rule.endpoint](**req.view_args)
    File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/__init__.py&quot;, line 149, in view_func
      function(data, context)
    File &quot;/workspace/main.py&quot;, line 11, in process_image
      pages = convert_from_path('/tmp/sample.pdf')
    File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/pdf2image/pdf2image.py&quot;, line 97, in convert_from_path
      page_count = pdfinfo_from_path(pdf_path, userpw, poppler_path=poppler_path)[&quot;Pages&quot;]
    File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/pdf2image/pdf2image.py&quot;, line 467, in pdfinfo_from_path
      raise PDFInfoNotInstalledError(
  pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
  </code></pre>
  <p>Thanks in advance for any help.</p>