IRONSOFTWAREHOME
USING IRONPDF

How to Convert a Webpage to PDF in ASP.NET

Curtis Chau
Curtis Chau
Updated: July 5, 2026

Converting web pages to PDF in ASP.NET is straightforward with IronPDF's ChromePdfRenderer class, which transforms HTML strings, URLs, and ASPX pages into high-quality PDF documents using just a few lines of C# code.

When you need to generate downloadable reports, invoices, or archival documents in an ASP.NET application, converting web content to PDF is one of the most common requirements. IronPDF gives you a direct path to convert a webpage to PDF in ASP.NET, handling everything from simple HTML strings to fully rendered dynamic web pages -- without requiring any third-party browser installations or complex configuration.

This guide walks through the primary conversion methods available in IronPDF, from basic HTML string rendering to URL-based page capture and ASP.NET Web Forms integration. By the end, you'll have working C# code for each scenario and a clear understanding of when to use each approach.

How Do You Install and Set Up IronPDF?

Before converting any content, install IronPDF into your ASP.NET project. The library is distributed via NuGet and works with .NET 6, .NET 8, .NET 10, and .NET Framework:

PM > Install-Package IronPdf

After installation, add the namespace at the top of your C# file:

using IronPdf;

IronPDF works with both ASP.NET Web Forms and ASP.NET Core applications. It supports Windows Server and IIS deployments, Docker containerization, Azure Functions, and AWS Lambda for cloud-native architectures. Review the installation overview for platform-specific setup details and Linux deployment instructions.

First Step:
arrow pointer

How Do You Convert an HTML String to PDF?

The ChromePdfRenderer class is the main entry point for PDF generation in IronPDF. When you have HTML content as a string -- whether generated dynamically or loaded from a template -- the RenderHtmlAsPdf method converts it directly to a PDF document.

This approach is ideal for generating reports, invoices, and receipts where you construct the HTML programmatically from database records or application data. The renderer processes the HTML using the same Chromium-based engine that powers modern browsers, so CSS layouts, web fonts, and standard HTML5 elements all render correctly.

using IronPdf;

var renderer = new ChromePdfRenderer();

string htmlContent = @"
    <h1>Quarterly Sales Report</h1>
    <p>Q3 2025 -- Summary of key revenue metrics and product performance.</p>
    <table>
        <thead><tr><th>Product</th><th>Units</th><th>Revenue</th></tr></thead>
        <tbody>
            <tr><td>Widget A</td><td>320</td><td>$8,960</td></tr>
            <tr><td>Widget B</td><td>150</td><td>$6,750</td></tr>
            <tr><td>Widget C</td><td>210</td><td>$3,055.30</td></tr>
        </tbody>
    </table>";

var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("quarterly-report.pdf");

If your HTML references external stylesheets or images using relative paths, provide the base directory as a second argument. This tells IronPDF where to resolve those references:

using IronPdf;

var renderer = new ChromePdfRenderer();

string html = @"
    <link rel='stylesheet' href='styles.css'>
    <h1>Company Report</h1>
    <div>Annual Summary</div>";

