PyMuPDF icon indicating copy to clipboard operation
PyMuPDF copied to clipboard

PDF's 45º lines dissapearing in png conversion

Open gabrielbeneli-missler opened this issue 1 year ago • 3 comments

Description of the bug

Hello,

I'm using the following function to convert PDF files into PNG:

        pix = page.get_pixmap(matrix=fitz.Matrix(40, 40),alpha=False,colorspace=fitz.csGRAY)
        pix.save(image_path, "png")

The conversion occurs as expected but every 45º line dissapears:

image

How to reproduce the bug

Using this function to convert the attached PDF.

def convert_pdf_to_images(pdf_path, output_folder):
    """
    Convert a multiple page PDF into single PNG files

    - pdf_path (str): A string containning the path for the PDF to be converted.
    - output_folder (str): A string containning the path for the folder to dump the images.

    """
    doc = fitz.open(pdf_path)

    for page_num in range(len(doc)):
        page = doc[page_num]
        pagenumiter = ('00000' + str(page_num + 1))[-5:]
        image_name = f"page_{pagenumiter}.png"
        image_path = f"{output_folder}/{image_name}"

        # Convert the PDF page to an image
        pix = page.get_pixmap(matrix=fitz.Matrix(40, 40),alpha=False,colorspace=fitz.csGRAY)
        pix.save(image_path, "png")

        print(f"Converted page {page_num + 1} to {image_path}")

    doc.close()

image

test.pdf

PyMuPDF version

1.23.22

Operating system

Windows

Python version

3.11

gabrielbeneli-missler avatar Feb 16 '24 14:02 gabrielbeneli-missler

This is an issue in the base library. I will submit a bug report in their system.

Here is the issue reference at MuPDF's system: https://bugs.ghostscript.com/show_bug.cgi?id=707590.

JorjMcKie avatar Feb 16 '24 14:02 JorjMcKie

@JorjMcKie thank you for your help!

gabrielbeneli-missler avatar Feb 16 '24 16:02 gabrielbeneli-missler

The MuPDF team has already developed a fix, which will be integrated in one of our next PyMuPDF releases.

JorjMcKie avatar Feb 17 '24 07:02 JorjMcKie

Fixed in 1.24.0.