2

I want to use pdf2image that is python package on Heroku, and it needs poppler so I have to add poppler buildpack.

I added https://github.com/survantjames/heroku-buildpack-poppler.git with referance to Install poppler onto Heroku Server django but my app showed error and crashed.

So I checked with bash on Heroku, path of poppler's bin direcroty is added enviroment variable but poppler utils fail and don't work.

The error message of pdfinfo (one of poppler utils) is:

pdfinfo: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory

In response to this, I added libpng12 buildpack from https://elements.heroku.com/buildpacks/freddix/libpng12 but it didn't improve. How do I use poppler buildpack on Heroku?

buildpacks:

1. https://github.com/survantjames/heroku-buildpack-poppler.git
2. heroku/python

app's code(python3):

from flask import Flask, Response
import pdf2image
import io

app = Flask(__name__)


@app.route('/')
def index():
    return 'Hello, World!'

@app.route('/img/')
def img():
    img = pdf2image.convert_from_path(f'{app.root_path}/static/pdf/miku.pdf')[0]
    buffer = io.BytesIO()
    img.save(buffer, 'PNG')
    return Response(buffer.getvalue(), mimetype='image/png')


if __name__ == '__main__':
    app.run()

2 Answers2

0

The solution that worked for me:

  1. remove poppler buildback on the settings
  2. add buildpack on the settings for: https://github.com/ONode/heroku-buildpack-xpdf
  3. manually adding the .xpdfrc file in the root project folder
  4. restart and deploy your dyno

(found solution originally here: https://www.npmjs.com/package/pdf-util?activeTab=readme)

0

The solution worked for me with some edits(Python 3):

  1. Add the buildpack to Heroku:

    heroku buildpacks:set heroku/python

    heroku buildpacks:add --index 1 heroku-community/apt

  2. Make a file named Aptfile in your project folder and write build-essential libpoppler-cpp-dev pkg-config python3-dev inside.