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 100 forks source link

Font-size in `em` unit does not work #100

Closed bernhardreiter closed 4 years ago

bernhardreiter commented 5 years ago

When using the unit em to specify a font size, the result is much smaller as expected. For example font-size="2em"

Expectation: Display similar to the browser.

bernhardreiter commented 5 years ago

Example (place file ast test100.html in ./dist after building and copying jspdf.debug.js.)

<svg id="svg" width="100%" height="100%">
  <g class="main" transform="translate(30, 20)">                                
    <g fill="none" font-size="10" text-anchor="start">                          
      <g opacity="1" transform="translate(0,40)">                               
        <text fill="black" x="-25">3.50</text>                                  
      </g>                                                                      
      <g opacity="1" font-size="2em" transform="translate(0,10)">               
        <text fill="black" x="-25">5.00</text>                                  
      </g>                                                                      
    </g>                                                                        
  </g>                                                                          
</svg>                                                                          
<script src="./jspdf.debug.js"></script>                                        
<script src="./svg2pdf.js"></script>                                            

<script type="text/javascript">
    const svgElement = document.getElementsByTagName('svg')[0];
    const width = 200, height = 100;
    const pdf = new jsPDF('l', 'pt', [width, height]);
    svg2pdf(svgElement, pdf, {
        xOffset: 0,
        yOffset: 0,
        scale: 1
    });
    pdf.save('myPDF.pdf');
</script>

Screenshot from Chromium 73.0.3683.75 built on Debian 9.8, running on Debian 9.9 test100-browser

resulting PDF test100-bad.pdf

Using svg2pdf 9a3ff91e0a50b2e6b6d5c7e7445e954e1a280bb0 (master) Date: Fri Jun 28 15:00:39 2019 +0200