Skip to footer content
USING IRONPDF

PDF API for .NET Core: Generate and Edit PDFs in C#

IronPDF .NET Core PDF API overview showing code editor with HTML to PDF conversion and output document side by side

IronPDF is a PDF API for .NET Core and .NET 10 that generates, converts, and edits PDF documents through C# code. Install the NuGet package, create a ChromePdfRenderer instance, and produce PDFs from HTML strings, live URLs, or existing files in a few lines.

PDF generation is a standard requirement in .NET Core applications for invoices, reports, contracts, and compliance documents. The challenge is finding a library that renders HTML accurately, integrates cleanly with ASP.NET Core and Blazor, produces consistent output on Windows, Linux, and macOS, and handles advanced operations like digital signatures and password protection without requiring separate tools. This guide walks through IronPDF's .NET Core PDF API from installation through the most common document operations, each with working C# code examples.

How Do You Get Started with IronPDF in .NET Core?

Install IronPDF from NuGet using the Package Manager Console or the .NET CLI:

# Package Manager Console
Install-Package IronPdf

# .NET CLI
dotnet add package IronPdf
# Package Manager Console
Install-Package IronPdf

# .NET CLI
dotnet add package IronPdf
SHELL

After installation, add your license key at application startup in Program.cs:

using IronPdf;

// Configure your license key before any IronPDF operations
License.LicenseKey = "YOUR-LICENSE-KEY";
using IronPdf;

// Configure your license key before any IronPDF operations
License.LicenseKey = "YOUR-LICENSE-KEY";
$vbLabelText   $csharpLabel

A free trial is available for evaluation without a credit card. IronPDF supports .NET 10, .NET 9, .NET 8, .NET Framework 4.6.2+, and all major .NET Core versions. The library runs on Windows, macOS, and Linux without additional runtime dependencies, making it suitable for containerized deployments and cloud environments including Azure, Docker, and AWS.

For ASP.NET Core projects, register IronPDF services in Program.cs before building the app, then inject ChromePdfRenderer through the standard dependency injection container. IronPDF integrates with ASP.NET Core project types including Web API, MVC, Razor Pages, and Blazor Server. The NuGet package installs as a single dependency without requiring native runtime libraries or external executables, which keeps your CI pipeline and container images straightforward. No additional configuration is required for Linux or macOS deployments beyond the standard .NET SDK.

Because ChromePdfRenderer is thread-safe, you can register it as a singleton and share it across request handlers. In high-throughput scenarios, create a pool of renderer instances or use the async render methods (RenderHtmlAsPdfAsync, RenderUrlAsPdfAsync) to avoid blocking request threads while PDF generation runs. IronPDF's licensing page covers deployment seat and concurrent-thread limits for production environments.

How Do You Generate PDFs from HTML in C#?

HTML-to-PDF conversion is the most common use of a .NET PDF API. IronPDF's ChromePdfRenderer converts HTML strings, local files, or live URLs while preserving CSS styles, fonts, JavaScript output, and images as they render in Chrome.

using IronPdf;

// Create the renderer and define HTML content with full CSS support
var renderer = new ChromePdfRenderer();
var html = @"<html>
<head>
    <style>
        body { font-family: Arial; font-size: 14px; margin: 40px; }
        h1 { color: #2c3e50; border-bottom: 2px solid #3498db; }
        table { border-collapse: collapse; width: 100%; margin-top: 16px; }
        td, th { border: 1px solid #ddd; padding: 10px; text-align: left; }
        th { background: #3498db; color: white; }
    </style>
</head>
<body>
    <h1>Sales Report - Q4 2025</h1>
    <p>Generated on: " + DateTime.Now.ToString("MMMM dd, yyyy") + @"</p>
    <table>
        <tr><th>Product</th><th>Units Sold</th><th>Revenue</th></tr>
        <tr><td>Widget A</td><td>1,200</td><td>$24,000</td></tr>
        <tr><td>Widget B</td><td>850</td><td>$17,000</td></tr>
    </table>
</body>
</html>";

var document = renderer.RenderHtmlAsPdf(html);
document.SaveAs("sales-report.pdf");
using IronPdf;

// Create the renderer and define HTML content with full CSS support
var renderer = new ChromePdfRenderer();
var html = @"<html>
<head>
    <style>
        body { font-family: Arial; font-size: 14px; margin: 40px; }
        h1 { color: #2c3e50; border-bottom: 2px solid #3498db; }
        table { border-collapse: collapse; width: 100%; margin-top: 16px; }
        td, th { border: 1px solid #ddd; padding: 10px; text-align: left; }
        th { background: #3498db; color: white; }
    </style>
</head>
<body>
    <h1>Sales Report - Q4 2025</h1>
    <p>Generated on: " + DateTime.Now.ToString("MMMM dd, yyyy") + @"</p>
    <table>
        <tr><th>Product</th><th>Units Sold</th><th>Revenue</th></tr>
        <tr><td>Widget A</td><td>1,200</td><td>$24,000</td></tr>
        <tr><td>Widget B</td><td>850</td><td>$17,000</td></tr>
    </table>
</body>
</html>";

var document = renderer.RenderHtmlAsPdf(html);
document.SaveAs("sales-report.pdf");
$vbLabelText   $csharpLabel

Output PDF Document

Visual Studio project running IronPDF HTML to PDF conversion producing a formatted Sales Report with a styled data table

The ChromePdfRenderer returns a PdfDocument object that you can save to a file path, export to a byte[] for HTTP responses, or write to a MemoryStream for in-memory processing. The renderer respects all CSS properties including custom fonts, flexbox, grid layouts, media queries, and @page rules for margin and page-size control. For HTML templates stored on disk alongside CSS and image assets, call RenderHtmlFileAsPdf with the file path instead of passing an inline string. IronPDF resolves relative asset paths against the file's directory, so linked stylesheets and local images appear in the output without additional configuration.

For applications that need to capture live web pages, use RenderUrlAsPdfAsync to screenshot any URL while executing JavaScript:

using IronPdf;

var renderer = new ChromePdfRenderer();

// Render a live URL including all JavaScript-rendered content
var document = await renderer.RenderUrlAsPdfAsync("https://example.com/monthly-report");
document.SaveAs("monthly-report.pdf");

// Return PDF bytes in an ASP.NET Core controller
byte[] pdfBytes = document.BinaryData;
return File(pdfBytes, "application/pdf", "report.pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();

// Render a live URL including all JavaScript-rendered content
var document = await renderer.RenderUrlAsPdfAsync("https://example.com/monthly-report");
document.SaveAs("monthly-report.pdf");

// Return PDF bytes in an ASP.NET Core controller
byte[] pdfBytes = document.BinaryData;
return File(pdfBytes, "application/pdf", "report.pdf");
$vbLabelText   $csharpLabel

URL rendering waits for JavaScript to complete before capturing, which ensures that dynamically loaded charts, tables, and data visualizations appear correctly in the output PDF. You can configure rendering options to set page margins, paper size, orientation, and JavaScript execution timeout. Authentication cookies and custom HTTP headers can also be injected into the request before rendering, which supports capturing pages that require a logged-in session.

How Do You Configure PDF Page Layout and Rendering Options?

The RenderingOptions property on ChromePdfRenderer controls page dimensions, margins, orientation, and JavaScript wait behavior before any render call executes. Set these properties once on the renderer instance and they apply to every document it produces.

using IronPdf;

var renderer = new ChromePdfRenderer();

// Configure page layout before rendering
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Landscape;
renderer.RenderingOptions.MarginTop = 15;
renderer.RenderingOptions.MarginBottom = 15;
renderer.RenderingOptions.MarginLeft = 20;
renderer.RenderingOptions.MarginRight = 20;

// Wait for dynamic JavaScript content before capturing
renderer.RenderingOptions.WaitFor.RenderDelay(500);

var document = renderer.RenderHtmlAsPdf("<h1>Landscape Report</h1><p>Body content here.</p>");
document.SaveAs("landscape-report.pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();

// Configure page layout before rendering
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Landscape;
renderer.RenderingOptions.MarginTop = 15;
renderer.RenderingOptions.MarginBottom = 15;
renderer.RenderingOptions.MarginLeft = 20;
renderer.RenderingOptions.MarginRight = 20;

// Wait for dynamic JavaScript content before capturing
renderer.RenderingOptions.WaitFor.RenderDelay(500);

var document = renderer.RenderHtmlAsPdf("<h1>Landscape Report</h1><p>Body content here.</p>");
document.SaveAs("landscape-report.pdf");
$vbLabelText   $csharpLabel

Paper size values cover standard formats including A4, A3, Letter, Legal, and custom dimensions specified in millimeters. The margin properties accept values in millimeters and apply independently to each edge. The WaitFor API controls JavaScript execution timing, which is useful when your HTML loads data asynchronously before rendering charts or computed table values. For pages that use CSS @page rules, IronPDF respects those declarations and applies them directly. See the full rendering options reference for the complete property list including zoom factor, background color, and PDF version selection.

How Do You Convert DOCX Files and Images to PDF?

Beyond HTML, IronPDF converts DOCX documents, common image formats, and Markdown files into PDFs. This supports processing pipelines that accept multiple input types.

using IronPdf;

// Convert a Word document to PDF while preserving its formatting
var docxPdf = new DocxToPdfRenderer().RenderDocxAsPdf("contract.docx");
docxPdf.SaveAs("contract.pdf");

// Combine multiple images into a single multi-page PDF
var images = new[] { "page1.png", "page2.png", "page3.png" };
var imagePdf = ImageToPdfConverter.ImageToPdf(images);
imagePdf.SaveAs("scanned-document.pdf");
using IronPdf;

// Convert a Word document to PDF while preserving its formatting
var docxPdf = new DocxToPdfRenderer().RenderDocxAsPdf("contract.docx");
docxPdf.SaveAs("contract.pdf");

// Combine multiple images into a single multi-page PDF
var images = new[] { "page1.png", "page2.png", "page3.png" };
var imagePdf = ImageToPdfConverter.ImageToPdf(images);
imagePdf.SaveAs("scanned-document.pdf");
$vbLabelText   $csharpLabel

Example Input DOCX vs. Output PDF

Side-by-side comparison of original Word document and the IronPDF-converted PDF output showing preserved table formatting and styles

The DOCX to PDF conversion feature preserves paragraph styles, tables, headers, footers, embedded images, and lists from the source Word document. The image-to-PDF converter accepts JPEG, PNG, TIFF, BMP, and GIF, optimizes output file size automatically, and supports combining multiple images into a single paginated document. Both converters return a standard PdfDocument instance, so you can chain them with editing operations like merging, signing, or watermarking. For DOCX files generated by Microsoft Word, the converter handles complex table structures and embedded images while maintaining the original paragraph and heading hierarchy.

How Do You Add Digital Signatures and Form Fields?

Production document workflows often require cryptographic signatures for authenticity and interactive form fields for data collection. IronPDF provides digital signatures and PDF form support through the same API.

using IronPdf;
using IronPdf.Signing;

// Load an existing PDF and apply a digital signature using an X.509 certificate
var pdf = PdfDocument.FromFile("agreement.pdf");
var signature = new PdfSignature("certificate.pfx", "pfx-password");
pdf.Sign(signature);

// Populate named form fields with dynamic application data
pdf.Form.FindFormField("CustomerName").Value = "Acme Corporation";
pdf.Form.FindFormField("ContractDate").Value = DateTime.Now.ToString("yyyy-MM-dd");
pdf.Form.FindFormField("Amount").Value = "$12,500.00";

pdf.SaveAs("signed-agreement.pdf");
using IronPdf;
using IronPdf.Signing;

// Load an existing PDF and apply a digital signature using an X.509 certificate
var pdf = PdfDocument.FromFile("agreement.pdf");
var signature = new PdfSignature("certificate.pfx", "pfx-password");
pdf.Sign(signature);

// Populate named form fields with dynamic application data
pdf.Form.FindFormField("CustomerName").Value = "Acme Corporation";
pdf.Form.FindFormField("ContractDate").Value = DateTime.Now.ToString("yyyy-MM-dd");
pdf.Form.FindFormField("Amount").Value = "$12,500.00";

pdf.SaveAs("signed-agreement.pdf");
$vbLabelText   $csharpLabel

Example Verified Signature

Adobe Acrobat showing a verified digital signature panel on a PDF signed with IronPDF's PdfSignature API

Digital signatures use X.509 certificates in PFX format and comply with PDF signature standards recognized by Adobe Acrobat and other PDF viewers. The signature panel in Acrobat confirms the certificate issuer, signing time, and integrity status. The PDF forms API supports text fields, checkboxes, radio buttons, and dropdown menus. You can create form templates programmatically, populate them with data at runtime, and read submitted field values from filled documents. This pattern is useful for contract management, HR onboarding, and automated data collection pipelines where the same PDF template is reused across many transactions with different field values.

For timestamp-based signatures, pass a PdfSignature instance configured with a timestamp server URI so that the signing time is certified by a trusted third party rather than the local system clock. The signing guide covers visible signature images, multiple sequential signers, and certificate validation options.

How Do You Edit and Manipulate Existing PDF Documents?

IronPDF lets you modify PDF files without rebuilding them from HTML. Add headers, footers, watermarks, annotations, or merge and split pages programmatically.

using IronPdf;

var document = PdfDocument.FromFile("report.pdf");

// Add a semi-transparent watermark using HTML
document.ApplyWatermark("<h2 style='color:red; opacity:0.4; transform:rotate(-30deg)'>CONFIDENTIAL</h2>",
    rotation: 30, opacity: 50);

// Add a branded header to every page
document.AddHtmlHeaders(new HtmlHeaderFooter
{
    HtmlFragment = "<div style='text-align:right; font-size:10px; color:#666'>Internal Use Only - Page {page} of {total-pages}</div>"
});

// Append supplementary pages from a second document
var appendix = PdfDocument.FromFile("appendix.pdf");
document.AppendPdf(appendix);

document.SaveAs("final-report.pdf");

// Export to bytes for HTTP streaming
byte[] pdfBytes = document.BinaryData;
using IronPdf;

var document = PdfDocument.FromFile("report.pdf");

// Add a semi-transparent watermark using HTML
document.ApplyWatermark("<h2 style='color:red; opacity:0.4; transform:rotate(-30deg)'>CONFIDENTIAL</h2>",
    rotation: 30, opacity: 50);

// Add a branded header to every page
document.AddHtmlHeaders(new HtmlHeaderFooter
{
    HtmlFragment = "<div style='text-align:right; font-size:10px; color:#666'>Internal Use Only - Page {page} of {total-pages}</div>"
});

// Append supplementary pages from a second document
var appendix = PdfDocument.FromFile("appendix.pdf");
document.AppendPdf(appendix);

document.SaveAs("final-report.pdf");

// Export to bytes for HTTP streaming
byte[] pdfBytes = document.BinaryData;
$vbLabelText   $csharpLabel

Example Output

PDF document with IronPDF-added confidential watermark and branded header showing page numbers and appended appendix pages

The HTML headers and footers API supports template variables including {page}, {total-pages}, and {date} for dynamic content. The custom watermark method accepts an HTML fragment so you can apply styled, rotated, semi-transparent overlays across all pages in one call. You can also split PDFs by page range, merge multiple documents, and extract embedded images and text content from any PDF. Text extraction preserves reading order across columns and tables, which simplifies downstream processing for search indexing, content migration, or data validation workflows.

How Do You Apply Password Protection and Security Settings?

Protecting PDF documents with passwords and permission flags is a standard requirement for financial reports, legal documents, and HR records.

using IronPdf;
using IronPdf.Security;

var pdf = PdfDocument.FromFile("financial-report.pdf");

// Set passwords: UserPassword controls opening, OwnerPassword controls editing
pdf.SecuritySettings.UserPassword = "viewer-password";
pdf.SecuritySettings.OwnerPassword = "admin-password";

// Configure fine-grained permissions
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.PrintLowResolution;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserFormData = false;

pdf.SaveAs("protected-report.pdf");
using IronPdf;
using IronPdf.Security;

var pdf = PdfDocument.FromFile("financial-report.pdf");

// Set passwords: UserPassword controls opening, OwnerPassword controls editing
pdf.SecuritySettings.UserPassword = "viewer-password";
pdf.SecuritySettings.OwnerPassword = "admin-password";

// Configure fine-grained permissions
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.PrintLowResolution;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserFormData = false;

pdf.SaveAs("protected-report.pdf");
$vbLabelText   $csharpLabel

The PDF security settings API applies 128-bit or 256-bit AES encryption. Setting UserPassword requires readers to enter the password when opening the file in any PDF viewer. Setting OwnerPassword restricts programmatic modification and owner-level operations. The permission flags control printing quality, text selection, annotations, and form field access independently. After applying security settings, the BinaryData property returns the encrypted PDF bytes for storage or HTTP transmission. These settings conform to the PDF specification's access control model, so protected documents open correctly in Adobe Acrobat, browser-based PDF viewers, and mobile reading applications.

To remove protection from a document you own, load the file with the owner password passed as a parameter to PdfDocument.FromFile, then save without security settings applied. This allows programmatic document processing in server-side workflows where password-protected files arrive as inputs and must be transformed before redistribution.

What Are Your Next Steps?

IronPDF's PDF API for .NET Core handles the full document lifecycle in C#: generating from HTML strings and URLs, converting DOCX and image files, configuring page layout and rendering options, editing watermarks, headers, and footers, applying digital signatures, and protecting documents with encryption. All operations use a consistent API across .NET 8, .NET 9, and .NET 10 on Windows, macOS, and Linux.

Start a free trial to evaluate IronPDF with your own documents. For additional scenarios, explore the HTML to PDF rendering options guide, PDF compression and optimization, and the complete IronPDF feature overview. Review licensing options for production deployment.

Frequently Asked Questions

What is IronPDF's PDF API for .NET Core?

IronPDF is a .NET library that generates, converts, and edits PDF documents in C# applications. It installs as a single NuGet package and supports .NET 10, .NET 9, .NET 8, and .NET Framework 4.6.2 or later.

How do you generate a PDF from HTML in .NET Core?

Create a ChromePdfRenderer instance and call RenderHtmlAsPdf with an HTML string, or RenderUrlAsPdfAsync with a URL. The renderer converts HTML, CSS, and JavaScript output to a PdfDocument object that you can save or stream.

How do you configure page size and margins in IronPDF?

Set properties on renderer.RenderingOptions before calling a render method. Use PaperSize for standard formats, PaperOrientation for portrait or landscape, and MarginTop, MarginBottom, MarginLeft, MarginRight for millimeter-based margins.

Can IronPDF convert DOCX files to PDF in .NET Core?

Yes. Use DocxToPdfRenderer.RenderDocxAsPdf with the file path. The converter preserves paragraph styles, tables, headers, footers, and embedded images from the source Word document.

How do you add a digital signature to a PDF in C#?

Load the PDF with PdfDocument.FromFile, create a PdfSignature with the PFX certificate path and password, then call pdf.Sign(signature). The resulting document shows as verified in Adobe Acrobat and compliant PDF viewers.

How do you password-protect a PDF using IronPDF?

Set pdf.SecuritySettings.UserPassword for the open password and pdf.SecuritySettings.OwnerPassword for the owner password. Use AllowUserPrinting, AllowUserCopyPasteContent, and related flags to control individual permissions.

How do you return a generated PDF as an HTTP response in ASP.NET Core?

Access the BinaryData property on the PdfDocument instance to retrieve the PDF as a byte array, then return it with File(pdfBytes, 'application/pdf', 'filename.pdf') in an ASP.NET Core controller action.

Does IronPDF work on Linux and macOS for .NET Core applications?

Yes. IronPDF runs on Windows, macOS, and Linux without additional native runtime dependencies. It supports containerized deployments to Docker, Azure, and AWS without platform-specific configuration.

How do you add headers and footers to a PDF with IronPDF?

Call document.AddHtmlHeaders with an HtmlHeaderFooter object whose HtmlFragment contains the header markup. Use template variables {page}, {total-pages}, and {date} for dynamic values. The same API applies to footers.

Is IronPDF thread-safe for use in ASP.NET Core?

ChromePdfRenderer is thread-safe and can be registered as a singleton in the dependency injection container. For high-throughput workloads, use the async render methods (RenderHtmlAsPdfAsync, RenderUrlAsPdfAsync) to avoid blocking request threads.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me