Hướng dẫn convert pdf to image python opencv - chuyển đổi pdf sang hình ảnh python opencv

Bạn có thể sử dụng thư viện pdf2image. Cài đặt với lệnh này: pip install pdf2image. Sau đó, bạn có thể chuyển đổi tệp thành một hoặc nhiều hình ảnh có thể đọc được bởi CV2. Mẫu mã tiếp theo sẽ chuyển đổi hình ảnh PIL thành một cái gì đó có thể đọc được bởi CV2:

Lưu ý: Mã sau yêu cầu Numpy pip install numpy.

from pdf2image import convert_from_path
import numpy as np

images_of_pdf = convert_from_path('source2.pdf')  # Convert PDF to List of PIL Images
readable_images_of_pdf = []  # Create a list for thr for loop to put the images into
for PIL_Image in images_of_pdf:
    readable_images_of_pdf.append(np.array(PIL_Image))  # Add items to list

Bit mã tiếp theo có thể chuyển đổi PDF thành một hình ảnh lớn có thể đọc được bởi CV2:

import cv2
import numpy as np
from pdf2image import convert_from_path

image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)

Hàm convert_from_path() của thư viện PDF2Image trả về một danh sách chứa mỗi trang PDF ở định dạng hình ảnh PIL. Chúng tôi chuyển đổi danh sách thành một tuple cho hàm kết nối numpy để xếp các hình ảnh lên trên nhau. Nếu bạn muốn chúng cạnh nhau, bạn có thể thay đổi số nguyên trục thành 1 biểu thị bạn muốn kết hợp các hình ảnh dọc theo trục y. Bit mã tiếp theo này sẽ hiển thị hình ảnh trên màn hình:

cv2.imshow("Image of PDF", image_of_pdf)
cv2.waitKey(0)

Điều này có thể sẽ tạo ra một cửa sổ trên màn hình quá lớn. Để thay đổi kích thước hình ảnh cho màn hình, bạn sẽ sử dụng mã sau sử dụng chức năng thay đổi kích thước tích hợp của CV2:

import cv2
from pdf2image import convert_from_path
import numpy as np
image_of_pdf = np.concatenate(tuple(convert_from_path('source2.pdf')), axis=0)
size = 0.15 # 0.15 is equal to 15% of the original size.
resized = cv2.resize(image_of_pdf, (int(image_of_pdf.shape[:2][1] * size), int(image_of_pdf.shape[:2][0] * size)))
cv2.imshow("Image of PDF", resized)
cv2.waitKey(0)

Trên màn hình 1920x1080, kích thước 0,15 có thể thoải mái hiển thị một tài liệu 3 trang. Nhược điểm là chất lượng được giảm đáng kể. Nếu bạn muốn phân tách các trang, bạn chỉ có thể sử dụng chức năng convert_from_path() gốc. Mã sau hiển thị từng trang riêng lẻ, để chuyển sang trang tiếp theo Nhấn bất kỳ phím nào:

import cv2
from pdf2image import convert_from_path
import numpy

images_of_pdf = convert_from_path('source2.pdf')  # Convert PDF to List of PIL Images
count = 0  # Start counting which page we're on
while True:
    cv2.imshow(f"Image of PDF Page {count + 1}", numpy.array(images_of_pdf[count]))  # Display the page with it's number
    cv2.waitKey(0)  # Wait until key is pressed
    cv2.destroyWindow(f"Image of PDF Page {count + 1}")  # Destroy the following window
    count += 1  # Add to the counter by 1
    if count == len(images_of_pdf):
        break  # Break out of the while loop before you get an "IndexError: list index out of range"

Điều hướng đến trang PDF chuyển đổi trên các dịch vụ trực tuyến Acrobat ..

Nhấp vào nút Chọn tệp hoặc kéo và thả tệp vào vùng thả ..

Chọn định dạng tệp ưa thích của bạn-PNG, JPG hoặc TIFF từ menu thả xuống ..

  • Nhấp vào nút Chuyển đổi sang JPG hoặc định dạng nào bạn đã chọn ..
  • Xem thảo luận
  • Điều hướng đến trang PDF chuyển đổi trên các dịch vụ trực tuyến Acrobat ..

    Nhấp vào nút Chọn tệp hoặc kéo và thả tệp vào vùng thả ..

    Chọn định dạng tệp ưa thích của bạn-PNG, JPG hoặc TIFF từ menu thả xuống ..

    Nhấp vào nút Chuyển đổi sang JPG hoặc định dạng nào bạn đã chọn ..pdf2image and poppler.

    Xem thảo luận

    • Cải thiện bài viếtThis module converts a PDF to a PIL object. To install this module type the below command in the terminal.
    pip install pdf2image
    • Lưu bài viế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

    & 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.

    Approach:

    • Nhập mô -đun PDF2Image
    • Lưu trữ PFD với Convert_From_Path ()convert_from_path()
    • Lưu hình ảnh với Save ()save()

    Dưới đây là việc thực hiện.

    Tệp PDF được sử dụng:

    Hướng dẫn convert pdf to image python opencv - chuyển đổi pdf sang hình ảnh python opencv

    Python

    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    0
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    1
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    2
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    3

    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    4
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    6
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    7
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    8

    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    9
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    0
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    1
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    2
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    3
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    4
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    5

    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    6
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    7
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    8
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    9
    import cv2
    from pdf2image import convert_from_path
    import numpy as np
    image_of_pdf = np.concatenate(tuple(convert_from_path('source2.pdf')), axis=0)
    size = 0.15 # 0.15 is equal to 15% of the original size.
    resized = cv2.resize(image_of_pdf, (int(image_of_pdf.shape[:2][1] * size), int(image_of_pdf.shape[:2][0] * size)))
    cv2.imshow("Image of PDF", resized)
    cv2.waitKey(0)
    
    0
    import cv2
    from pdf2image import convert_from_path
    import numpy as np
    image_of_pdf = np.concatenate(tuple(convert_from_path('source2.pdf')), axis=0)
    size = 0.15 # 0.15 is equal to 15% of the original size.
    resized = cv2.resize(image_of_pdf, (int(image_of_pdf.shape[:2][1] * size), int(image_of_pdf.shape[:2][0] * size)))
    cv2.imshow("Image of PDF", resized)
    cv2.waitKey(0)
    
    1
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    9
    import cv2
    from pdf2image import convert_from_path
    import numpy as np
    image_of_pdf = np.concatenate(tuple(convert_from_path('source2.pdf')), axis=0)
    size = 0.15 # 0.15 is equal to 15% of the original size.
    resized = cv2.resize(image_of_pdf, (int(image_of_pdf.shape[:2][1] * size), int(image_of_pdf.shape[:2][0] * size)))
    cv2.imshow("Image of PDF", resized)
    cv2.waitKey(0)
    
    3
    import cv2
    from pdf2image import convert_from_path
    import numpy as np
    image_of_pdf = np.concatenate(tuple(convert_from_path('source2.pdf')), axis=0)
    size = 0.15 # 0.15 is equal to 15% of the original size.
    resized = cv2.resize(image_of_pdf, (int(image_of_pdf.shape[:2][1] * size), int(image_of_pdf.shape[:2][0] * size)))
    cv2.imshow("Image of PDF", resized)
    cv2.waitKey(0)
    
    4
    import cv2
    from pdf2image import convert_from_path
    import numpy as np
    image_of_pdf = np.concatenate(tuple(convert_from_path('source2.pdf')), axis=0)
    size = 0.15 # 0.15 is equal to 15% of the original size.
    resized = cv2.resize(image_of_pdf, (int(image_of_pdf.shape[:2][1] * size), int(image_of_pdf.shape[:2][0] * size)))
    cv2.imshow("Image of PDF", resized)
    cv2.waitKey(0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    8

    Output:

    Hướng dẫn convert pdf to image python opencv - chuyển đổi pdf sang hình ảnh python opencv

    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.This Script implements the above Implementation into a GUI.

    Dưới đây là việc thực hiện.

    Python3

    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    0
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    1
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    2
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    3

    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    4
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    6
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    7
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    8

    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    9
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    0
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    1
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    2
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    3
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    4
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    5

    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    6
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    7
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    8
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    9
    import cv2
    from pdf2image import convert_from_path
    import numpy as np
    image_of_pdf = np.concatenate(tuple(convert_from_path('source2.pdf')), axis=0)
    size = 0.15 # 0.15 is equal to 15% of the original size.
    resized = cv2.resize(image_of_pdf, (int(image_of_pdf.shape[:2][1] * size), int(image_of_pdf.shape[:2][0] * size)))
    cv2.imshow("Image of PDF", resized)
    cv2.waitKey(0)
    
    0
    import cv2
    from pdf2image import convert_from_path
    import numpy as np
    image_of_pdf = np.concatenate(tuple(convert_from_path('source2.pdf')), axis=0)
    size = 0.15 # 0.15 is equal to 15% of the original size.
    resized = cv2.resize(image_of_pdf, (int(image_of_pdf.shape[:2][1] * size), int(image_of_pdf.shape[:2][0] * size)))
    cv2.imshow("Image of PDF", resized)
    cv2.waitKey(0)
    
    1
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    9
    import cv2
    from pdf2image import convert_from_path
    import numpy as np
    image_of_pdf = np.concatenate(tuple(convert_from_path('source2.pdf')), axis=0)
    size = 0.15 # 0.15 is equal to 15% of the original size.
    resized = cv2.resize(image_of_pdf, (int(image_of_pdf.shape[:2][1] * size), int(image_of_pdf.shape[:2][0] * size)))
    cv2.imshow("Image of PDF", resized)
    cv2.waitKey(0)
    
    3
    import cv2
    from pdf2image import convert_from_path
    import numpy as np
    image_of_pdf = np.concatenate(tuple(convert_from_path('source2.pdf')), axis=0)
    size = 0.15 # 0.15 is equal to 15% of the original size.
    resized = cv2.resize(image_of_pdf, (int(image_of_pdf.shape[:2][1] * size), int(image_of_pdf.shape[:2][0] * size)))
    cv2.imshow("Image of PDF", resized)
    cv2.waitKey(0)
    
    4
    import cv2
    from pdf2image import convert_from_path
    import numpy as np
    image_of_pdf = np.concatenate(tuple(convert_from_path('source2.pdf')), axis=0)
    size = 0.15 # 0.15 is equal to 15% of the original size.
    resized = cv2.resize(image_of_pdf, (int(image_of_pdf.shape[:2][1] * size), int(image_of_pdf.shape[:2][0] * size)))
    cv2.imshow("Image of PDF", resized)
    cv2.waitKey(0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    8

    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    6
    pip install pdf2image
    2
    pip install pdf2image
    3

    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.

    pip install pdf2image
    4
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    9 pip install pdf2image2
    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    1 pip install pdf2image4

    pip install pdf2image5pip install pdf2image6pip install pdf2image7

    import cv2
    from pdf2image import convert_from_path
    import numpy as np
    image_of_pdf = np.concatenate(tuple(convert_from_path('source2.pdf')), axis=0)
    size = 0.15 # 0.15 is equal to 15% of the original size.
    resized = cv2.resize(image_of_pdf, (int(image_of_pdf.shape[:2][1] * size), int(image_of_pdf.shape[:2][0] * size)))
    cv2.imshow("Image of PDF", resized)
    cv2.waitKey(0)
    
    4
    import cv2
    from pdf2image import convert_from_path
    import numpy as np
    image_of_pdf = np.concatenate(tuple(convert_from_path('source2.pdf')), axis=0)
    size = 0.15 # 0.15 is equal to 15% of the original size.
    resized = cv2.resize(image_of_pdf, (int(image_of_pdf.shape[:2][1] * size), int(image_of_pdf.shape[:2][0] * size)))
    cv2.imshow("Image of PDF", resized)
    cv2.waitKey(0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    8

    ________ 26 ________ 72 & nbsp;

    pip install pdf2image
    3

    pip install pdf2image
    4pip install numpy5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5 pip install numpy7

    pip install pdf2image
    4pip install numpy9convert_from_path()0convert_from_path()1

    cv2.imshow("Image of PDF", image_of_pdf)
    cv2.waitKey(0)
    
    6convert_from_path()3
    pip install pdf2image
    3

    pip install pdf2image
    4pip install numpy5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5 convert_from_path()8

    pip install pdf2image
    4pip install numpy9convert_from_path()0convert_from_path()1

    convert_from_path()3

    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5 convert_from_path()5

    convert_from_path()6

    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5convert_from_path()8convert_from_path()9
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    01
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    02
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    04

    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    05
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    07

    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    08
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    01
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    11
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    13
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    8

    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    15
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    17
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    19
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    20
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    22

    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    23
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    01
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    11
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    28
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    29
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    28
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    32
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    28
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    35
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    37
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    38
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    5
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    37
    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    8

    import cv2
    import numpy as np
    from pdf2image import convert_from_path
    
    image_of_pdf = np.concatenate(tuple(convert_from_path('/path/to/pdf/source.pdf')), axis=0)
    
    42

    Output:

    Hướng dẫn convert pdf to image python opencv - chuyển đổi pdf sang hình ảnh python opencv

    Nếu không có tệp PDF tại vị trí đã cho của bạn.

    Hướng dẫn convert pdf to image python opencv - chuyển đổi pdf sang hình ảnh python opencv


    Làm cách nào để chuyển đổi tệp PDF thành hình ảnh trong Python?

    Nhiều công cụ có sẵn trên Internet để chuyển đổi PDF thành hình ảnh ...
    Nhập mô -đun PDF2Image ..
    Lưu trữ PFD với Convert_From_Path ().
    Lưu hình ảnh với Save ().

    Làm cách nào để chuyển đổi PDF thành PNG trong Python?

    Dưới đây là các bước đơn giản về cách chuyển PDF thành PNG bằng Python ...
    Đầu tiên, bạn cần cài đặt thư viện PDF2Image trên máy tính của mình bằng cách sử dụng.....
    Cài đặt gói PIL bằng cách sử dụng Gối cài đặt lệnh: PIP ..
    Từ hình ảnh nhập khẩu PIL ..
    Image1 = Image.open (r'path trong đó hình ảnh được lưu trữ \ tên tệp.png ').
    im1 = Image1.Convert ('RGB').

    CV2 có thể đọc PDF không?

    OpenCV hoàn toàn không hỗ trợ định dạng PDF, vì vậy bạn nên chuyển đổi trang PDF thành hình ảnh bằng thư viện khác., so you should convert pdf page to image using another library.

    Làm thế nào để tôi tạo một tệp PDF thành một bức tranh?

    Cách chuyển đổi bản PDF thành hình ảnh ...
    Điều hướng đến trang PDF chuyển đổi trên các dịch vụ trực tuyến Acrobat ..
    Nhấp vào nút Chọn tệp hoặc kéo và thả tệp vào vùng thả ..
    Chọn định dạng tệp ưa thích của bạn-PNG, JPG hoặc TIFF từ menu thả xuống ..
    Nhấp vào nút Chuyển đổi sang JPG hoặc định dạng nào bạn đã chọn ..