CairoSVG icon indicating copy to clipboard operation
CairoSVG copied to clipboard

Can't convert svg to pdf

Open OnlyFart opened this issue 1 year ago • 3 comments

This file can't covert to pdf. test.svg.zip

If remove image, then convert work success

Command: cairosvg test.svg -o test.pdf

Result: OSError: [Errno cairo returned CAIRO_STATUS_READ_ERROR: b'error while reading from input stream'] 10

OS: macos Version: 2.7.1

OnlyFart avatar Jun 03 '24 10:06 OnlyFart

After a series of experiments, I found out that if execution goes along the first branch, then an error occurs. If according to the "else" branch, then everything works correctly

Снимок экрана 2024-06-03 в 16 44 06

OnlyFart avatar Jun 03 '24 13:06 OnlyFart

Hi!

With image.png corresponding to the PNG in your SVG file, I’ve tested this small C code:

#include <cairo.h>
#include <stdio.h>

int main()
{
    cairo_surface_t *surface = cairo_image_surface_create_from_png ("/tmp/image.png");
    if (cairo_surface_status(surface) == CAIRO_STATUS_READ_ERROR)
        {
            printf("read error\n");
        }
    return 0;
}

It prints read error, so the problem comes from Cairo, not CairoSVG.

Maybe this PNG is broken? Otherwise, you should report a bug to Cairo, there’s not much we can do for you here.

liZe avatar Jun 03 '24 22:06 liZe

Hi!

With image.png corresponding to the PNG in your SVG file, I’ve tested this small C code:

#include <cairo.h>
#include <stdio.h>

int main()
{
    cairo_surface_t *surface = cairo_image_surface_create_from_png ("/tmp/image.png");
    if (cairo_surface_status(surface) == CAIRO_STATUS_READ_ERROR)
        {
            printf("read error\n");
        }
    return 0;
}

It prints read error, so the problem comes from Cairo, not CairoSVG.

Maybe this PNG is broken? Otherwise, you should report a bug to Cairo, there’s not much we can do for you here.

Yes, this png is broken...

IEND header not correct image

At the same time, cairosvg is capable of dealing with this broken file if it goes along another branch)

OnlyFart avatar Jun 04 '24 07:06 OnlyFart

At the same time, cairosvg is capable of dealing with this broken file if it goes along another branch)

We wont fix this, according to the project’s philosophy that focuses on correct input.

liZe avatar May 12 '25 11:05 liZe