C# PDF how-to guides, with code that runs.
Short, complete C# programs for common PDF tasks in .NET, each explained step by step. Every sample on these pages is compiled and run on Windows and Linux before it is published, and the PDF it produced is on the page.
Convert a password-protected web page to PDF in C# with SelectPdf.Universal: send a bearer token or session cookie, answer Basic auth, or fill in a login form.
Digitally sign a PDF with a PFX certificate in C#Digitally sign a PDF in C# with a .pfx certificate and SelectPdf.Universal: a visible signature with reason and location, a seal image, and a second signer.
Fonts on Linux: the same PDF on every server, in every language (C#)Make HTML to PDF in C# look the same on Windows and Linux with SelectPdf.Universal: built-in Liberation fonts, Noto fonts for every script, your own fonts.
Convert a page behind a login to PDF in C#
Convert a password-protected web page to PDF in C# with SelectPdf.Universal: send a bearer token or session cookie, answer Basic auth, or fill in a login form.
Free HTML to PDF in C# with the SelectPdf Community Edition
Convert HTML to PDF in C# for free with the SelectPdf Community Edition on Windows, Linux, macOS and Docker: setup, headers and footers, and the 5-page limit.
Generate an invoice PDF from an HTML template in C#
Generate invoice PDFs in C# from an HTML template and your data with SelectPdf.Universal: line items, totals, A4 margins, repeating table headers, page numbers.
Control page breaks in HTML to PDF with CSS
Control where pages break when you convert HTML to PDF in C#: page-break-before, page-break-after and page-break-inside in CSS, plus breaks from @media print.
HTML to PDF in C#: convert a URL or an HTML string
Convert a web page URL or an HTML string to PDF in C# on .NET 8 or .NET 10, with A4 pages and 20 mm margins, on Windows, Linux and macOS, step by step.
Add page numbers to a PDF in C# (Page X of Y)
Add "Page X of Y" page numbers to PDFs in C#: in an HTML to PDF footer, skipped on a cover page, or stamped onto an existing PDF with SelectPdf.Universal.
HTML headers and footers with a logo and the date in C#
Add an HTML header with a logo and title and a footer with the date to each PDF page in C#, from an HTML string, a URL or an image, with SelectPdf.Universal.
Convert HTML to PNG or JPG in C#
Convert a URL or an HTML string to a PNG or JPG image in C# with HtmlToImage: set the browser size, resolve relative images, capture one element, go async.
Take a full-page screenshot of a website in C#
Capture a whole web page as one PNG in C# with SelectPdf.Universal HtmlToImage: auto height, a first-screen crop, a phone-width capture and script delays.
Convert HTML to PDF asynchronously and in parallel in C#
Convert many pages to PDF at once in C#: async conversion with Task.WhenAll, a concurrency limit, timeouts and cancellation, batches with Parallel.ForEachAsync.
Generate PDFs in a background queue in .NET (BackgroundService)
Queue HTML and URL to PDF jobs in a .NET app and convert them in a BackgroundService: a Channel as the job queue, async conversion and a clean shutdown.
Add a watermark to every page of a PDF in C#
Stamp a rotated, semi-transparent CONFIDENTIAL watermark on every page of an existing PDF in C# with SelectPdf.Universal, plus logo and DRAFT variations.
Merge PDF files in C#: files, streams and folders
Merge PDF files in C# with SelectPdf.Universal: combine files, in-memory streams, converted HTML or a whole folder into one PDF, on Windows, Linux and macOS.
Fill PDF form fields in C#
Fill PDF form fields in C#: create a fillable form from HTML, set text boxes, check boxes, combo boxes and radio buttons by name, then save the filled PDF.
Flatten a PDF form in C#
Flatten a PDF form in C#: create a fillable form from HTML, fill it, and turn the values into page content, for all fields or some, or for an existing PDF file.
Digitally sign a PDF with a PFX certificate in C#
Digitally sign a PDF in C# with a .pfx certificate and SelectPdf.Universal: a visible signature with reason and location, a seal image, and a second signer.
Validate PDF digital signatures in C#
Validate PDF digital signatures in C# with SelectPdf.Universal: check they are intact and trusted, and detect tampering, later changes and revoked certificates.
Password-protect a PDF with AES-256 in C#
Encrypt a PDF with AES-256 in C#: set an open password, block printing and copying with an owner password, or protect an existing file with SelectPdf.Universal.
Redact PDF text with a regular expression in C#
Remove sensitive text such as card numbers from a PDF in C# with SelectPdf.Universal. The content is deleted from the file, not just covered over.
Accessible PDF/UA from HTML in C# (tagged PDF)
Create accessible, tagged PDF/UA-1 and PDF/UA-2 documents from HTML in C#, with PDF/A-4 or PDF/A-3A for archiving, all validated with veraPDF.
Convert HTML to PDF/A for archiving in C#
Convert HTML to archival PDF/A in C#: PDF/A-2b with metadata, PDF/A-1b, PDF/A-3b with an embedded source file, and merging into PDF/A, validated by veraPDF.
Create a ZUGFeRD / Factur-X invoice in C#
Create a ZUGFeRD / Factur-X hybrid invoice in C#: convert HTML to PDF/A-3 and embed the CII XML with AddZugferdInvoice and the right profile.
Create an XRechnung invoice in C#
Create an XRechnung invoice in C#: convert the invoice to PDF/A-3 and embed the XRechnung XML as xrechnung.xml with AddZugferdInvoice, validated by veraPDF.
Convert DOCX to PDF on Linux in C#
Convert Word DOCX files to PDF on Linux in C# with SelectPdf.Universal, and no Microsoft Office installed. Missing fonts come from the bundled Liberation fonts.
Convert Word documents to PDF/A for archiving in C#
Convert Word DOCX files to archival PDF/A in C#: PDF/A-2b with title metadata, PDF/A-4, accessible PDF/A-3a with PDF/UA-1, and merging into PDF/A.
Convert PDF pages to PNG images in C#
Render every page of a PDF to a PNG image in C# with SelectPdf.Universal at the resolution you choose, plus a first-page thumbnail, JPG files and grayscale.
Extract text from a PDF in C#
Extract the text of a PDF in C# with SelectPdf.Universal: get it as a string or save it to a UTF-8 file, read a page range, keep columns or reading order.
Generate and download a PDF from Blazor in C#
Generate a PDF on the server from a Blazor Web App in C# and download it with a link or a JS interop stream, using a Razor component as the template.
Return a PDF from an ASP.NET Core endpoint in C#
Return HTML rendered as a PDF download from an ASP.NET Core minimal API endpoint in C#, asynchronously, and render Razor components such as invoices to PDF.
Fonts on Linux: the same PDF on every server, in every language (C#)
Make HTML to PDF in C# look the same on Windows and Linux with SelectPdf.Universal: built-in Liberation fonts, Noto fonts for every script, your own fonts.
HTML to PDF on ARM64 Linux (AWS Graviton) in C#
Convert HTML to PDF in C# on ARM64 Linux, such as AWS Graviton, with SelectPdf.Universal: the linux-arm64 engine package and an ARM64 Docker image, no apt-get.
HTML to PDF on Google Cloud Run in C#
Convert HTML to PDF in an ASP.NET Core container on Google Cloud Run: packages and fonts, a Dockerfile with the non-root user, and the gcloud deploy settings.
HTML to PDF in AWS Lambda with C# (x86_64 and arm64)
Generate PDFs from HTML in an AWS Lambda function in C#, packaged as a container image on x86_64 or arm64 Graviton, with the Dockerfile and deployment steps.
HTML to PDF in Azure Functions with C#
Generate PDFs from HTML in an Azure Functions HTTP trigger with C#: the isolated worker, the plans that work, the Linux and Windows packages, deployment.
HTML to PDF in Docker on Linux with C# (no apt-get)
Convert HTML to PDF in a Linux Docker container with SelectPdf.Universal: two NuGet packages, a stock .NET runtime image, and no system packages to install.
HTML to PDF on Azure App Service (Linux) in C#
Convert HTML to PDF in an ASP.NET Core app on Azure App Service for Linux: which plan to use, the packages and fonts it needs, and zip deployment.
Fix HTML to PDF on Alpine Linux in C# with the remote engine
HTML to PDF fails on Alpine because the native engines need glibc. Convert from an Alpine .NET image in C# through the selectpdf/engine container instead.
Fix blank pages and missing content in HTML to PDF (C#)
Fix blank or incomplete PDFs from HTML in C#: wait for script content, start the conversion from JavaScript, resolve relative images and use print CSS.
Looking for something else? The SelectPdf.Universal documentation covers every class and option, and the online demo runs the converters in your browser.