# How to Export and Save PDFs in IronPDF C#
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.
*as-heading:2(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.
```cs
:title=Export or save your PDF in one line!
new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>HelloPDF</h1>").SaveAs("myExportedFile.pdf");
```
<div class="hsg-featured-snippet">
<h3>Minimal Workflow (5 steps)</h3>
<ol>
<li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://www.nuget.org/packages/IronPdf/">Download the C# PDF library from NuGet</a></li>
<li>Render or load a <code>PdfDocument</code></li>
<li>Save to disk with <code>SaveAs</code>, or to memory with <code>Stream</code> and <code>BinaryData</code></li>
<li>Serve the bytes to the web as a file response rather than HTML</li>
<li>Export conformant output with <code>SaveAsPdfA</code>, <code>SaveAsPdfUA</code>, or <code>SaveAsRevision</code></li>
</ol>
</div>
<br class="clear" />
## 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.
```csharp
// 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](https://ironpdf.com/how-to/pdf-permissions-passwords/).
### Output
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/save-to-disk.pdf" width="100%" height="500px"></iframe>
### 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](https://ironpdf.com/how-to/pdf-memory-stream/).
```csharp
// 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
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/memory-stream.pdf" width="100%" height="500px"></iframe>
### 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.
```csharp
// 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](https://ironpdf.com/how-to/pdf-to-memory-stream/) covers it.
### Output
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/binary-data.pdf" width="100%" height="500px"></iframe>
## 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](https://ironpdf.com/how-to/cshtml-to-pdf-mvc-core/).
```csharp
// 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");
}
```
### 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.
```csharp
// 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();
}
```
## 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`.
```csharp
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);
```
### Output
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/archive-pdfa.pdf" width="100%" height="500px"></iframe>
### 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.
```csharp
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);
```
### Output
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/accessible-pdfua.pdf" width="100%" height="500px"></iframe>
### 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.
```csharp
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");
```
### Output
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/revision-v2.pdf" width="100%" height="500px"></iframe>
## 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.
```csharp
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");
```
### Output
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/async-render.pdf" width="100%" height="500px"></iframe>
## 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](https://ironpdf.com/how-to/pdf-memory-stream/) workflow, or lock down a saved file using [PDF permissions and passwords](https://ironpdf.com/how-to/pdf-permissions-passwords/).
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.
Save to disk with SaveAs, or to memory with Stream and BinaryData
Serve the bytes to the web as a file response rather than HTML
Export conformant output with SaveAsPdfA, SaveAsPdfUA, or SaveAsRevision
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 diskusing IronPdf;// Initialize the Chrome PDF renderervar renderer = new ChromePdfRenderer();// Create HTML content with stylingstring 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 PDFPdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);// Save to disk with standard methodpdf.SaveAs("invoice_12345.pdf");// Save with password protection for sensitive documentspdf.Password = "secure123";pdf.SaveAs("protected_invoice_12345.pdf");
// 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");
IRONVBCONVERTERERROR developers@ironsoftware.com
IRON VB CONVERTER ERROR developers@ironsoftware.com
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 MemoryStreamusing IronPdf;using System.IO;var renderer = new ChromePdfRenderer();// Render HTML contentPdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Monthly Report</h1><p>Sales figures...</p>");// Get the PDF as a MemoryStreamMemoryStream 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 donestream.Dispose();
// 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();
ImportsIronPdfImportsSystem.IO' Example: Save PDF to MemoryStreamDim renderer As New ChromePdfRenderer()' Render HTML contentDim pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Monthly Report</h1><p>Sales figures...</p>")' Get the PDF as a MemoryStreamDim stream AsMemoryStream = 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 donestream.Dispose()
Imports IronPdf
Imports System.IO
' Example: Save PDF to MemoryStream
Dim renderer As New ChromePdfRenderer()
' Render HTML content
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Monthly Report</h1><p>Sales figures...</p>")
' Get the PDF as a MemoryStream
Dim stream As MemoryStream = 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 datausing IronPdf;var renderer = new ChromePdfRenderer();// Configure rendering options for better qualityrenderer.RenderingOptions = new ChromePdfRenderOptions(){MarginTop = 20,MarginBottom = 20,MarginLeft = 10,MarginRight = 10,PaperSize = IronPdf.Rendering.PdfPaperSize.A4};// Render content to PDFPdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Contract Document</h1>");// Get binary databyte[] binaryData = pdf.BinaryData;// Example: Store in database// database.StorePdfDocument(documentId, binaryData);// Example: Send via API// apiClient.UploadDocument(binaryData);
// 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);
ImportsIronPdf' Example: Convert PDF to binary dataDim renderer As New ChromePdfRenderer()' Configure rendering options for better qualityrenderer.RenderingOptions = New ChromePdfRenderOptions() With { .MarginTop = 20, .MarginBottom = 20, .MarginLeft = 10, .MarginRight = 10, .PaperSize = IronPdf.Rendering.PdfPaperSize.A4}' Render content to PDFDim pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Contract Document</h1>")' Get binary dataDim binaryData AsByte() = pdf.BinaryData' Example: Store in database' database.StorePdfDocument(documentId, binaryData)' Example: Send via API' apiClient.UploadDocument(binaryData)
Imports IronPdf
' Example: Convert PDF to binary data
Dim renderer As New ChromePdfRenderer()
' Configure rendering options for better quality
renderer.RenderingOptions = New ChromePdfRenderOptions() With {
.MarginTop = 20,
.MarginBottom = 20,
.MarginLeft = 10,
.MarginRight = 10,
.PaperSize = IronPdf.Rendering.PdfPaperSize.A4
}
' Render content to PDF
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Contract Document</h1>")
' Get binary data
Dim binaryData As Byte() = 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 exportpublic IActionResultDownloadInvoice(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 IActionResultViewInvoice(int invoiceId){ var renderer = new ChromePdfRenderer(); PdfDocument pdf = renderer.RenderHtmlAsPdf(GenerateInvoiceHtml(invoiceId)); // Returning BinaryData with no filename displays the PDF inline returnFile(pdf.BinaryData, "application/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 exportprotected voidExportButton_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 PdfDocumentMyPdfDocument = renderer.RenderHtmlAsPdf(GetReportHtml()); // Retrieve the PDF bytes byte[] Binary = MyPdfDocument.BinaryData; // Write the bytes to the response as a downloadResponse.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();}
// 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.
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.
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.
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 archivePdfDocument 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);
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 technologyPdfDocument 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);
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 documentPdfDocument 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 bytesloaded.SaveAsRevision("revision-v2.pdf");
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 responsivePdfDocument pdf = await renderer.RenderHtmlAsPdfAsync("<h1>Async Generated PDF</h1>");// SaveAs writes the finished document to disk once the render completespdf.SaveAs("async-render.pdf");
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.
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 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.