Find answers from the community

Updated 2 months ago

@Logan M was working on ```pdf_file = "

was working on
Plain Text
pdf_file = "llama2.pdf"

# Split the base name and extension
output_directory_path, _ = os.path.splitext(pdf_file)

if not os.path.exists(output_directory_path):
    os.makedirs(output_directory_path)

# Open the PDF file
pdf_document = fitz.open(pdf_file)

# Iterate through each page and convert to an image
for page_number in range(pdf_document.page_count):
    # Get the page
    page = pdf_document[page_number]

    # Convert the page to an image
    pix = page.get_pixmap()

    # Create a Pillow Image object from the pixmap
    image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)

    # Save the image
    image.save(f"./{output_directory_path}/page_{page_number + 1}.png")

# Close the PDF file
pdf_document.close()
and got error: AttributeError: module 'fitz' has no attribute 'open'
L
a
7 comments
maybe uninstall and reinstall pymupdf ?
@Logan M thougths?
Whelp, not sure. I'd be googling the same things as you lol
worked yesterday without issues, but not working today
@Logan M love to see if there is alternative
Add a reply
Sign up and join the conversation on Discord