IRONSOFTWAREHOME

How to Export and Save PDFs in IronPDF C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

IronPDF exports a rendered PdfDocument to PDF in C# through SaveAs for disk, the Stream and BinaryData properties for memory, and SaveAsPdfA, SaveAsPdfUA, and SaveAsRevision for archival, accessible, and versioned output. Each method takes a document you already rendered and writes it to the destination your application needs, whether that is a file path, an in-memory buffer, or an HTTP response.

This guide walks through every export target, from a one-line file save to serving a PDF directly to a browser, and the methods that produce conformance-tagged output.

Quickstart: Export HTML to PDF in C#

Render HTML and write the result to disk in a single statement. The RenderHtmlAsPdf call returns a PdfDocument, and SaveAs persists it.

  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 2Copy and run this code snippet.

    new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>HelloPDF</h1>").SaveAs("myExportedFile.pdf");
    C#
  3. 3Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

What Are the Options for Saving PDFs?

IronPDF saves a PdfDocument to four kinds of destination: a file on disk, an in-memory MemoryStream, a raw byte[], and a conformance-tagged file for archiving, accessibility, or incremental revision. The sections below cover each target with a tested example, starting with the simplest file save and ending with the specialized export methods.

How to Save a PDF to Disk

Use the SaveAs method to write a PdfDocument to a file path. This is the direct route for desktop applications or any server process that keeps PDFs on the file system.

// Complete example for saving PDF to disk
using IronPdf;

// Initialize the Chrome PDF renderer
var renderer = new ChromePdfRenderer();

// Create HTML content with styling
string htmlContent = @"
<html>
<head>
    <style>
        body { font-family: Arial, sans-serif; margin: 40px; }
        h1 { color: #333; }
        .content { line-height: 1.6; }
    </style>
</head>
<body>
    <h1>Invoice #12345</h1>
    <div class='content'>
        <p>Date: " + DateTime.Now.ToString("yyyy-MM-dd") + @"</p>
        <p>Thank you for your business!</p>
    </div>
</body>
</html>";

// Render HTML to PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);

// Save to disk with standard method
pdf.SaveAs("invoice_12345.pdf");

// Save with password protection for sensitive documents
pdf.Password = "secure123";
pdf.SaveAs("protected_invoice_12345.pdf");

The same example also sets the Password property before a second save, which encrypts the file so it cannot open without that password. For finer control over what a recipient can do with the file, see the guide on PDF permissions and passwords.

Output

How to Save a PDF to a MemoryStream

The Stream property returns the document as a System.IO.MemoryStream. Reach for it when you need to hand the PDF to another method, upload it, or email it without writing a temporary file first. Read more on working with PDF memory streams.

// Example: Save PDF to MemoryStream
using IronPdf;
using System.IO;

var renderer = new ChromePdfRenderer();

// Render HTML content
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Monthly Report</h1><p>Sales figures...</p>");

// Get the PDF as a MemoryStream
MemoryStream stream = pdf.Stream;

// Example: Upload to cloud storage or database
// UploadToCloudStorage(stream);

// Example: Email as attachment without saving to disk
// EmailService.SendWithAttachment(stream, "report.pdf");

// Remember to dispose of the stream when done
stream.Dispose();

Output

How to Save to Binary Data

The BinaryData property returns the document as a byte[]. A byte array suits database columns, cache entries, and APIs that accept raw bytes rather than a stream.

// Example: Convert PDF to binary data
using IronPdf;

var renderer = new ChromePdfRenderer();

// Configure rendering options for better quality
renderer.RenderingOptions = new ChromePdfRenderOptions()
{
    MarginTop = 20,
    MarginBottom = 20,
    MarginLeft = 10,
    MarginRight = 10,
    PaperSize = IronPdf.Rendering.PdfPaperSize.A4
};

// Render content to PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Contract Document</h1>");

// Get binary data
byte[] binaryData = pdf.BinaryData;

// Example: Store in database
// database.StorePdfDocument(documentId, binaryData);

// Example: Send via API
// apiClient.UploadDocument(binaryData);

When you need the reverse direction, loading bytes back into an editable document, the guide on converting PDFs to a MemoryStream covers it.

Output

How Do I Serve a PDF from a Web Server to the Browser?

To return a PDF over HTTP you send the bytes as a file response, not as HTML. Both Stream and BinaryData plug straight into the file-result types that ASP.NET provides, so the controller renders a document and returns it without ever touching disk.

How Do I Export a PDF in MVC?

In ASP.NET Core MVC, wrap the Stream in a FileStreamResult to prompt a download, or pass BinaryData to File to display the PDF inline. The two actions below show both. This pairs naturally with rendering CSHTML views to PDF.

// MVC controller methods for PDF export
public IActionResult DownloadInvoice(int invoiceId)
{
    // Generate your HTML content
    string htmlContent = GenerateInvoiceHtml(invoiceId);

    // Render the PDF with IronPDF
    var renderer = new ChromePdfRenderer();
    PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);

    // Take the PDF stream and rewind it
    MemoryStream stream = pdf.Stream;
    stream.Position = 0;

    // Returning a FileStreamResult prompts a download in the browser
    return new FileStreamResult(stream, "application/pdf")
    {
        FileDownloadName = $"invoice_{invoiceId}.pdf"
    };
}

