![](/img/trans.png)
[英]split a multiple page pdf with multiple pages to individual pdfs based on a string and save using that string python
[英]Trying to loop through multiple PDF files and save the individual pages of those PDF as images
我正在研究一個 python 項目,該項目需要我一個接一個地遍歷存儲在當前目錄的 sample/ 文件夾中的多個 pdf,並將這些 pdf 的各個頁面作為圖像保存在另一個名為 convert_images/ 的目錄中。 有人能幫我嗎? 所有 pdf 文件都是隨機命名的,但具有“.pdf”擴展名。
你可以用pdf2image
pip install pdf2image
from pdf2image import convert_from_path
pages = convert_from_path('pdf_file', 500)
for page in pages:
page.save('out.jpg', 'JPEG')
或者:
import pypdfium2 as pdfium
pdffile = 'path/to/your_doc.pdf'
# render multiple pages concurrently (in this case: all)
for image, suffix in pdfium.render_pdf(pdffile):
image.save(f'output_{suffix}.jpg')
# render a single page (in this case: the first one)
with pdfium.PdfContext(pdffile) as pdf:
image = pdfium.render_page(pdf, 0)
image.save('output.jpg')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.