-
Notifications
You must be signed in to change notification settings - Fork 0
/
Default.aspx.cs
74 lines (63 loc) · 2.59 KB
/
Default.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PuppeteerSharp;
using System.Threading.Tasks;
using PuppeteerSharp.Media;
namespace SFHTMLtoPDF
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnPDF_Click(object sender, EventArgs e)
{
//Initialize HTML to PDF converter
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = Server.MapPath("~/bin/QtBinaries");
settings.MediaType = Syncfusion.HtmlConverter.MediaType.Print;
settings.Orientation = PdfPageOrientation.Landscape;
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert HTML to PDF
PdfDocument document = htmlConverter.Convert(txtURL.Text);
//Save the PDF document
document.Save(Server.MapPath("~/PDF/HTMLToPDF.pdf"), Response, HttpReadType.Open);
//Close the document
document.Close(true);
//This will open the PDF file so, the result will be seen in default PDF viewer
//Process.Start("HTMLToPDF.pdf");
}
protected async void btnPupet_Click(object sender, EventArgs e)
{
var fileName = Server.MapPath("~/PDF/PuppetToPDF.pdf");
var output = "" + fileName;
// await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision).ConfigureAwait(false);
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
ExecutablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
}).ConfigureAwait(false);
var pdfOptions = new PdfOptions
{
Format = PaperFormat.A4,
Landscape = true,
PrintBackground = true,
DisplayHeaderFooter = true
};
var page = await browser.NewPageAsync().ConfigureAwait(false);
await page.GoToAsync(txtURL.Text).ConfigureAwait(false);
await page.PdfAsync(output, pdfOptions).ConfigureAwait(false);
lblmsg.Visible = true;
}
}
}