翻譯|使用教程|編輯:顏馨|2023-04-21 09:43:07.410|閱讀 123 次
概述:本章講述通過Spire.Doc將Doc轉換為PDF時如何使用卸載的字體,歡迎查閱!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
現在Spire.Doc支持在將Doc轉換為PDF時使用未安裝的字體以實現文本內容的多樣化。在這篇文章中,我們將談論如何實現這一功能:如何在通過Spire.Doc將Doc轉換為PDF時使用卸載的字體
步驟1:下載一個在系統中卸載的字體。
步驟2:創建一個新的空白Word文檔。
Document document = new Document();步驟3:添加一個部分并創建一個新段落。
Section section = document.AddSection(); Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph();步驟4:為 txtRange 附加文本。
TextRange txtRange = paragraph.AppendText(text);步驟5:為名為pdf的類ToPdfParameterList創建一個示例,并為屬性PrivateFontPaths創建一個新的PrivateFontPathlist,使用下載字體的名稱和路徑實例化一個PrivateFontPath。
ToPdfParameterList toPdf = new ToPdfParameterList() { PrivateFontPaths = new List() { new PrivateFontPath("DeeDeeFlowers",@"D:\DeeDeeFlowers.ttf") } };步驟6:為 txtaRange 設置新字體。
txtRange.CharacterFormat.FontName = "DeeDeeFlowers";步驟7:將文檔轉換為 PDF。
document.SaveToFile("result.pdf", toPdf);步驟8:查看轉換后的 PDF 文件。
System.Diagnostics.Process.Start("result.pdf");結果截圖:
完整代碼如下:
Document document = new Document(); //Add the first secition Section section = document.AddSection(); //Create a new paragraph and get the first paragraph Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph(); //Append Text String text = "This paragraph is demo of text font and color. " + "The font name of this paragraph is Tahoma. " + "The font size of this paragraph is 20. " + "The under line style of this paragraph is DotDot. " + "The color of this paragraph is Blue. "; TextRange txtRange = paragraph.AppendText(text); //Import the font ToPdfParameterList toPdf = new ToPdfParameterList() { PrivateFontPaths = new List<PrivateFontPath>() { new PrivateFontPath("DeeDeeFlowers",@"D:\DeeDeeFlowers.ttf") } }; //Make use of the font. txtRange.CharacterFormat.FontName = "DeeDeeFlowers"; document.SaveToFile("result.pdf", toPdf); System.Diagnostics.Process.Start("result.pdf");
以上便是通過Spire.Doc將Doc轉換為PDF時如何使用卸載的字體的教程,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn