C# code of this sample
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using ExpertPdf.HtmlToPdf;
namespace ExpertPdf.Samples.Pages
{
public class WindowStatusModel : PageModel
{
public void OnGet()
{
TxtUrl = Helper.WWWRoot(Request) + Url.Content("~/files/window-status.html");
}
[BindProperty]
public string TxtUrl { get; set; }
[BindProperty]
public string TxtWindowStatus { get; set; } = "ready";
[BindProperty]
public string DdlRenderingEngine { get; set; } = "Chromium";
public List<SelectListItem> RenderingEngines { get; } = Helper.BrowserRenderingEngines();
public IActionResult OnPost()
{
// instantiate a html to pdf converter object
PdfConverter converter = new PdfConverter() { AllowLocalAccess = false };
// converter.LicenseKey = "your license key";
// the rendering engine: WindowStatus is honored by Chromium (recommended) and Blink
converter.RenderingEngine = (RenderingEngine)Enum.Parse(typeof(RenderingEngine), DdlRenderingEngine);
// wait until the page sets window.status to this text; give up after 30 seconds
if (!string.IsNullOrEmpty(TxtWindowStatus))
converter.WindowStatus = TxtWindowStatus;
converter.NavigationTimeout = 30;
// convert the url to pdf
byte[] pdf = converter.GetPdfBytesFromUrl(TxtUrl);
// return resulted pdf document
FileResult fileResult = new FileContentResult(pdf, "application/pdf");
fileResult.FileDownloadName = "WindowStatus.pdf";
return fileResult;
}
}
}