# 如何在IronPDF C#中导出并保存PDF
IronPDF通过`SaveAsRevision`用于存档、可访问和版本化输出。 每种方法接收一个您已渲染的文档,并将其写入您的应用程序需要的目的地,无论是文件路径,内存缓冲区,或HTTP响应。
本指南逐步介绍每个导出目标,从一行文件保存到直接向浏览器提供PDF,以及产生合规标签输出的方法。
*as-heading:2(快速入门:在C#中导出HTML为PDF)*
渲染HTML并在一个语句中将结果写入磁盘。 `SaveAs`持久化它。
```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>最小工作流程(5 个步骤)</h3>
<ol>
<li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://www.nuget.org/packages/IronPdf/">从NuGet下载C# PDF库</a></li>
<li>渲染或加载<code>PdfDocument</code></li>
<li>使用<code>SaveAs</code>保存到磁盘,或使用<code>Stream</code>和<code>BinaryData</code>保存到内存</li>
<li>将字节作为文件响应提供给网络,而不是HTML</li>
<li>使用<code>SaveAsPdfA</code>、<code>SaveAsPdfUA</code>或<code>SaveAsRevision</code>导出符合输出标准的文件</li>
</ol>
</div>
<br class="clear" />
## 保存PDF有哪些选项?
IronPDF将`byte[]`,以及用于存档、可访问性或增量修订的符合标准标记的文件。 以下各节提供每个目标的经过测试的示例,从最简单的文件保存开始,最后是专用的导出方法。
### 如何将PDF保存到磁盘
使用`PdfDocument`写入文件路径。 这是桌面应用程序或任何将PDF保存在文件系统上的服务器进程的直接路线。
```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");
```
相同的示例还在第二次保存之前设置`Password`属性,这会加密文件,以便没有该密码无法打开它。 欲获得对收件人可以对文件做什么的更精细控制,请参阅[PDF权限和密码](https://ironpdf.com/how-to/pdf-permissions-passwords/)指南。
### 输出
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/save-to-disk.pdf" width="100%" height="500px"></iframe>
### 如何将PDF保存到MemoryStream
`System.IO.MemoryStream`形式返回。 当你需要将PDF交给另一个方法、上传或通过电子邮件发送而不先写入临时文件时,这非常有用。请阅读更多[关于处理PDF内存流的信息](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();
```
### 输出
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/memory-stream.pdf" width="100%" height="500px"></iframe>
### 如何保存为二进制数据
`byte[]`形式返回。 字节数组适合数据库列、缓存条目和接受原始字节而不是流的API。
```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);
```
当您需要反向操作,即将字节重新加载到可编辑文档中,[将PDF转换为MemoryStream的指南](https://ironpdf.com/how-to/pdf-to-memory-stream/)涵盖了这一内容。
### 输出
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/binary-data.pdf" width="100%" height="500px"></iframe>
## 如何从Web服务器将PDF提供到浏览器?
要通过HTTP返回PDF,您发送字节作为文件响应,而不是HTML。 `BinaryData`直接插入ASP.NET提供的文件结果类型,因此控制器渲染一个文档并返回它,而无需接触磁盘。
### 如何在MVC中导出PDF?
在ASP.NET Core MVC中,将`File`显示PDF内联。以下两个操作展示了两者。 这与渲染[CSHTML视图为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");
}
```
### 如何在ASP.NET WebForms中导出PDF?
传统ASP.NET WebForms应用程序通过`Response`对象写入字节。 配置渲染选项一次,拉取`BinaryData`,并将其流式传输给客户端。
```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();
}
```
## 如何导出PDF/A、PDF/UA和修订版?
除了常规的保存目标外,IronPDF写入三种符合规范的格式。 `SaveAsRevision`将增量修订附加到现有文档。
### 如何保存PDF/A存档?
`SaveAsPdfA`写入符合ISO PDF/A标准的自包含文件,以用于长期存储,嵌入字体和颜色数据以供多年后阅读所需。 `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);
```
### 输出
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/archive-pdfa.pdf" width="100%" height="500px"></iframe>
### 如何保存可访问的PDF/UA文件?
`SaveAsPdfUA`写入符合PDF/UA无障碍标准的标记PDF,屏幕阅读器依赖其来导航文档。 第三个参数设置文档语言,以便辅助技术用正确的声音朗读。
```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);
```
### 输出
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/accessible-pdfua.pdf" width="100%" height="500px"></iframe>
### 如何保存增量修订版?
`SaveAsRevision`将更改附加到文件,而不是重写它,因此早期的修订,包括任何数字签名,保持不变。 必须用`ChangeTrackingModes.EnableChangeTracking`打开该文档,增量保存才能生效。
```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");
```
### 输出
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/revision-v2.pdf" width="100%" height="500px"></iframe>
## 如何异步导出PDF?
渲染阻止调用线程,直到Chromium引擎完成。 在Web请求或桌面UI中,改为调用`SaveAs`方法保存返回的文档。 这使线程在渲染运行时保持空闲。
```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");
```
### 输出
<iframe loading="lazy" src="/static-assets/pdf/how-to/export-save-pdf-csharp/async-render.pdf" width="100%" height="500px"></iframe>
## 结论
IronPDF将渲染的`PdfDocument`导出到磁盘、内存、HTTP响应或符合标准标记的文件中,每个文件通过您已构建的文档上的单个方法。 选择与字节需要去向匹配的目标,并在输出必须符合存档、无障碍或版本标准时应用`SaveAsRevision`。
从这里开始,使用[PDF内存流工作流](https://ironpdf.com/how-to/pdf-memory-stream/)将字节完全保留在磁盘之外,或者使用[PDF权限和密码](https://ironpdf.com/how-to/pdf-permissions-passwords/)锁定保存的文件。
// 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
// 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()
输出
如何保存为二进制数据
byte[]形式返回。 字节数组适合数据库列、缓存条目和接受原始字节而不是流的API。
// 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)
// 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");
}
// 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#
我最喜欢的这种库是 IronPDF。它允许快速高效地操作 PDF 文件。它还具有许多有价值的功能,比如导出为 PDF/A 格式和数字签名 PDF 文档。
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);
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);
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");
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");
是的,IronPDF 允许您将 PDF 文件作为二进制数据直接提供给网络浏览器。您可以使用 BinaryData 属性以字节数组的形式获取 PDF,并通过网络应用程序的响应流提供 PDF,从而无需临时文件存储。
在一行中将 HTML 转换并保存为 PDF 的最简单方法是什么?
IronPDF 提供了单行解决方案:new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("Your HTML").SaveAs("output.pdf")。只需一条语句,即可创建渲染器、将 HTML 转换为 PDF 并保存到磁盘。
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.