Last active
April 14, 2021 16:46
-
-
Save aspose-com-gists/4a225a6dc57234b9aa9cb47fab93d6ef to your computer and use it in GitHub Desktop.
HTML至PDF CSharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 创建HTML加载选项 | |
HtmlLoadOptions htmloptions = new HtmlLoadOptions(); | |
// 载入HTML档案 | |
Document doc = new Document("HTML-Document.html", htmloptions); | |
// 将HTML文件转换为PDF | |
doc.Save("HTML-to-PDF.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 创建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