Spire.Doc拥有强大的转换功能。本文将介绍如何使用Spire.Doc将HTML String和HTML file两种HTML样式的文档保存为PDF格式。
HTML String另存为PDF格式
C#
string HTML = File.ReadAllText("InputHtml.txt");
Document document = new Document();
Section sec = document.AddSection();
sec.AddParagraph().AppendHTML(HTML);
document.SaveToFile("HtmlstringtoPDF.PDF", FileFormat.PDF);
VB.NET
Dim HTML As String = File.ReadAllText("InputHtml.txt")
Dim document As New Document()
Dim sec As Section = document.AddSection()
sec.AddParagraph().AppendHTML(HTML)
document.SaveToFile("HtmlstringtoPDF.PDF", FileFormat.PDF)
原文档:
结果文档:
HTML file另存为PDF格式
C#
Document document = new Document();
document.LoadFromFile("InputHtmlFile.html", FileFormat.Html, XHTMLValidationType.None);
document.SaveToFile("HtmlFileToPDF.pdf", FileFormat.PDF);
VB.NET
Dim document As Document = New Document
document.LoadFromFile("InputHtmlFile.html", FileFormat.Html, XHTMLValidationType.None)
document.SaveToFile("HtmlFileToPDF.pdf", FileFormat.PDF)
原文档:
结果文档: