python - 如何在 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()
解决方案
对我有用的解决方案:
- 删除设置上的poppler buildback
- 在以下设置中添加 buildpack:https ://github.com/ONode/heroku-buildpack-xpdf
- 在根项目文件夹中手动添加 .xpdfrc 文件
- 重新启动并部署您的测功机
(最初在这里找到解决方案:https ://www.npmjs.com/package/pdf-util?activeTab=readme )
推荐阅读
- c# - 使用 Autofac 在依赖链中选择 LifetimeScope 的更简洁方法
- windows - 如何在不知道文件名的情况下搜索/打开文件类型
- java - mvnDebug tomcat7:运行不要挂起
- c++ - 重载运算符 = 用于在 C++ 中继承标准列表的类
- r - Dplyr::summarise 删除变量
- java - 即使在文件使用时也删除目录
- jenkins - 如何在 Jenkins 中将 PR 标题添加到 GitHub 组织(多分支管道)的 Pull Requests 视图中?
- wcf - .Net Core WCF 客户端 - NTLM 身份验证 - 401
- google-kubernetes-engine - 如何在 kubernetes 机密中/从 kubernetes 机密中存储/检索 KMS 加密的 .enc 文件
- wordpress - Wordpress:根据显示的页面向正文添加动态类