Multiple text format in single tablecell

Dear all,

I'm new to syncfusion PDF and i'm trying to create some complex PdfTables. Within a sinlge PDF Table Cell, i want to have text with different formatting like bold, underline, another font and fontsize, etc.. I read a lot of documentation and found that I should use the BeginCellLayout event. However, a lot a things remain unclear to me. It is not clear how i can draw multiple strings after one another with also wordwrapping etc. In the image bellow you can see an example I've created in word to demonstrate my need.

Thanks in advance for your help.


2022-02-14-002.png


4 Replies

SV Surya Venkatesan Syncfusion Team February 15, 2022 07:02 PM UTC

Hi Tom,


We have created a sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/PDF_SAmple_GridWithMultiFonts312796388
to add multiple fonts text in a PDF table cell. Kindly try it on your end and let us know the result.


Regards,

Surya V



TO Tom February 15, 2022 07:14 PM UTC

Hi Surya,

First of all I would like to thank you for taking time to take a look at my issue I've adressed. I had a look at the provided sample and output and it is not exactly what I'm looking for.

Let me clarrify: the provided sample indeed shows me a cell with multi-formatted text, which is great. However, each text with it's own font/format is printed on a seperate line. What I'm looking for is continous text with different formatting like in the example above. it is unclear to me how I can achive that.



GK Gowthamraj Kumar Syncfusion Team February 16, 2022 02:19 PM UTC

Hi Tom, 

Currently, we are analyzing on your requirement in our end and we will update the further details on February 18th 2022. 
 
Regards, 
Gowthamraj K 



SV Surya Venkatesan Syncfusion Team replied to Tom February 18, 2022 07:45 PM UTC

Hi Tom,


Kindly try with the below code snippet to achieve your requirement of multiple text format in a single Grid cell,

//Create PDF document

            PdfDocument doc = new PdfDocument();

 

            //Add pages

            PdfPage page = doc.Pages.Add();

 

            //Create PdfGrid

            PdfGrid grid = new PdfGrid();

 

            //Add PdfGridRow

            PdfGridRow row = grid.Rows.Add();

 

            //Add 2 column

            grid.Columns.Add(2);

 

            row.Cells[0].Value = "1";

            row.Cells[1].Value = "2";

 

            row = grid.Rows.Add();

 

            string longText = "<font color='#FF0000'>Essential PDF</font> is a <U>.NET</U>" +

 

             "<I> library with the capability to produce Adobe PDF files</I>";

 

            PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);

 

            //Create PdfHtmlTextElement

            PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(longText, font, PdfBrushes.Black);

            row.Cells[0].Value = "Hello World";

            row.Cells[1].Value = richTextElement;

 

            // Draw PdfGrid

            grid.Draw(page.Graphics, new PointF(0, 0));

 

            //Creating the stream object

 

            MemoryStream stream = new MemoryStream();

 

            //Save the PDF document to stream

 

            doc.Save(stream);


Refer to the following link to get more details on this, https://www.syncfusion.com/kb/5831/how-to-add-formatted-html-tag-in-pdfgridcell


Regards,

Surya V


Loader.
Up arrow icon