*这么优秀的国产工具怎能错过呢!在线下单专享“一口价”,查看优惠价格!想要获取更多福利的朋友可以咨询在线客服哦~
HTML String另存为PDF格式
import com.spire.doc.*;import java.io.*;public class htmlStringToWord { public static void main(String[] args) throws Exception { String inputHtml = "InputHtml.txt"; //新建Document对象 Document document = new Document(); //添加section Section sec = document.addSection(); String htmlText = readTextFromFile(inputHtml); //添加段落并写入HTML文本 sec.addParagraph().appendHTML(htmlText); //文档另存为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(); }}

HTML file另存为PDF格式
import com.spire.doc.*;import com.spire.doc.documents.XHTMLValidationType;public class htmlFileToWord { public static void main(String[] args) throws Exception { //加载HTML文档 Document document = new Document(); document.loadFromFile("InputHtmlFile.html", FileFormat.Html, XHTMLValidationType.None); //文档另存为PDF document.saveToFile("Result.pdf",FileFormat.PDF); }}

还想要更多教程资源吗可以点击阅读【2020 · E-iceblue最新资源整合】,查找需要的教程资源。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!