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 document = 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)
原文档:
结果文档: