Domanda

I have a Bezier curve defined in SVG that I'd like to draw using jsPDF. I haven't been able to get the curve to render correctly using jsPDF. How do I draw the Bezier curve defined in the SVG below using jsPDF?

The curve in SVG:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="192" version="1.1" height="288">
    <path fill="black" stroke="black" d="M19.0544,25.8288C24.2384,43.2816,22.3952,46.9968,18.7376,50.510400000000004" stroke-width="0" font=" 10pt Arial"></path>
</svg>

My attempt at the curve using jsPDF:

var doc = new jsPDF();
doc.lines([[24.2384, 43.2816, 22.3952, 46.9968, 18.7376, 50.5104]], null, null, [1, 1], 'FD');

What the SVG produces when rendered (left) and what my jsPDF code produces (right):

enter image description here enter image description here

È stato utile?

Soluzione

I don't see the initial move reflected in your code. According to my reading of the documentation, shouldn't this be something more like the following?

var doc = new jsPDF();
doc.lines([[24.2384, 43.2816, 22.3952, 46.9968, 18.7376, 50.5104]], 19.0544,25.8288, [1, 1]);

Update

Didn't notice the docs say coords are relative (thanks Pomax), so try this.

var doc = new jsPDF();
var x = 19.0544;
var y = 25.8288;
doc.lines([[24.2384-x, 43.2816-y, 22.3952-x, 46.9968-y, 18.7376-x, 50.5104-y]], x,y, [1, 1]);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top