首页 > 解决方案 > 如何在 Heroku 上使用 poppler buildpack

问题描述

我想在 Heroku 上使用 pdf2image,它是 python 包,它需要 poppler,所以我必须添加 poppler buildpack。

我添加了https://github.com/survantjames/heroku-buildpack-poppler.git并参考了将 poppler 安装到 Heroku Server django 上,但我的应用程序显示错误并崩溃。

所以我在 Heroku 上使用 bash 进行了检查,poppler 的 bin 目录路径添加了环境变量,但是 poppler utils 失败并且不起作用。

pdfinfo(poppler utils 之一)的错误消息是:

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

作为对此的回应,我从https://elements.heroku.com/buildpacks/freddix/libpng12添加了 libpng12 buildpack,但没有改善。如何在 Heroku 上使用 poppler buildpack?

构建包:

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

应用程序代码(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()

标签: pythonpython-3.xherokubuildpackpoppler

解决方案


对我有用的解决方案:

  1. 删除设置上的poppler buildback
  2. 在以下设置中添加 buildpack:https ://github.com/ONode/heroku-buildpack-xpdf
  3. 在根项目文件夹中手动添加 .xpdfrc 文件
  4. 重新启动并部署您的测功机

(最初在这里找到解决方案:https ://www.npmjs.com/package/pdf-util?activeTab=readme )


推荐阅读