Closed facuescobar closed 3 years ago
Please post the SVG here: http://raw.githack.com/yWorks/svg2pdf.js/master/ as described in the issue template. That's almost definitely a problem with the SVG and if you don't post it, we cannot help. I could send you a PDF that has your shape, but that would not be helpful, either, or would it? ;-)
Thanks for your quick response @yGuy, sorry I've missed that part
Here's the SVG
Huh? But it does work in the link, doesn't it?
Please check how your code differs from our demo.
Yes, as you can see, the SVG works in the demo viewer, but it doesn't work in my code.
Do you think it could be a problem related to svgOptions or something? I've tried exporting it without svgOptions but it doesn't work either.
Thanks for your suggestion @yGuy
I've updated my code following the demo version, and the SVG is being exported now
// Convert SVG string to HTML element
const svgWrapperElement = document.getElementById('svg-wrapper')
svgWrapperElement.innerHTML = window.svg
const svgElement = svgWrapperElement.firstChild
// Force layout calculation
svgElement.getBoundingClientRect()
const width = svgElement.width.baseVal.value
const height = svgElement.height.baseVal.value
// eslint-disable-next-line
const pdf = new jsPDF(width > height ? 'l' : 'p', 'pt', [
width,
height,
])
const svgOptions = { width, height }
pdf.svg(svgElement, svgOptions).then(() => {
pdf.save('svg.pdf')
})
Describe the bug The SVG content is not exported in PDF file
I'm able to generate the SVG content and display it as an HTML element in DOM. But When I export the PDF file, the SVG content is not included, the PDF content is empty.
Code
Svg http://raw.githack.com/yWorks/svg2pdf.js/master/?svg=...
Screenshots SVG Element in DOM
Exported PDF
Desktop (please complete the following information):