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

custom fonts in jspdf take effect but not for svg #199

Closed zhyale closed 2 years ago

zhyale commented 2 years ago

I have created a custom Chinese font MiSans-Normal for jsPDF, and test OK for jspdf.text() , but Chinese characters are still messy code in jspdf.svg( ) . I am not sure whether it is a bug, or any option need to be configured, can you help me, thank you :)

carwestsam commented 2 years ago

try add font-family in svg, and it will use fonts defines in jsPDF

<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
        <style>
            text {
                font-family: MiSan-Normal;
            };
        </style> 
            <text > 文字 </text>
 </svg>
zhyale commented 2 years ago

try add font-family in svg, and it will use fonts defines in jsPDF

<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
        <style>
            text {
                font-family: MiSan-Normal;
            };
        </style> 
            <text > 文字 </text>
 </svg>

Thank you very much, it works now :)

rafh commented 2 years ago

@zhyale I ran into the same issue and switched over to svg2pdf. However, I'm not able to get the correct fonts passed to my svg. Do you have an example of how you accomplished this task?