Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọcpdf2image and poppler.
Bàn luận
- Nhiều công cụ có sẵn trên Internet để chuyển đổi PDF thành hình ảnh. Trong bài viết này, chúng tôi sẽ viết mã để chuyển đổi PDF thành hình ảnh và tạo một ứng dụng tiện dụng trong Python. Trước khi viết mã, chúng tôi cần cài đặt mô -đun cần thiết PDF2IMAGE và POPPLER.This module converts a PDF to a PIL object. To install this module type the below command in the terminal.
pip install pdf2image
- Các mô -đun cần thiếtThis module allows to read, render, or modify PDF documents. Windows users will have to build or download poppler for Windows. click here to download
PDF2IMAGE 1.14.0: Mô -đun này chuyển đổi PDF thành đối tượng PIL. Để cài đặt mô -đun này, loại lệnh dưới đây trong thiết bị đầu cuối.
Poppler: Mô -đun này cho phép đọc, kết xuất hoặc sửa đổi các tài liệu PDF. Người dùng Windows sẽ phải xây dựng hoặc tải xuống Poppler cho Windows. nhấn vào đây để tai
Approach:
- & nbsp; sau đó bạn sẽ phải thêm thùng/ thư mục vào đường dẫn hoặc sử dụng
- & nbsp; poppler_pmer = r triệt C: \ path \ to \ poppler-xx \ bin Hồi như một đối số trong Convert_from_path.convert_from_path[]
- Nhập mô -đun PDF2Imagesave[]
Lưu trữ PFD với Convert_From_Path []
Lưu hình ảnh với Save []
Dưới đây là việc thực hiện.
Tệp PDF được sử dụng:
Python
from
pdf2image
import
convert_from_path
images
=
convert_from_path[
'example.pdf'
Output:
from
0 from
1from
2 from
3from
4from
5from
6This Script implements the above Implementation into a GUI.
Lưu trữ PFD với Convert_From_Path []
Python3
Tệp PDF được sử dụng:
Python
from
pdf2image
import
convert_from_path
images
=
convert_from_path[
'example.pdf'
from
7convert_from_path
3convert_from_path
4
from
0 from
1from
2 from
3from
4from
5from
6
from
7from
8from
9pdf2image
0 pdf2image
1pdf2image
222
Hãy để mã viết mã cho ứng dụng bằng cách sử dụng Tkinter: Tập lệnh này thực hiện việc triển khai ở trên thành GUI.
from
import
3import
import
5
from
import
3import
import
9
convert_from_path
5convert_from_path[
0convert_from_path[
1convert_from_path[
2
from
7convert_from_path[
4convert_from_path
4
convert_from_path
0 convert_from_path
1
convert_from_path
5convert_from_path[
0convert_from_path[
1convert_from_path[
2
convert_from_path
5images
=
convert_from_path[
pdf2image
1images
0
'example.pdf'
7=
'example.pdf'
9]
0=
]
2]
3=
]
5
convert_from_path
5from
0 images
3from
2 images
5
]
9=
]
2from
02=
from
04]
images
6images
7images
8pdf2image
5pdf2image
6]
from
14=
]
2from
02=
from
19from
20=
from
19from
23=
from
19from
26=
from
28from
29=
from
28]
from
33
Output:
________ 17 ________ 63 & nbsp; convert_from_path
4