Word格式處理控件Aspose.Words for .NET教程——設(shè)置字體格式并獲取行距
Aspose.Words For .NET是一種高級Word文檔處理API,用于執(zhí)行各種文檔管理和操作任務(wù)。API支持生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印文檔,而無需在跨平臺應(yīng)用程序中直接使用Microsoft Word。此外,API支持所有流行的Word處理文件格式,并允許將Word文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
>>Aspose.Words for .NET已經(jīng)更新至v20.4,Aspose.Words for .Net更新至新版本v20.4,主要新增5大特點,包括:支持閱讀PDF文檔;提供了更改亞洲段落間距和縮進(jìn)的功能;為PDF渲染添加了圖像插值選項;添加了新的模式3D形狀渲染;圖表數(shù)據(jù)標(biāo)簽和系列的擴(kuò)展API,點擊下載體驗
設(shè)置字體格式
當(dāng)前字體格式由DocumentBuilder.Font屬性返回的Font對象表示。Font類包含Microsoft Word中可能存在的各種字體屬性。 下例顯示了如何設(shè)置字體格式。
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set font formatting properties
Font font = builder.Font;
font.Bold = true;
font.Color = System.Drawing.Color.DarkBlue;
font.Italic = true;
font.Name = "Arial";
font.Size = 24;
font.Spacing = 5;
font.Underline = Underline.Double;
// Output formatted text
builder.Writeln("I'm a very nice formatted string.");
dataDir = dataDir + "DocumentBuilderSetFontFormatting_out.doc";
doc.Save(dataDir);
獲取字體行距
字體的行距是兩行連續(xù)文本的基線之間的垂直距離。因此,行距包括行之間的空白以及字符本身的高度。
如以下示例所示,在Font類中引入了LineSpacing屬性以獲得該值:
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
// Initialize document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Font.Name = "Calibri";
builder.Writeln("qText");
// Obtain line spacing.
Font font = builder.Document.FirstSection.Body.FirstParagraph.Runs[0].Font;
Console.WriteLine($"lineSpacing = {font.LineSpacing}");
還想要更多嗎?您可以點擊閱讀【2019 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請隨時加入Aspose技術(shù)交流群(642018183),我們很高興為您提供查詢和咨詢。

QQ交談
在線咨詢

渝公網(wǎng)安備
50010702500608號

客服熱線