我找到了一种方法来转换PDF文件到JPG,实际上是从PDF文件中提取图像文件。我已经设法用PyMuPDF库做到了这一点。下面是该库的文档:
https://pymupdf.readthedocs.io/en/latest/
我看过下面的代码:
Extract images from PDF without resampling, in python?
这段代码是:
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为什么我会得到此打印输出,如何删除它?我猜它来自于自由党,但我不知道如何阻止它。
发布于 2020-10-27 19:00:20
该输出可能来自您正在使用的某个库。您可以查看他们的文档,找出是否有日志级别选项,或者作为最后的“修复”,使用contextlib.redirect_stdout (和.redirect_stderr)上下文管理器来隐藏输出。
https://stackoverflow.com/questions/64552961
复制相似问题