public IActionResult ViewInvoice(int invoiceId)
{
    var renderer = new ChromePdfRenderer();
    PdfDocument pdf = renderer.RenderHtmlAsPdf(GenerateInvoiceHtml(invoiceId));

    // Returning BinaryData with no filename displays the PDF inline
    return File(pdf.BinaryData, "application/pdf");
}
C#

How Do I Export a PDF in ASP.NET WebForms?

Traditional ASP.NET WebForms applications write the bytes through the Response object instead. Configure the rendering options once, pull BinaryData, and stream it to the client.

// ASP.NET WebForms PDF export
protected void ExportButton_Click(object sender, EventArgs e)
{
    var renderer = new ChromePdfRenderer();

    // Configure rendering options
    renderer.RenderingOptions = new ChromePdfRenderOptions()
    {
        PaperSize = IronPdf.Rendering.PdfPaperSize.Letter,
        PrintHtmlBackgrounds = true,
        CreatePdfFormsFromHtml = true
    };

    // Render from custom HTML
    PdfDocument MyPdfDocument = renderer.RenderHtmlAsPdf(GetReportHtml());

    // Retrieve the PDF bytes
    byte[] Binary = MyPdfDocument.BinaryData;

    // Write the bytes to the response as a download
    Response.Clear();
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition",
        "attachment; filename=report_" + DateTime.Now.ToString("yyyyMMdd") + ".pdf");
    Context.Response.OutputStream.Write(Binary, 0, Binary.Length);
    Response.Flush();
    Response.End();
}
C#

My favorite library of this kind is IronPDF. It allows for fast and efficient manipulation of PDF files. It also has many valuable features, like exporting to PDF/A format and digitally signing PDF documents.

Milan Jovanovic

Microsoft MVP

View case study

IronOCR means we can save $40,000 annually from manual processing, while enhancing productivity and freeing up resources for high-impact tasks. I would highly recommend it.

Brent Matzelle

Chief Technology Officer, OPYN

View case study

The IronSuite play a crucial role in our operations. These are tools that increase efficiencies across the business including creating floor plans and improving inventory management.

David Jones

Lead Software Engineer, Agorus Build

View case study

How Do I Export PDF/A, PDF/UA, and Revisions?

Beyond the general save targets, IronPDF writes three conformance-specific formats. SaveAsPdfA produces an archival file, SaveAsPdfUA produces a tagged accessible file, and SaveAsRevision appends an incremental revision to an existing document.

How to Save a PDF/A Archive

SaveAsPdfA writes a self-contained file that meets the ISO PDF/A standard for long-term storage, embedding the fonts and color data a reader needs years from now. The PdfAVersions argument selects the conformance level, such as PdfA3b.

using IronPdf;

var renderer = new ChromePdfRenderer();

// Render the document you want to archive
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Archived Document</h1>");

// Save as a PDF/A-3b file for long-term archiving.
// PdfAVersions controls the conformance level (PdfA1b, PdfA2b, PdfA3b, PdfA4, and others).
pdf.SaveAsPdfA("archive-pdfa.pdf", IronPdf.PdfAVersions.PdfA3b);
C#

Output

How to Save an Accessible PDF/UA File

SaveAsPdfUA writes a tagged PDF that meets the PDF/UA accessibility standard, which screen readers rely on to navigate the document. The third argument sets the document language so assistive technology reads it with the right voice.

using IronPdf;

var renderer = new ChromePdfRenderer();

// Render content that should be tagged for assistive technology
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Accessible Document</h1><p>Tagged for screen readers.</p>");

// Save as a PDF/UA-1 file. The last argument sets the document's primary
// language, which screen readers use to choose the correct voice.
pdf.SaveAsPdfUA("accessible-pdfua.pdf", IronPdf.PdfUAVersions.PdfUA1, IronPdf.NaturalLanguages.English_UnitedKingdom);
C#

Output

How to Save an Incremental Revision

