翻譯|行業資訊|編輯:胡濤|2023-08-24 10:59:30.303|閱讀 149 次
概述:本文將演示如何在 Java 應用程序中使用 Spire.Doc for Java 將 HTML 字符串和 HTML 文件轉換為 PDF。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc 是一款專門對 Word 文檔進行操作的 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷,除此之外,你也可以瀏覽E-iceblue 旗下其他不同語言的文檔開發工具~
Spire.Doc for.net下載 Spire.Doc for java下載
本文將演示如何在 Java 應用程序中使用 Spire.Doc for Java 將 HTML 字符串和 HTML 文件轉換為 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 轉換為 PDF,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn