Kozea / CairoSVG

Convert your vector images
https://courtbouillon.org/cairosvg
GNU Lesser General Public License v3.0
773 stars 151 forks source link

Can't convert svg to pdf #425

Open OnlyFart opened 5 months ago

OnlyFart commented 5 months ago

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 commented 5 months ago

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
liZe commented 5 months ago

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.

OnlyFart commented 5 months ago

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)