Export RichText GridCell to PDF

Is it possible to convert a RichText (HTML) GridCell on ExportToPDF so it's formatted with the appropriate styling in the PDF grid that's generated?

I found this tutorial on how to export a RichText control to PDF in its entirety (https://blog.syncfusion.com/blogs/post/export-blazor-rich-text-editor-to-pdf.aspx ), but that's not quite what I'm looking for when it comes to the built in PDF export functionality of a Syncfusion Blazor sfGrid.

Thanks.


3 Replies

SP Sarveswaran Palani Syncfusion Team December 1, 2023 02:51 AM UTC

Hi Riley,


Greetings from Syncfusion Support.

From your query, we suspect that you want to export the templated column. So that, we suggest you to use PDFQueryCellInfoEvent method. This method is used to export the templated columns of the DataGrid by defining the IncludeTemplateColumn of PDFExportProperties as true. We have already discussed this topic in our UG documentation. Kindly refer the shared documentation link.


Reference : https://blazor.syncfusion.com/documentation/datagrid/pdf-export#export-template-columns


If you have any further  queries, please get back to us.


Regards,

Sarvesh



RG Riley Grant February 2, 2024 02:09 AM UTC

I understand how to export the template, but how do you convert the HTML format value of a RichTextField to display properly in the PDF export?

For example, RTF fields store values in a format that contains HTML tags -

<p><strong>TEST</strong></p>

I don't want to display the HTML tags. I want them to be formatted to show TEST as bold in the exported cell.


I would have hoped that something like this might work, but it doesn't:

if (args.Column.Field == "RichTextDescription") 
{
    args.Cell.Value = new HtmlString(args.Data.DocumentDescription);

}


The example you provided does not take into consideration richtext values, nor does it provide an example on how to handle them properly when exporting to PDF.



SP Sarveswaran Palani Syncfusion Team February 7, 2024 03:39 AM UTC

Hi Riley,

From your query, we suspect that you want to export HTML format values to normal values without having HTML tags. We have achieved your requirement using below approach. Kindly refer the attached sample and code snippet for your reference.

public void PdfQueryCellInfoHandler(PdfQueryCellInfoEventArgs<Order> args)

{

     if (args.Column.Field == "CustomerID")

     {

         args.Cell.Value = "Mr." + args.Data.CustomerID;

     }

     if (args.Column.Field == "RichTextDescription")

     {

         args.Cell.Value = StripHtmlTags(args.Data.RichTextDescription);

     }

}

 

private string StripHtmlTags(string html)

{

     return Regex.Replace(html, "<.*?>", String.Empty);

}


If you have any further queries, please get back to us.

Regards,
Sarvesh


Attachment: SfGridPDF_Export_6d05e6fa.zip

Loader.
Up arrow icon