var w1 = "𠊎";
var w2 = "𪜶";
var w3 = "𫣆";
var p1 = "✔️";
var p2 = "✅";
var p3 = "☑️";
var p4 = "💩";
var content = $"w1: {w1}, w2: {w2}, w3: {w3}; p1: {p1}, p2: {p2}, p3: {p3}, p4: {p4}.";
string outputPath = "./test.pdf";
var font = FontRepository.FindFont("Microsoft JhengHei");
var document = new Aspose.Pdf.Document();
var newTextState = new TextState();
newTextState.Font = font;
document.PageInfo.DefaultTextState = newTextState;
Page page = document.Pages.Add();
page.PageInfo.DefaultTextState = newTextState;
var text = new Aspose.Pdf.Text.TextFragment(content);
text.TextState.Font = font;
page.Paragraphs.Add(text);
document.Save(outputPath);
var doc = new Aspose.Pdf.Document(outputPath);
var fonts = doc.FontUtilities.GetAllFonts();
foreach(var f in fonts)
{
Console.WriteLine(f.FontName);
}
您好,
原本產生的 pdf 就已包含 Arial字型,
將pdfSaveOptions加到document.Save(outputPath, pdfSaveOptions);之中,
產生出的 pdf 檔案內含字型還是為 MSGothic 及 Arial。
程式碼如下,
var w1 = "𠊎";
var w2 = "𪜶";
var w3 = "𫣆";
var p1 = "✔️";
var p2 = "✅";
var p3 = "☑️";
var p4 = "💩";
var content = $"w1: {w1}, w2: {w2}, w3: {w3}; p1: {p1}, p2: {p2}, p3: {p3}, p4: {p4}.";
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.DefaultFontName = "Arial";
string outputPath = "./test.pdf";
var font = FontRepository.FindFont("Arial");
var document = new Aspose.Pdf.Document();
var newTextState = new TextState();
newTextState.Font = font;
document.PageInfo.DefaultTextState = newTextState;
Page page = document.Pages.Add();
page.PageInfo.DefaultTextState = newTextState;
var text = new Aspose.Pdf.Text.TextFragment(content);
text.TextState.Font = font;
page.Paragraphs.Add(text);
document.Save(outputPath, pdfSaveOptions);
var doc = new Aspose.Pdf.Document(outputPath);
var fonts = doc.FontUtilities.GetAllFonts();
foreach(var f in fonts)
{
Console.WriteLine(f.FontName);
}
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.