SaveAsRevision appends changes to a file instead of rewriting it, so earlier revisions, including any digital signatures, stay intact. The document must be opened with ChangeTrackingModes.EnableChangeTracking for the incremental save to work.

using IronPdf;
using IronPdf.Rendering;

var renderer = new ChromePdfRenderer();

// Create and save the original revision of the document
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Versioned Document</h1>");
pdf.SaveAs("revision-base.pdf");

// Re-open with change tracking enabled so the next save appends a revision
// instead of rewriting the file. This preserves earlier signed revisions.
PdfDocument loaded = PdfDocument.FromFile("revision-base.pdf", null, null, ChangeTrackingModes.EnableChangeTracking);

// Write an incremental revision on top of the existing bytes
loaded.SaveAsRevision("revision-v2.pdf");
C#

Output

How Do I Export a PDF Asynchronously?

Rendering blocks the calling thread until the Chromium engine finishes. In a web request or a desktop UI, call RenderHtmlAsPdfAsync instead and await it, then save the returned document with the same SaveAs method. This keeps the thread free while the render runs.

using IronPdf;
using System.Threading.Tasks;

var renderer = new ChromePdfRenderer();

// Render off the calling thread so a web request or UI stays responsive
PdfDocument pdf = await renderer.RenderHtmlAsPdfAsync("<h1>Async Generated PDF</h1>");

// SaveAs writes the finished document to disk once the render completes
pdf.SaveAs("async-render.pdf");
C#

Output

Conclusion

IronPDF exports a rendered PdfDocument to disk, memory, an HTTP response, or a conformance-tagged file, each through a single method on the document you already built. Pick the target that matches where the bytes need to go, and apply SaveAsPdfA, SaveAsPdfUA, or SaveAsRevision when the output has to meet an archival, accessibility, or versioning standard.

From here, keep the bytes off disk entirely with the PDF memory stream workflow, or lock down a saved file using PDF permissions and passwords.

Frequently Asked Questions

How can I save a PDF to disk using IronPDF in C#?

To save a PDF to disk in C#, you can use IronPDF's `SaveAs` method. After rendering your HTML content to a `PdfDocument`, you simply call `pdf.SaveAs("filename.pdf")` to write the PDF to a specified file path.

Can I export a PDF to an in-memory stream with IronPDF?

Yes, IronPDF allows exporting a PDF to an in-memory `MemoryStream`. You can access the `Stream` property of a `PdfDocument`, which returns the document as a `MemoryStream`, making it suitable for further operations like uploading or emailing without creating a temporary file.

What is the process for saving a PDF as binary data in IronPDF?

IronPDF provides a `BinaryData` property that returns the PDF as a `byte[]`. This binary data can be stored in databases, cache entries, or sent through APIs that handle raw bytes.

How do I serve a PDF from a web server to a browser using IronPDF?

To serve a PDF from a web server using IronPDF, you can send the document bytes as a file response using ASP.NET's `FileStreamResult` or `File` in MVC, or through `Response` in WebForms. Both `Stream` and `BinaryData` can be used to directly provide the PDF data to the client.

What are the specific formats supported for PDF export in IronPDF?

IronPDF supports exporting PDFs in formats such as PDF/A for long-term archival, PDF/UA for accessibility compliance, and incremental revisions for versioned documents using methods like `SaveAsPdfA`, `SaveAsPdfUA`, and `SaveAsRevision`.

How do I asynchronously export a PDF using IronPDF in a responsive application?

To asynchronously export a PDF while keeping the application responsive, use the `RenderHtmlAsPdfAsync` method from IronPDF, await its completion, and then use the `SaveAs` method to save the document once rendering is done.

Can I password-protect a PDF using IronPDF?

Yes, IronPDF allows you to set a password on a `PdfDocument` via the `Password` property before saving it. This ensures that a PDF cannot be opened without the correct password.

What should I do if I need an accessible PDF conforming to PDF/UA standards?

You can create a PDF that conforms to PDF/UA standards using IronPDF by calling the `SaveAsPdfUA` method. This ensures that the document includes tags to aid navigation by screen readers.

How can I keep different versions of a PDF document?

IronPDF supports incremental saves with the `SaveAsRevision` method, which appends changes to an existing PDF file while preserving previous revisions, ideal for maintaining version history.

Why should I consider exporting PDFs using the PDF/A format?

Exporting PDFs in PDF/A format ensures that the document is self-contained and suitable for long-term archiving, as it includes all necessary components like fonts and color data to ensure fidelity over time.

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

Ready to Get Started?

Nuget Downloads 20,809,720Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999

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