python - 将 PDF 转换为图像打印输出没有打印功能
问题描述
我找到了一种将 PDF 文件转换为 JPG 的方法,实际上是从 PDF 文件中提取图像文件。PyMuPDF
我已经设法用lib做到了。这是该库的文档:
https://pymupdf.readthedocs.io/en/latest/
我看过这段代码:
这个代码:
https://www.thepythoncode.com/article/extract-pdf-images-in-python
我写了一个代码,没有给我任何错误,这是代码:
import fitz
import cv2
import numpy as np
doc = fitz.open("sample15.pdf")
#print(doc)
my_images = []
for i in range(len(doc)):
for img in doc.getPageImageList(i):
xref = img[0]
img = doc.extractImage(xref)
img = img["image"]
nparr = np.frombuffer(img, np.uint8)
img_np = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
my_images.append(img_np)
如您所见,我在任何地方都没有打印功能,但我的程序会打印:
mupdf: expected object number #this is printed red
xref 9 image type jpeg
xref 12 image type jpeg
xref 15 image type jpeg
xref 18 image type jpeg
xref 21 image type jpeg
xref 24 image type jpeg
为什么我会得到这个打印输出,我该如何删除它?我猜它来自lib,但我不知道如何阻止它
解决方案
该输出可能来自您正在使用的库之一。您可以查看他们的文档以确定是否有日志记录级别选项,或者作为最后的“修复”,使用contextlib.redirect_stdout
(和.redirect_stderr
)上下文管理器隐藏输出。
推荐阅读
- concrete5 - 迁移后保留旧 cID url
- python - 如何从数据集中在 pandas 中创建标题和列?
- git - 为 git 子模块的最后一次提交运行 travis build
- java - Thymeleaf 3 使用点符号访问地图
- javascript - 使用高阶组件为每个组件添加事件监听器
- excel - 使用具有自定义正文/主题的 VBA 回复特定 Outlook 电子邮件
- c++ - 为什么 pthread_cond_wait() 不与“-lpthread”链接时不阻塞?
- google-dl-platform - Jupyter Lab 的 CloudShell 的 Web 预览不起作用
- vba - 视觉基本程序太大的错误和不明确的名称检测到 worksheet_change
- salesforce - Salesforce Lightning 组件视图数据未刷新