alafr / SVG-to-PDFKit

Insert SVG into a PDF document created with PDFKit
MIT License
397 stars 111 forks source link

SVG is not displayed correctly when adding it to pdfmake pdf #184

Open EdoardoCroci opened 5 months ago

EdoardoCroci commented 5 months ago

I have a react project with pdfmake added by yarn, a component draws a chart (svg) using d3, I use an id to get the svg. This is how I get the svg and add it to an empty document:

const svgElement = document.getElementById('svgConcrete');
const svgString = svgElement.outerHTML;

const docDefinition = {
  content: [           
    {
      columns: [
        { width: '*', text: '' },
        {
          svg: svgString,
          width: 175,
          height: 175
        },
        { width: '*', text: '' },
      ]
    }
  ],
}

The image that should be displayed is this: WhatsApp Image 2024-03-11 at 12 03 04

The image that I get is: WhatsApp Image 2024-03-11 at 12 05 03

Why does this happen? How can I fix it?