I tried to change the format of the selected text,
When I save to pdf or docx,
The font size is changed, but the text format has not changed.
- Code: Select all
Spire.Doc.Document docX = new Spire.Doc.Document("test.docx");
TextSelection[] selections = docX.FindAllString("うえお", true, false);
if (selections == null) throw new Exception("can not find text");
foreach (TextSelection selection in selections)
{
TextRange range = selection.GetAsOneRange();
range.CharacterFormat.FontName = "ABCDE";
range.CharacterFormat.FontSize = 36;
}
string fontPath = Path.Combine(Application.StartupPath, "KTEGAKI.ttf");
if (!System.IO.File.Exists(fontPath)) throw new Exception("can not find font file!");
docX.EmbedFontsInFile = true;
docX.PrivateFontList.Add(new PrivateFontPath("ABCDE", fontPath));
docX.SaveToFile("text.pdf", Spire.Doc.FileFormat.PDF);
docX.SaveToFile("text2.docx", Spire.Doc.FileFormat.Docx);