使用 python 和 pdfkit 将 PDF 转换为 HTML

问题描述 投票:0回答:1

这个站点上,Adobe 写了关于使用 pdfkit 从 pdf 到 html 的转换

他们使用

pdfkit.from_pdf(...)
方法。

此脚本使用“pdfkit”库将 PDF 文件转换为 HTML。要使用此脚本,您需要安装“pdfkit”库...

我想用这个方法的时候报错

Traceback (most recent call last):
  File "C:\TestPdfToHtml\script.py", line 7, in <module>
    html_file = pdfkit.from_pdf(pdf_file, "my_html_file.html")
                ^^^^^^^^^^^^^^^
AttributeError: module 'pdfkit' has no attribute 'from_pdf'. Did you mean: 'from_url'?

我该如何解决这个问题?

以下是完整脚本

import pdfkit
# Read the PDF file
pdf_file = open('test2.pdf', 'rb')
# Convert the PDF to HTML
html_file = pdfkit.from_pdf(pdf_file, "my_html_file.html")
# Close the PDF file
pdf_file.close()
python pdfkit pdf-to-html
1个回答
1
投票

可能是新版本的pdfkit不支持pdfkit.from_pdf。你可以试试 pdfkit.from_file()

pdfkit.from_file(pdf_file, html_file)

希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.