Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 14, 2021 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/4a225a6dc57234b9aa9cb47fab93d6ef to your computer and use it in GitHub Desktop.
Save aspose-com-gists/4a225a6dc57234b9aa9cb47fab93d6ef to your computer and use it in GitHub Desktop.
HTML至PDF CSharp
WebRequest req = WebRequest.Create(@"https://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html");
// 将网页放入流中
using (Stream stream = req.GetResponse().GetResponseStream())
{
// 初始化HTML加载选项
HtmlLoadOptions htmloptions = new HtmlLoadOptions("https://docs.oracle.com/");
// 将流加载到Document对象中
Document pdfDocument = new Document(stream, htmloptions);
// 将输出另存为PDF格式
pdfDocument.Save("HTML-to-PDF.pdf");
}
// 创建HTML加载选项
HtmlLoadOptions htmloptions = new HtmlLoadOptions();
// 载入HTML档案
Document doc = new Document("HTML-Document.html", htmloptions);
// 将HTML文件转换为PDF
doc.Save("HTML-to-PDF.pdf");
// 创建HTML加载选项
HtmlLoadOptions htmloptions = new HtmlLoadOptions();
// 载入HTML档案
Document doc = new Document("HTML-Document.html", htmloptions);
// 设置加密参数
doc.Encrypt("userpassword", "ownerPassword", Permissions.ModifyContent, CryptoAlgorithm.AESx256);
// 将HTML文件转换为PDF
doc.Save("HTML-to-PDF.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment