Skip to content

Adobe Acrobat does not render SVG #211

Description

@kyasu1

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.

printpdf/src/svg.rs

Lines 85 to 95 in ac411a8

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions