yWorks / svg2pdf.js

A javascript-only SVG to PDF conversion utility that runs in the browser. Brought to you by yWorks - the diagramming experts
MIT License
646 stars 96 forks source link

SVG is upscaled in the pdf-file #231

Closed Franky-W closed 1 year ago

Franky-W commented 1 year ago

Hi, thank you for this awesome library!

I create with svgdotjs a svg-image. The problem: The svg wich is shown in the PDF-File is way to big. One PDF-Page holds approx. 1/4 of the svg-image. What can I do? What do I wrong?

HTML `

`

JS-draw funtion const template = '<rect width="690.74792" height="519.3775" ...' // holds svg-data as string const draw = SVG(document.querySelector('#drawing')) draw.svg(template)

JS-pdf function const doc = new jsPDF() const element = document.getElementById('drawing') doc.svg(element, ) .then(() => { doc.save('myPDF.pdf') })

yGuy commented 1 year ago

The svg function takes a second parameter (the one that you omitted in your last snippet) that lets you define the size of the svg in the PDF. Did you try that? See width and height options here.

Franky-W commented 1 year ago

Hello yGuy, thank you for your fast response. Yes I did, but the result is the same.

Even the code from here https://codepen.io/cl10k/project/editor/ZOjgJg dosent work for me.

Edit: vue-File attached. HelloWorld.txt

Franky-W commented 1 year ago

Found the solution. Added width, height and viewbox to the svg tag.