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

Garbled text that ends with "..." #85

Closed scottctr closed 5 years ago

scottctr commented 5 years ago

I've got several text elements that I've truncated and added "..." so it will fit into the allotted space with an indication of the truncation. The text appears fine in the graph component, but comes out garbled in the PDF. I'm using the latest version of svg2pdf (1.3.4) and jsPdf-yworks (2.0.2). This issue seems to only occur with text I've truncated and added the dots.

PDF image

Graph image

SVG from Graph <text transform="translate(0 45)" fill="#333333" font-family="'Arial'" font-size="10px" font-style="normal" font-weight="normal"><tspan dy="1.1em" x="75" text-anchor="middle">Korea (Democratic People's…</tspan></text>

HackbrettXXX commented 5 years ago

The reason is the character, which is not part of the "native" Helvetica font (which is used as backup for Arial). To resolve this issue you need to embed a font that supports this Unicode character. See the readme of jsPDF on how to do this.

scottctr commented 5 years ago

I got this to work, but had to use this instead. Also had to add jsPdf.setFont('Arial'), but not sure why I had to set the font since it's set correctly in the SVG. Is it because there's an extra set of quotes around "'Arial'" (see SVG above)? That text element is being generated by TextRenderSupport.addText(...).

HackbrettXXX commented 5 years ago

That's curious. I cannot reproduce it. The quotes should make no difference. Could you send me the font file you are using?

scottctr commented 5 years ago

Font file attached -- thanks! arial-normal.zip

HackbrettXXX commented 5 years ago

Your font file works for me. Did you maybe load the scripts in the wrong order? The font file needs to be loaded after jsPDF. Otherwise the jsPdf-API is undefined.

scottctr commented 5 years ago

You're correct about loading the scripts out of order -- thanks!