Free Support Forum - aspose.com

Use two fonts in one table cell | Aspose.PDF for .NET | Default font is not working

i need show two fonts in a single cell, i use two TextFragment and set the font,it’s ok。
but If I set the default font(row or table),it will not work.
image.png (25.1 KB)

public void CreateDemo(string savepath)
{
Font FontA = FontRepository.FindFont(“SimSun”);
Font FontB = FontRepository.OpenFont(@“d:\SpecialFont.ttf”);

Document doc = new Document();
Page page = doc.Pages.Add();

Aspose.Pdf.Table tabcontent = new Aspose.Pdf.Table();
page.Paragraphs.Add(tabcontent);

tabcontent.ColumnWidths = "200";
tabcontent.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
tabcontent.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1F);
Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo(5,5,5,5);
tabcontent.DefaultCellPadding = margin;
        
//first row
var row = tabcontent.Rows.Add();
var cell = new Cell();
var sptxt = new TextFragment("页面Page");
sptxt.TextState.Font = FontA;
cell.Paragraphs.Add(sptxt);
row.Cells.Add(cell);

//second row
var row2 = tabcontent.Rows.Add();
var cell2 = new Cell();
var sptxt2 = new TextFragment("");
sptxt2.TextState.Font = FontB;
cell2.Paragraphs.Add(sptxt2);
row2.Cells.Add(cell2);

//third row
var row3 = tabcontent.Rows.Add();
var cell3 = new Cell();
sptxt = new TextFragment("页面Page");
sptxt2 = new TextFragment("");
sptxt.TextState.Font = FontA;
sptxt2.TextState.Font = FontB;
sptxt2.IsInLineParagraph = true;
cell3.Paragraphs.Add(sptxt);
cell3.Paragraphs.Add(sptxt2);
row3.Cells.Add(cell3);

//if set the default font,it will not work
//cell3.DefaultCellTextState.Font = FontA;
//row3.DefaultCellTextState.Font = FontA;
//tabcontent.DefaultCellTextState.Font = FontA;
doc.Save(savepath);

}

@epepep

Would you kindly share the other font file which you are using from a file path. Also, please share which language character are you adding inside table cell. We will test the scenario in our environment and address it accordingly.

@asad.ali
some characters is self made characters, created by windows tool(c:\windows\system32\eudcedit.exe).
SpecialFont.zip (11.7 KB)

@epepep

We were still unable to notice the issue in our environment while testing the scenario with Aspose.PDF for .NET 21.2. Would you kindly share the special random characters that you created using the Windows Tool. You can add them into a file and share that file in .zip format with us. This would help us testing the scenario accordingly.

@asad.ali
CreatePdf.zip (845 Bytes)
in vs2019,These characters are shown blank,It doesn’t matter
image.png (4.2 KB)
in notepad,it’s ok
image.png (31.3 KB)

@epepep

We apologize for the inconvenience being faced. But we were still unable to notice the issue. Would you please share the PDF file where special character text is added correctly and the other file where they are appearing as blocks if font is set as default font. We will further proceed accordingly.