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 do I export HTML content to PDF in C#?

You can export HTML to PDF in C# using IronPDF's ChromePdfRenderer class. Simply create a renderer instance, use the RenderHtmlAsPdf() method to convert your HTML content, and then save it using the SaveAs() method. IronPDF makes it easy to convert HTML strings, files, or URLs directly to PDF documents.

What are the different methods to save a PDF using C#?

IronPDF provides multiple methods to save PDFs: SaveAs() for saving to disk, Stream for serving PDFs in web applications without creating temporary files, and BinaryData for getting the PDF as a byte array. Each method in IronPDF serves different use cases, from simple file storage to dynamic web delivery.

Can I save a PDF to memory instead of disk?

Yes, IronPDF allows you to save PDFs to memory using System.IO.MemoryStream. This is useful for web applications where you want to serve PDFs directly to users without creating temporary files on the server. You can use the Stream property or convert the PDF to binary data.

How do I add password protection when saving a PDF?

IronPDF enables password protection by setting the Password property on the PdfDocument object before saving. Simply assign a password string to pdf.Password and then use SaveAs() to create a protected PDF file that requires the password to open.

Can I serve a PDF directly to web browsers without saving to disk?

Yes, IronPDF allows you to serve PDFs directly to web browsers as binary data. You can use the BinaryData property to get the PDF as a byte array and serve it through your web application's response stream, eliminating the need for temporary file storage.

What's the simplest way to convert and save HTML as PDF in one line?

IronPDF provides a one-line solution: new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("Your HTML").SaveAs("output.pdf"). This creates a renderer, converts HTML to PDF, and saves it to disk in a single statement.

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,389,208Version:2026.8just 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

Try IronPDF for Free

Get Set Up in 5 Minutes

C# PDF DLL

Download DLL

Download Now

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"
C# NuGet Library for PDF

Install with NuGet

                  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
Key in blue circle

Get your free 30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
  • 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 related to IronPDF Product Demo

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