翻譯|使用教程|編輯:顏馨|2023-04-21 09:43:07.410|閱讀 123 次
概述:本章講述通過Spire.Doc將Doc轉(zhuǎn)換為PDF時如何使用卸載的字體,歡迎查閱!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進(jìn)行操作的 .NET 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團(tuán)隊研發(fā),不依賴第三方軟件,不受其他國家的技術(shù)或法律法規(guī)限制,同時適配國產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
現(xiàn)在Spire.Doc支持在將Doc轉(zhuǎn)換為PDF時使用未安裝的字體以實(shí)現(xiàn)文本內(nèi)容的多樣化。在這篇文章中,我們將談?wù)撊绾螌?shí)現(xiàn)這一功能:如何在通過Spire.Doc將Doc轉(zhuǎn)換為PDF時使用卸載的字體
步驟1:下載一個在系統(tǒng)中卸載的字體。
步驟2:創(chuàng)建一個新的空白Word文檔。
Document document = new Document();步驟3:添加一個部分并創(chuàng)建一個新段落。
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創(chuàng)建一個示例,并為屬性PrivateFontPaths創(chuàng)建一個新的PrivateFontPathlist,使用下載字體的名稱和路徑實(shí)例化一個PrivateFontPath。
ToPdfParameterList toPdf = new ToPdfParameterList() { PrivateFontPaths = new List() { new PrivateFontPath("DeeDeeFlowers",@"D:\DeeDeeFlowers.ttf") } };步驟6:為 txtaRange 設(shè)置新字體。
txtRange.CharacterFormat.FontName = "DeeDeeFlowers";步驟7:將文檔轉(zhuǎn)換為 PDF。
document.SaveToFile("result.pdf", toPdf);步驟8:查看轉(zhuǎn)換后的 PDF 文件。
System.Diagnostics.Process.Start("result.pdf");結(jié)果截圖:
完整代碼如下:
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轉(zhuǎn)換為PDF時如何使用卸載的字體的教程,如果您有其他問題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。
歡迎下載|體驗更多E-iceblue產(chǎn)品
獲取更多信息請咨詢 ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn