printpdf icon indicating copy to clipboard operation
printpdf copied to clipboard

Adobe Acrobat does not render SVG

Open kyasu1 opened this issue 10 months ago • 1 comments

Adobe Acrobat does not render and complains with the following error if we open svg_example.pdf generated by example/svg.rs, though browsers render it.

Screenshot 2025-03-20 at 23 09 10

As far as I have investigated, this is caused by the following ColorSpace resource being defined incorrectly.

https://github.com/fschutt/printpdf/blob/ac411a8ef7b30ea20924c258d655d5baefd9ec45/src/svg.rs#L85-L95

It should be defined something like below.

https://github.com/kyasu1/printpdf/blob/2cca445ddbcb672a0f8d75e9cb717431f11ca644/src/svg.rs#L85-L102

            (
                "Resources",
                DictItem::Dict {
                    map: [(
                        "ColorSpace".to_string(),
                        DictItem::Dict {
                            map: [(
                                "cs0".to_string(),
                                DictItem::Name(ColorSpace::Rgb.as_string().into()),
                            )]
                            .into_iter()
                            .collect(),
                        },
                    )]
                    .into_iter()
                    .collect(),
                },
            ),

With this modification, the pdf is rendered as expected.

Screenshot 2025-03-20 at 23 09 45

However, the error dialog is still shown. It is caused by the camera svg which contains unsupportedPattern and Shading resources. Supporting them is another story.

Anyway, hardcoding the name cs0 is not the correct approach. Instead, we need to figure out how to look up all ColorSpaces defined in the PDF file.

kyasu1 avatar Mar 20 '25 15:03 kyasu1

Yeah, I didn't want to do proper color management for this release.

fschutt avatar Mar 20 '25 15:03 fschutt