Open nukul4r opened 2 years ago
Hi, we face to exactly same problem during rendering the SVG file, when we use CSS to define a background image. I have tested it with both relative address and data-URI:
.icon-at {
background-image: url("images/flag-at.svg");
}
//////// OR ///////
.icon-at {
background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='1000' height='600' viewBox='0 0 5 3'><desc>Flag of Germany</desc><rect id='red_stripe ' width='5' height='3' y='0' x='0' fill='#ed2939'/><rect id='white_stripe' width='5' height='2' y='1' x='0' fill='#FFF'/><rect id='red_stripe2' width='5' height='1' y='2' x='0' fill='#ed2939'/></svg>");
}
Hello again,
By my last check, I have found that might be change code in AbstractOutputDevice.paintBackground0() where is checkd whether backgroundImage is GRADIENT or URI. I think it should be check again if URI contains ".svg", then draws a SVG file instead of Image.
In other words, It should create XMLResource instead of ImageResource.
I hope it was helpful. :)
Thanks @omna-manz,
SVG background images are likely to get in the next release. Stay tuned.
Thank you @danfickle, It is a great news :)
@danfickle Is there a fix for this issue?
Has anybody found a way to get this to work? Or can we come up with a PR?
See also #583.
I tried to create a PR but I'm not sure where to put the logic.
My first attempt was to add the code to the AbstractOutputDevice
, but we have no access to the Box
there.
Then I tried to use the ReplacedElementFactory
to turn the SVG into PNG and replace the url
, but that didn't seem to have an effect.
Can somebody advise?
In the meantime, my workaround is to replace the SVG data-urls with PNG data-urls in the HTML as a pre-processing step.
I am also facing the same issue with SVG binary images. They are not getting loaded. I am using docx4j-ImportXHTML (11.4.8) which is calling openhtmltopdf-core(1.0.10). Can someone please help here
In our project, we are using
PdfRendererBuilder.withW3cDocument
to convert a HTML document to PDF. In this input, we use CSS to define a background image:When the PDF is rendered, we get the following stacktrace:
When we add the SVG directly to the HTML (with
<img src="classpath:static/public/img/logo.svg"></img>
), the image is rendered correctly. To make this work, we add thecom.openhtmltopdf.svgsupport.BatikSVGDrawer
inPdfRendererBuilder.useSVGDrawer
.The cause seems to be, that the SVG drawer is not used when rendering the background.
Thanks!