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
649 stars 98 forks source link

Support for units #154

Open HackbrettXXX opened 3 years ago

HackbrettXXX commented 3 years ago

Currently, svg2pdf does not support units (except for some rare exceptions) and treats every dimension value as in PDF units. The PDF unit is specified in the jsPDF constructor (e.g. new jsPDF({ unit: "mm" })).

We should really support different units.

Resources:

In order to implement this, we should add a method to the Context class that converts a dimension value with unit into a unit-less dimension value. For relative dimensions there is already a viewPort property on the Context with the current viewport.

In order to implement units by specification, we should also factor out the PDF unit/scaleFactor, meaning we need to

We can combine these factors to a matrix that is applied once "around everything" in the svg2pdf method.

After this we can replace/remove the toPixels method in the utils/misc file.