如何在 pdfminer3 中查看来自 pdf 的图像
How do I view images from pdf in pdfminer3
这是我的代码。
from pdfminer3.layout import LAParams
from pdfminer3.pdfpage import PDFPage
from pdfminer3.pdfinterp import PDFResourceManager
from pdfminer3.pdfinterp import PDFPageInterpreter
from pdfminer3.converter import PDFPageAggregator
from pdfminer3.converter import TextConverter
import io
resource_manager = PDFResourceManager()
fake_file_handle = io.StringIO()
converter = TextConverter(resource_manager, fake_file_handle,laparams=LAParams())
page_interpreter = PDFPageInterpreter(resource_manager, converter)
with open('/storage/emulated/0/Download/Rick-Riordan-The-Tyrants-Tomb-The-Trials-of-Apollo-4.pdf','rb') as fh:
for page in PDFPage.get_pages(fh,
caching=True,
check_extractable=True):
page_interpreter.process_page(page)
text = fake_file_handle.getvalue()
# close open handles
converter.close()
fake_file_handle.close()
print(text)
我只想看图。我的版本是python 3.我不想导入另一个模块,所以请尝试给出使用pdfminer3的解决方案。
您需要在文本转换器中指定保存 pdf 图像的位置。尝试添加 ImageWriter..
pdfResourceManager = PDFResourceManager()
convertedText = StringIO()
layoutParams = LAParams()
imageWriter = ImageWriter('pathToSaveImages/..')
converter = TextConverter(pdfResourceManager, convertedText, codec='utf-8',laparams=layoutParams, imagewriter=imageWriter)
这是我的代码。
from pdfminer3.layout import LAParams
from pdfminer3.pdfpage import PDFPage
from pdfminer3.pdfinterp import PDFResourceManager
from pdfminer3.pdfinterp import PDFPageInterpreter
from pdfminer3.converter import PDFPageAggregator
from pdfminer3.converter import TextConverter
import io
resource_manager = PDFResourceManager()
fake_file_handle = io.StringIO()
converter = TextConverter(resource_manager, fake_file_handle,laparams=LAParams())
page_interpreter = PDFPageInterpreter(resource_manager, converter)
with open('/storage/emulated/0/Download/Rick-Riordan-The-Tyrants-Tomb-The-Trials-of-Apollo-4.pdf','rb') as fh:
for page in PDFPage.get_pages(fh,
caching=True,
check_extractable=True):
page_interpreter.process_page(page)
text = fake_file_handle.getvalue()
# close open handles
converter.close()
fake_file_handle.close()
print(text)
我只想看图。我的版本是python 3.我不想导入另一个模块,所以请尝试给出使用pdfminer3的解决方案。
您需要在文本转换器中指定保存 pdf 图像的位置。尝试添加 ImageWriter..
pdfResourceManager = PDFResourceManager()
convertedText = StringIO()
layoutParams = LAParams()
imageWriter = ImageWriter('pathToSaveImages/..')
converter = TextConverter(pdfResourceManager, convertedText, codec='utf-8',laparams=layoutParams, imagewriter=imageWriter)