如何将 PyPDF.PageObject 页面呈现为 python 中的 PIL 图像?
How to render a PyPDF.PageObject page to a PIL image in python?
你能帮我把使用 PyPDF2 打开的 pdf 页面渲染成 python3 中的 PIL 图像吗?谢谢!!!
我认为 PyPDF2 无法呈现 pdf 页面。但是,您可以使用 PyMuPDF 的 PyMuPDF to do this. Here is the tutorial。
这里是一个用 PyMuPDF 渲染的例子:
import fitz
from PIL import Image
filename = "test.pdf" # name of pdf file you want to render
n = 0 # n is the page number
#render with PyMuPDF
doc = fitz.open(filename)
page = doc.loadPage(n)
pix = page.getPixmap()
#convert to a PIL image
img = Image.frombytes("RGBA", [pix.width, pix.height], pix.samples)
你能帮我把使用 PyPDF2 打开的 pdf 页面渲染成 python3 中的 PIL 图像吗?谢谢!!!
我认为 PyPDF2 无法呈现 pdf 页面。但是,您可以使用 PyMuPDF 的 PyMuPDF to do this. Here is the tutorial。
这里是一个用 PyMuPDF 渲染的例子:
import fitz
from PIL import Image
filename = "test.pdf" # name of pdf file you want to render
n = 0 # n is the page number
#render with PyMuPDF
doc = fitz.open(filename)
page = doc.loadPage(n)
pix = page.getPixmap()
#convert to a PIL image
img = Image.frombytes("RGBA", [pix.width, pix.height], pix.samples)