Kendo pdf export issue - PNG export doesn't have SVG background image and doesn't respect font face

1 Answer 187 Views
PDF Export
Kamil
Top achievements
Rank 1
Kamil asked on 07 Jun 2023, 12:14 PM

Hi

I have simple page

<kendo-pdf-export #svgPrint>
<svg width="600" height="450" style="background-color: white">>
<defs>
<pattern id="colorBack" x="0" y="0" width="600" height="400" viewBox="0 0 600 400"
preserveAspectRatio="xMidYMax slice" patternUnits="userSpaceOnUse">
<image xlink:href="assets/anthrazit.png"></image>
</pattern>
</defs>
<rect class="profile" x="0" y="0" width="600" height="400" fill="url(#colorBack)" stroke="#555E5E"></rect>
<text fill="gray" class="dimensions-text" x="0" y="420" text-anchor="start"> 5890 </text>
</svg>
</kendo-pdf-export>

 

I see in a browser this:

But in exported PNG file, there is no background and there is default font instead of specified in css:

 

i created also a div with paragraph and it works fine.

<kendo-pdf-export #divPrint style="background-color: white; width: 600px; height: 450px;">
<div style="width: 600px; height: 400px; background-image: url('assets/anthrazit.png');">
&nbsp;
</div>
<p class="dimensions-text"> 5890 </p>
</kendo-pdf-export>

 

I attached example app with issue reproduction.

--

Best regards

Kamil Paszkiewicz

1 Answer, 1 is accepted

Sort by
0
Yanmario
Telerik team
answered on 12 Jun 2023, 07:22 AM | edited on 12 Jun 2023, 07:23 AM

Hi Kamil,

Thank you for the provided example and context. That helps us to understand the issue at hand and provide a more precise response in return.

There are some limits to the PDF Export component using external images inside the svg element. In this specific use case, the developer might need to convert the image to base64 data URI and load it inside the svg element. I've managed to convert the image and will share the same example as the base64 string is quite big. 

I hope the provided information was helpful to resolve the issue.

Regards,
Yanmario
Progress Telerik

As of R2 2023, the default icon type will be SVG instead of Font. See this blogpost for more information.
Kamil
Top achievements
Rank 1
commented on 12 Jun 2023, 12:43 PM

Thank you for your answer. 

Background loaded as BASE64 works fine and it is quite good solution in my project.

But what about font in <text> tag?

 

--

Best regards

Kamil Paszkiewicz

Yanmario
Telerik team
commented on 15 Jun 2023, 07:30 AM

Hi Kamil,

I'm glad to hear that the BASE64 solution proved to be useful. When it comes to styling related to SVG image exporting, it can be a bit challenging. To ensure proper styling, it is necessary to include a style element that specifies the font to be used within the SVG. This will help maintain consistent and accurate rendering of the SVG image.

Here is an updated version that works on my side with the shared example:

<kendo-pdf-export #svgPrint [imageResolution]="150">
  <svg width="620" height="460" style="background-color: white">>
    <style>
        .foo {
          font: italic 15px Dimensions;
        }
      </style>
    <defs>
      <pattern id="colorBack" x="0" y="0" width="600" height="400" viewBox="0 0 600 400"
        preserveAspectRatio="xMidYMax slice" patternUnits="userSpaceOnUse">
        
      </pattern>
    </defs>
    <rect class="profile" x="10" y="10" width="600" height="400" fill="url(#colorBack)" stroke="#555E5E"></rect>
    <text fill="gray" class="foo" x="10" y="440" text-anchor="start"> 5890 </text>
  </svg>
  
</kendo-pdf-export>

Regards,
Yanmario
Progress Telerik     

Kamil
Top achievements
Rank 1
commented on 15 Jun 2023, 09:00 AM

Thank you very much, works great :-)

BR

Kamil

Tags
PDF Export
Asked by
Kamil
Top achievements
Rank 1
Answers by
Yanmario
Telerik team
Share this question
or