We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

String with multiple font using TextFragment

Hi Team,

i want to display multi colored string in a single cell of table. Example string as show below.

“hi Aspose!!” Please suggest how this can be achived.

i am using com.aspose.pdf package classes.

Thanks in advance.

Hi Ramesh,

Thanks for contacting support.

In order to accomplish your requirements, please try using following code snippet. For your reference, I have also attached the resultant file generated over my end.
com.aspose.pdf.Document pdfDocument1 = new com.aspose.pdf.Document();


// create table instance

com.aspose.pdf.Table table1 = new com.aspose.pdf.Table();

// set width of table columns

table1.setColumnWidths("100 100");

// add row to table instance

com.aspose.pdf.Row row1 = table1.getRows().add();

// create cell instance

com.aspose.pdf.Cell cell1 = row1.getCells().add();

// create TextFragment for cell1 instance

com.aspose.pdf.TextFragment textfragment = new com.aspose.pdf.TextFragment();

// create first segment instance

com.aspose.pdf.TextSegment seg1 = new com.aspose.pdf.TextSegment("hi ");

// set foreground color for first segment


// add first segment to TextFragment instance


//create first segment instance

com.aspose.pdf.TextSegment seg2 = new com.aspose.pdf.TextSegment("Aspose!!");

//set foreground color for first segment


//add first segment to TextFragment instance



// add table to paragraphs collection of first page of document


// save PDF file