Hi Felix,
I could not help but notice that you recently added SVG support to printpdf using my svg2pdf crate (thanks!).
Converting an SVG to a PDF often requires more than a single content stream/object. svg2pdf heavily uses the /Do operator to draw other XObjects and references many objects through the Resources dictionary of the page. printpdf currently discards all of the svg2pdf output except for the main content stream.
This means that SVGs using the features listed below will produce content streams with broken references:
- transparency of any kind, be it fill or stroke opacity or whole groups
- gradients
- patterns
- masks
- external images
- some transformed groups
- filters (e.g. blend modes) -- if I'll ever support those 😬
To fix this, printpdf would have to collect all objects in the Page's Resources dictionary and the Resources dictionary of all referenced XObjects recursively and carry them over to the target file.
In order to reproduce the bug, I converted the attached SVG to a PDF file with printpdf and a standalone svg2pdf setup. The printpdf result cannot be opened in Acrobat and only shows a solid orange rectangle in Pdfium while the svg2pdf output reproduces the output of an SVG viewer.
The original SVG (on OneDrive because GitHub does not allow the file format in issues)
The printpdf result (pardon the margins)
The svg2pdf result
Hi Felix,
I could not help but notice that you recently added SVG support to
printpdfusing mysvg2pdfcrate (thanks!).Converting an SVG to a PDF often requires more than a single content stream/object.
svg2pdfheavily uses the/Dooperator to draw other XObjects and references many objects through theResourcesdictionary of the page.printpdfcurrently discards all of thesvg2pdfoutput except for the main content stream.This means that SVGs using the features listed below will produce content streams with broken references:
To fix this,
printpdfwould have to collect all objects in thePage'sResourcesdictionary and theResourcesdictionary of all referenced XObjects recursively and carry them over to the target file.In order to reproduce the bug, I converted the attached SVG to a PDF file with
printpdfand a standalonesvg2pdfsetup. Theprintpdfresult cannot be opened in Acrobat and only shows a solid orange rectangle in Pdfium while thesvg2pdfoutput reproduces the output of an SVG viewer.The original SVG (on OneDrive because GitHub does not allow the file format in issues)
The
printpdfresult (pardon the margins)The
svg2pdfresult