翻譯|行業(yè)資訊|編輯:胡濤|2023-08-24 10:59:30.303|閱讀 149 次
概述:本文將演示如何在 Java 應(yīng)用程序中使用 Spire.Doc for Java 將 HTML 字符串和 HTML 文件轉(zhuǎn)換為 PDF。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
Spire.Doc 是一款專(zhuān)門(mén)對(duì) Word 文檔進(jìn)行操作的 類(lèi)庫(kù)。在于幫助開(kāi)發(fā)人員無(wú)需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專(zhuān)業(yè)開(kāi)發(fā)經(jīng)驗(yàn)Spire系列辦公文檔開(kāi)發(fā)工具,專(zhuān)注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷,除此之外,你也可以瀏覽E-iceblue 旗下其他不同語(yǔ)言的文檔開(kāi)發(fā)工具~
Spire.Doc for.net下載 Spire.Doc for java下載
本文將演示如何在 Java 應(yīng)用程序中使用 Spire.Doc for Java 將 HTML 字符串和 HTML 文件轉(zhuǎn)換為 PDF。
import com.spire.doc.*; import java.io.*; public class htmlStringToWord { public static void main(String[] args) throws Exception { String inputHtml = "InputHtml.txt"; //Create a new document Document document = new Document(); //Add a section Section sec = document.addSection(); String htmlText = readTextFromFile(inputHtml); //add a paragraph and append html string. sec.addParagraph().appendHTML(htmlText); //Save to PDF document.saveToFile("HTMLstringToPDF.pdf", FileFormat.PDF); } public static String readTextFromFile(String fileName) throws IOException{ StringBuffer sb = new StringBuffer(); BufferedReader br = new BufferedReader(new FileReader(fileName)); String content = null; while ((content = br.readLine()) != null) { sb.append(content); } return sb.toString(); } }
import com.spire.doc.*; import com.spire.doc.documents.XHTMLValidationType; public class htmlFileToWord { public static void main(String[] args) throws Exception { // Load the sample HTML file Document document = new Document(); document.loadFromFile("InputHtmlFile.html", FileFormat.Html, XHTMLValidationType.None); //Save to file document.saveToFile("Result.pdf",FileFormat.PDF); } }
以上便是如何在Java中將 Word 轉(zhuǎn)換為 PDF,如果您有其他問(wèn)題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品
獲取更多信息請(qǐng)咨詢(xún) ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn