python - 使用 Python 获取 PDF 版本
问题描述
我需要从 PDF 文档中提取 PDF 版本。我尝试了 PDF 矿工,但它仅提供以下信息:
- PDF 生成器
- 已创建
- 修改的
- 应用
下面是我试过的代码:
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
fp = open("ibs.servlets.pdf", 'rb')
parser = PDFParser(fp)
doc = PDFDocument(parser)
parser.set_document(doc)
if len(doc.info) > 0:
info = doc.info[0]
print(info)
除了我可以使用的 pdf miner 之外,还有其他库吗?
解决方案
PDF 版本作为注释存储在 PDF 文件的第一行中。我找不到如何使用 pdfparser 获取此信息,但使用PyPDF2我可以手动检索此信息:
from PyPDF2.pdf import PdfFileReader
doc = PdfFileReader('ibs.servlets.pdf')
doc.stream.seek(0) # Necessary since the comment is ignored for the PDF analysis
print(doc.stream.readline().decode())
输出:
%PDF-1.5
推荐阅读
- excel - 如何使用基于自定义数字格式的 countif
- testing - 赛普拉斯抛出 SyntaxError: 'import' 和 'export' 可能只出现在 'sourceType: module' (17:0)
- node.js - 使用 MulterGoogleStorage 和 NestJS 删除文件
- java - 拆分数字时将空字符串添加到字符串数组
- java - Java保存文件在程序重新启动时清除
- c++ - 如何验证所有正确的输入数字C++
- c - 如何在 C txt 文件中读取一行中的单词数
- python-3.x - 用于为模型创建 train.record 的 Tensorflow KeyError
- python - discord.py 嵌入带有时间戳的页脚
- angular - 如何在 *ngfor 中显示数组对象的数组