Skip to content

Instantly share code, notes, and snippets.

@KennethScott
Created December 20, 2022 15:41
Show Gist options
  • Save KennethScott/eb73951ee150beb2fe6e40c49633288d to your computer and use it in GitHub Desktop.
Save KennethScott/eb73951ee150beb2fe6e40c49633288d to your computer and use it in GitHub Desktop.
var baseUrl = $"{Request.Scheme}://{Request.Host}{Request.PathBase}";
//var baseUrl = "D:\\home\\site\\wwwroot\\wwwroot";
IronPdf.Logging.Logger.EnableDebugging = true;
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.File;
IronPdf.Logging.Logger.LogFilePath = "IronPdf.txt";
var cookies = Request.Cookies;
Dictionary<string, string> customCookies = cookies.ToDictionary(c => c.Key, c => c.Value);
var newPdf = new HtmlToPdf
{
PrintOptions = new ChromePdfRenderOptions
{
CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print,
},
LoginCredentials = new ChromeHttpLoginCredentials
{
CustomCookies = customCookies,
EnableCookies = true
}
};
return await newPdf.RenderHtmlAsPdfAsync(html, new Uri(baseUrl));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment