@gwert
Thank you for getting back to us.
We are pleased to inform you that PDFNET-46449 has been marked as resolved for Aspose.PDF for .NET 19.8 which will tentatively be released around first week of August 2019.
Once it is released, you will be able to specify ReplacementFont property in textsegment.TextEditOptions. The specified font will be used (if accessible) in the case where specified TextState.Font can not display segment text.
segment.TextEditOptions = new TextEditOptions(TextEditOptions.NoCharacterAction.UseCustomReplacementFont)
{
ReplacementFont = FontRepository.FindFont("ArialUnicodeMS")
};
We have used the following code for testing:
//open
Document document = new Document(inFile);
//update
for (int i = 1; i <= document.Pages.Count; i++)
{
Page page = document.Pages[i];
//page margins need to be updated as well, otherwise the header will be truncated
page.PageInfo.Margin.Right = 30;
page.PageInfo.Margin.Left = 30;
//prepare header of PDF page
HeaderFooter pageHeader = new HeaderFooter
{
Margin = new MarginInfo(30, 0, 30, 20)
};
double headerWidth = page.Rect.Width - 60;
#region Build table in header
//create table in header
Table table = new Table
{
Left = 0,
Top = 0,
ColumnWidths = headerWidth.ToString(System.Globalization.CultureInfo.InvariantCulture),
DefaultCellBorder =
new BorderInfo(
BorderSide.All,
0.1F,
Color.FromRgb(System.Drawing.ColorTranslator.FromHtml("#d3d3d3"))),
Margin = new MarginInfo
{
Top = 0f,
Left = 0f,
Bottom = 0f,
Right = 0f
}
};
Table rowTable = new Table
{
Left = 0,
Top = 0,
DefaultCellBorder =
new BorderInfo(
BorderSide.Left,
0.1F,
Color.FromRgb(System.Drawing.ColorTranslator.FromHtml("#d3d3d3"))),
DefaultCellPadding = new MarginInfo
{
Top = 2f,
Left = 2f,
Bottom = 2f,
Right = 2f
}
};
Row row = rowTable.Rows.Add();
TextSegment segment = new TextSegment("08 包括打印出来的与 LandscapePortrait")
{
TextState = new TextState
{
FontStyle = FontStyles.Regular,
FontSize = 12,
Font = FontRepository.FindFont("Times New Roman")
}
};
double cellWidth = segment.Rectangle.Width + 5;
rowTable.ColumnWidths = $"{(int)(headerWidth - cellWidth)} {(int)cellWidth}";
Cell cell1 = row.Cells.Add();
cell1.Alignment = HorizontalAlignment.Center;
TextState textState = new TextState
{
FontSize = 12,
HorizontalAlignment = cell1.Alignment,
Font = FontRepository.FindFont("Times New Roman")
};
TextFragment textFragment1 = new TextFragment();
textFragment1.Segments.Add(new TextSegment("Cell 1 data in Latin chars")
{
TextState = textState
});
cell1.Paragraphs.Add(textFragment1);
Cell cell2 = row.Cells.Add();
cell2.Alignment = HorizontalAlignment.Center;
TextFragment textFragment2 = new TextFragment();
segment = new TextSegment("08 包括打印出来的与 LandscapePortrait")
{
TextState = textState
};
segment.TextEditOptions = new TextEditOptions(TextEditOptions.NoCharacterAction.UseCustomReplacementFont)
{
ReplacementFont = FontRepository.FindFont("ArialUnicodeMS")
};
textFragment2.Segments.Add(segment);
cell2.Paragraphs.Add(textFragment2);
table.Rows.Add().Cells.Add().Paragraphs.Add(rowTable);
#endregion
pageHeader.Paragraphs.Add(table);
page.Header = pageHeader;
page.FreeMemory();
}
document.Save(outFile);
We have also attached generated PDF document for your kind reference 46449_fixed.pdf. We will notify you as soon as upcoming version will be released.