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
654 stars 101 forks source link

Different text alignment and font style in PDF #54

Closed daiger14 closed 6 years ago

daiger14 commented 6 years ago

Hello. Text in generated pdf doesn't have alignment and font size like in original svg. Code: const doc = new jsPDF(); result.forEach((page) => { svg2pdf(page, doc, { xOffset: 0, yOffset: 0, scale: 0.39, }); doc.addPage(); }); Example: Original svg image PDF image PDF generated from canvas (convert svg to image and draw in canvas) image Maybe I did something wrong? Or need to add some settings to pdf? Tried this simple code to check if will be some difference, nothing has changed. doc.setFont('helvetica'); doc.setFontType('bold'); doc.setFontSize(20); Thanks.

HackbrettXXX commented 6 years ago

Could you provide us with an SVG sample that reproduces this issue? Which version of svg2pdf and jsPDF are you using?

daiger14 commented 6 years ago

SVG sample https://pastebin.com/tBCLpWc7

$ npm view jspdf-yworks version 1.3.2

$ npm view svg2pdf.js version 1.2.1

HackbrettXXX commented 6 years ago

This is not a bug of svg2pdf. You need to set the unit of jsPDF to "pt":

const doc = new jsPDF({
  unit: "pt"
})

The reason is that font-sizes are always given in points, whereas all other measures are given in the unit passed to the constructor (default: "mm").