【发布时间】:2021-02-09 15:28:29
【问题描述】:
我找到了一种将 PDF 文件转换为 JPG 的方法,实际上是从 PDF 文件中提取图像文件。我已经设法用PyMuPDF lib 做到了。
这是该库的文档:
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
为什么我会得到这个打印输出,我该如何删除它? 我猜它来自 lib,但我不知道如何阻止它
【问题讨论】: