반응형
[python] pdf to png, 해상도 높게 저장하기
import fitz # PyMuPDF
def pdf_to_png(pdf_file, output_folder, dpi=300):
# Open the PDF file
pdf_document = fitz.open(pdf_file)
for page_number in range(pdf_document.page_count):
# Get the page
page = pdf_document[page_number]
# Set the resolution (DPI)
zoom = dpi / 72.0
mat = fitz.Matrix(zoom, zoom)
image = page.get_pixmap(matrix=mat)
# Save the image as a PNG file
image.save(f"{output_folder}/page_{page_number + 1}.png", "png")
# Close the PDF file
pdf_document.close()
if __name__ == "__main__":
input_pdf = "input.pdf" # Replace with your PDF file path
output_folder = "output_images" # Replace with your output folder
dpi = 600 # Adjust DPI as needed
pdf_to_png(input_pdf, output_folder, dpi)
반응형
'프로그래밍 > Python' 카테고리의 다른 글
[python] PyAudio (0) | 2023.10.20 |
---|---|
[Python] savefig 0.0.4 (0) | 2023.10.17 |
[python] matrix 3.0.0 (0) | 2023.10.04 |
[python] 알고리즘 - 탐색 (0) | 2023.09.27 |
[python] 알고리즘 - 정렬 (0) | 2023.09.27 |