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 RepeatTableHeaderModel : PageModel
{
public void OnGet()
{
TxtUrl = Helper.WWWRoot(Request) + Url.Content("~/files/table/table_with_repeated_head.html");
}
[BindProperty]
public string TxtUrl { get; set; }
[BindProperty]
public string DdlRenderingEngine { get; set; } = "Chromium";
public List<SelectListItem> RenderingEngines { get; } = Helper.RenderingEngines();
public IActionResult OnPost()
{
// instantiate a html to pdf converter object
PdfConverter converter = new PdfConverter() { AllowLocalAccess = false };
// converter.LicenseKey = "your license key";
// the rendering engine: Chromium is the recommended engine for modern pages
converter.RenderingEngine = (RenderingEngine)Enum.Parse(typeof(RenderingEngine), DdlRenderingEngine);
converter.PdfDocumentOptions.TopMargin = 20;
converter.PdfDocumentOptions.BottomMargin = 20;
// lay out the page for printing: Chromium and Blink repeat the thead of the table on every page with the
// print media type
converter.UsePrintCSSMediaType = true;
// convert the url to pdf
byte[] pdf = converter.GetPdfBytesFromUrl(TxtUrl);
// return resulted pdf document
FileResult fileResult = new FileContentResult(pdf, "application/pdf");
fileResult.FileDownloadName = "RepeatTableHeader.pdf";
return fileResult;
}
}
}