// Provide the base path so the renderer can locate relative resources
var pdf = renderer.RenderHtmlAsPdf(html, @"C:\Reports\Assets\");
pdf.SaveAs("annual-report.pdf");

PDF viewer displaying a Q3 2025 quarterly sales report with a summary table showing product sales data including quantities and unit prices, with a grand total of $18,765.30 highlighted for review

For more on asset handling, see the guide on base URLs and asset encoding and the HTML to PDF tutorial for advanced rendering techniques including DataURI image embedding.

How Do You Convert a URL to PDF?

When you need to capture an existing web page -- whether an internal application route or a public URL -- IronPDF's RenderUrlAsPdf method fetches the full page content and converts it to PDF. The output preserves styles, images, and layout exactly as rendered in a browser.

Rendering a Static Web Page

For pages that serve mostly static content, a basic call to RenderUrlAsPdf is sufficient. The method handles SSL certificates, redirects, and content encoding automatically:

using IronPdf;

var renderer = new ChromePdfRenderer();

// Optional: wait a short time for the page to finish loading
renderer.RenderingOptions.WaitFor.RenderDelay(500);

var pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/PDF");
pdf.SaveAs("wikipedia-pdf-article.pdf");

Rendering Pages with JavaScript or Authentication

For pages that require authentication or use JavaScript to load data dynamically, configure the renderer with the appropriate credentials and wait strategy:

using IronPdf;

var renderer = new ChromePdfRenderer();

// Enable JavaScript for pages that load content after the initial HTML response
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.WaitFor.NetworkIdle(500);

// Provide credentials for authenticated internal pages
renderer.LoginCredentials = new ChromeHttpLoginCredentials()
{
    NetworkUsername = "service-account",
    NetworkPassword = "secure-password"
};

var pdf = renderer.RenderUrlAsPdf("https://app.internal/reports/monthly");
pdf.SaveAs("monthly-report.pdf");

Wikipedia homepage showing multiple content sections including featured articles about the 2019 Champion of Champions snooker tournament, current news items, and educational facts, demonstrating how complex web layouts are preserved when converted to PDF

For sites that use session cookies or Windows authentication, review the guide on TLS and system logins. See the complete URL to PDF documentation for a full list of configuration options including cookie handling and custom HTTP headers.

How Do You Convert an ASPX Page to PDF in ASP.NET Web Forms?

For ASP.NET Web Forms applications, IronPDF provides the AspxToPdf class that converts the currently rendered ASPX page directly to a PDF -- without requiring a separate HTTP request or re-rendering the page content.

Basic One-Line ASPX Conversion

Call RenderThisPageAsPdf() inside a page event handler, and IronPDF intercepts the response and replaces it with a PDF download:

using IronPdf;

protected void Page_Load(object sender, EventArgs e)
{
    // Configure paper settings before rendering
    IronPdf.AspxToPdf.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.Letter;
    IronPdf.AspxToPdf.RenderingOptions.MarginTop = 20;
    IronPdf.AspxToPdf.RenderingOptions.MarginBottom = 20;

    // Convert the current ASPX page to PDF and send it to the browser
    IronPdf.AspxToPdf.RenderThisPageAsPdf(
        IronPdf.AspxToPdf.FileBehavior.InBrowser,
        "invoice-" + DateTime.UtcNow.ToString("yyyy-MM-dd") + ".pdf"
    );
}

PDF viewer displaying a converted ASP.NET Web Forms page with a blue 'Convert This Page to PDF' button and preserved application styling and headers, demonstrating successful web-to-PDF conversion in a test environment

This method captures all HTML structure, styles, and dynamic content generated during the page lifecycle. For a full list of ASPX conversion options, see the ASPX to PDF guide and the advanced settings examples.

How Do You Add Headers and Footers to PDF Documents?

Headers and footers are standard for professional reports and invoices. IronPDF supports both text-based and HTML-based headers and footers, with built-in placeholders for dynamic values like page numbers and the current date.

Text and HTML Headers

The TextHeaderFooter class lets you define simple text on the left, center, and right of each page. Placeholders like {page}, {total-pages}, and {date} are populated automatically during rendering. When you need branded headers with logos and custom layouts, use HtmlHeaderFooter instead -- its HTML fragment is processed by the same rendering engine as the document body:

using IronPdf;

var renderer = new ChromePdfRenderer();

// Simple text header with divider line
renderer.RenderingOptions.TextHeader = new TextHeaderFooter()
{
    CenterText = "Quarterly Financial Report",
    LeftText = "Document ID: {document-id}",
    RightText = "{date:yyyy-MM-dd}",
    DrawDividerLine = true,
    FontSize = 10,
    FontFamily = "Arial"
};

// HTML footer with branded layout
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
{
    HtmlFragment = @"
        <div style='border-top: 1px solid #ccc; padding: 8px; font-size: 10px;
                    display: flex; justify-content: space-between;'>
            <span>© 2026 Enterprise Corp</span>
            <span>Page {page} of {total-pages}</span>
            <span>Classification: Internal</span>
        </div>",
    MaxHeight = 40
};

renderer.RenderingOptions.MarginTop = 40;
renderer.RenderingOptions.MarginBottom = 40;

var pdf = renderer.RenderHtmlAsPdf("<h1>Report Content</h1><p>Financial data goes here.</p>");
pdf.SaveAs("report-with-headers.pdf");

PDF viewer showing a monthly report with properly formatted headers including document title and compliance information, footers with page numbers and classification markings, demonstrating professional enterprise document standards

See the headers and footers documentation for the full list of available placeholders and advanced branding patterns.

How Do You Configure PDF Page Layout and Rendering Options?

IronPDF gives you full control over the page layout, margins, DPI, and CSS rendering behavior through the RenderingOptions property. This is where you configure paper size, print vs. screen CSS, and interactive form generation.

Key Rendering Options

using IronPdf;

var renderer = new ChromePdfRenderer();

// Set paper dimensions and orientation
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.Letter;
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait;

// Define margins (values in millimeters)
renderer.RenderingOptions.MarginTop = 25;
renderer.RenderingOptions.MarginBottom = 25;
renderer.RenderingOptions.MarginLeft = 19;
renderer.RenderingOptions.MarginRight = 19;

// Use print-specific CSS rules and set output DPI
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
renderer.RenderingOptions.DPI = 300;

// Preserve HTML form elements as interactive PDF form fields
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;

var pdf = renderer.RenderHtmlAsPdf("<h1>Custom Layout Document</h1><p>Content with configured layout.</p>");
pdf.SaveAs("configured-output.pdf");

PDF viewer displaying a custom layout document with proper formatting, headers, and structured content sections demonstrating various PDF customization options and professional document appearance

The table below summarizes key rendering options and their effect on the output:

Common IronPDF Rendering Options
OptionPurposeExample Value
PaperSizeSets paper dimensions (Letter, A4, Legal, etc.)PdfPaperSize.A4
MarginTop / MarginBottomSets page margins in millimeters25
DPIOutput resolution -- higher values for print quality300
CssMediaTypeChooses between Screen and Print CSS rulesPdfCssMediaType.Print
EnableJavaScriptEnables or disables JavaScript execution during rendertrue
CreatePdfFormsFromHtmlConverts HTML form elements to interactive PDF formstrue
WaitFor.RenderDelayAdds a delay before capturing to allow JS execution500 (ms)

For a full reference of available options, see the rendering options guide. Related guides cover responsive CSS handling and page break control for common layout challenges.

How Do You Generate PDFs in ASP.NET Core MVC?

In ASP.NET Core MVC, you return a PDF directly from a controller action using File(). The pattern is to render an internal URL or HTML string to a PdfDocument object, then return its binary data with the application/pdf MIME type.

Returning a PDF from a Controller Action

The following example renders an internal report URL and returns the result as a file download. The Microsoft ASP.NET Core MVC documentation covers the base Controller class and File() return type in detail:

using IronPdf;
using Microsoft.AspNetCore.Mvc;

public class ReportsController : Controller
{
    public IActionResult GeneratePdf()
    {
        var renderer = new ChromePdfRenderer();

        renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.Letter;
        renderer.RenderingOptions.MarginTop = 20;
        renderer.RenderingOptions.MarginBottom = 20;

        // Add a text footer with page numbers
        renderer.RenderingOptions.TextFooter = new TextHeaderFooter()
        {
            CenterText = "Page {page} of {total-pages}",
            FontSize = 9
        };

        // Build the URL to the internal report page and render it
        string reportUrl = $"{Request.Scheme}://{Request.Host}/reports/quarterly";
        var pdf = renderer.RenderUrlAsPdf(reportUrl);

        return File(pdf.BinaryData, "application/pdf", "quarterly-report.pdf");
    }
}

PDF viewer displaying a quarterly sales report for Q3 2025 with a detailed data table showing four products with quantities and unit prices totaling $18,765.30, demonstrating professional report formatting with proper headers

For Razor view rendering, see CSHTML to PDF conversion and Razor view rendering without HTTP. If your application handles high volumes of PDF requests, review async PDF generation for non-blocking generation patterns that keep the application responsive under load.

What Security and Compliance Features Does IronPDF Support?

Beyond basic PDF generation, IronPDF includes a set of features for organizations that require document security, long-term archiving, or accessibility compliance. These are particularly relevant for finance, healthcare, legal, and government applications where documents must meet defined regulatory standards.

Document Security

Password protection and permissions give you control over who can open, print, edit, or copy content from your PDFs. See the permissions and passwords guide for configuration details.

IronPDF supports digital signing with X.509 certificates, including HSM-based signatures for organizations with strict key management requirements. Review the digital signatures guide.

Archival and Accessibility Compliance

For long-term document archiving in regulated industries, IronPDF can convert standard PDFs to PDF/A format -- the ISO standard for archival-grade documents.

To meet Section 508 and WCAG accessibility requirements, IronPDF supports generating tagged, accessible PDFs conforming to the PDF/UA standard.

Content Redaction and Metadata

Sensitive information can be permanently removed using the redaction features, which eliminates content without leaving recoverable traces. For audit trails and document classification, you can set author, creation date, keywords, and custom metadata fields through the metadata guide.

How Do You Get Started with a Free Trial?

IronPDF is available with a free trial license that includes all features covered in this guide -- PDF generation, security controls, headers and footers, and compliance features. No credit card is required to begin testing.

To explore additional capabilities, review the complete API reference and the code examples library for working implementations covering the most common PDF scenarios. The quickstart guide provides a focused starting point if this is your first project with IronPDF.

For production deployments, explore PDF compression to reduce file sizes, PDF merging and splitting for document management, and OCR capabilities through IronOCR for extracting text from scanned documents. All Iron Software products share compatible licensing and can be used together in the same application.

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

Related Articles

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required