Trying to use PuppeteerSharp in our ASP.NET Web Forms application to generate a PDF and while it works fine locally I receive the below error when deploying to an IIS server.
One thing I do notice is that a ZIP file with zero bytes called download-Win64-706915.zip is created.
My code is as follows
var url = ConfigurationManager.AppSettings["EnrolmentFormUrl"] + "?code=" + code;
var fileName = "enrolment" + $"{DateTime.Now:__ddMMyyyyhhmmssfff}" + ".pdf";
var output = Config.attachmentPath + fileName;
var browserFetcher = new BrowserFetcher(new BrowserFetcherOptions
{
Path = Config.attachmentPath
});;
await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision).ConfigureAwait(false);
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
TransportFactory = AspNetWebSocketTransport.AspNetTransportFactory,
ExecutablePath = browserFetcher.RevisionInfo(BrowserFetcher.DefaultRevision).ExecutablePath
}).ConfigureAwait(false);
var pdfOptions = new PdfOptions
{
Format = PaperFormat.A4,
PreferCSSPageSize = true
};
var page = await browser.NewPageAsync();
await page.GoToAsync(url).ConfigureAwait(false);
await page.PdfAsync(output, pdfOptions).ConfigureAwait(false);
The issue was due to the fact that the server being deployed to did not have internet access and PuppeteerSharp was looking to download Chromium resolved by specifying a local execution path.
ExecutablePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
Revised code below
var url = ConfigurationManager.AppSettings["EnrolmentFormUrl"] + "?code=" + code;
var fileName = "enrolment" + $"{DateTime.Now:__ddMMyyyyhhmmssfff}" + ".pdf";
var output = Config.attachmentPath + fileName;
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
TransportFactory = AspNetWebSocketTransport.AspNetTransportFactory,
ExecutablePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
}).ConfigureAwait(false);
var pdfOptions = new PdfOptions
{
Format = PaperFormat.A4,
PreferCSSPageSize = true
};
var page = await browser.NewPageAsync();
await page.GoToAsync(url).ConfigureAwait(false);
await page.PdfAsync(output, pdfOptions).ConfigureAwait(false);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.