Sample code · C#
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using SelectPdf.Universal; namespace SelectPdf.Samples.Pages { public class PageSettingsModel : PageModel { public void OnGet() { } public IActionResult OnPost() { // create a new pdf document PdfDocument doc = new PdfDocument(); // create a new pdf font PdfFont font = doc.Fonts.Add(PdfStandardFont.Helvetica); font.Size = 18; // add a new page to the document // (with specific page size, margins and orientation) PdfPage page = doc.AddPage(PdfCustomPageSize.A4, new PdfMargins(0f), PdfPageOrientation.Portrait); // create a new text element and add it to the page PdfTextElement text = new PdfTextElement(0, 0, Helper.SomeText(), font); page.Add(text); // add a new page to the document // (with specific page size, margins and orientation) PdfPage page2 = doc.AddPage(PdfCustomPageSize.Letter, new PdfMargins(20f), PdfPageOrientation.Landscape); // create a new text element and add it to the page PdfTextElement text2 = new PdfTextElement(0, 0, Helper.SomeText(), font); page2.Add(text2); // save pdf document byte[] pdf = doc.Save(); // close pdf document doc.Close(); // return resulted pdf document FileResult fileResult = new FileContentResult(pdf, "application/pdf"); fileResult.FileDownloadName = "Document.pdf"; return fileResult; } } }