Class Cleaner
The Cleaner class can be used to scan or sanitize (remove any potentially harmful content) PDF document.
Inheritance
Namespace: IronPdf
Assembly: IronPdf.dll
Syntax
public static class Cleaner : Object
Working with PDF generation in IronPDF runs through Cleaner. It can be used to scan or sanitize (remove any potentially harmful content) PDF document.
Cleaner matters when an application needs to configure or invoke PDF generation from C# code. The class encapsulates the related options and behavior in a single object that is set up once and reused across render or processing calls. Typical scenarios include batch generation pipelines, templated document workflows, and integration with existing C# document services.
To use Cleaner, instantiate or obtain it from the relevant entry point in the IronPDF C# API. Key methods include SanitizeWithBitmap, SanitizeWithBitmap, SanitizeWithBitmap, SanitizeWithBitmap. Assign options or invoke methods on the instance to configure or perform the operation. The add remove attachments covers typical usage in C# end to end.
using IronPdf;
// Obtain Cleaner from the relevant entry point in the IronPDF API
void Configure(Cleaner instance)
{
instance.SanitizeWithBitmap();
}For the broader workflow, see the sanitize PDF guide in the IronPDF C# documentation. For broader context, the PDF generation portion of the IronPDF C# API contains related types that work with Cleaner directly. Cleaner exposes additional members beyond those highlighted above; the reference tables on this page list the full set. In application code, treat Cleaner as a configured object that is constructed once and reused across operations rather than instantiated per call. Configuration is generally idempotent: assigning the same property value twice has the same effect as assigning it once. For diagnostic purposes, inspect the relevant Cleaner property after each operation to confirm the configured state. See the constructors, properties, and methods tables below for the complete API surface of Cleaner. Application code typically obtains or instantiates a single Cleaner and shares it across multiple IronPDF operations rather than recreating it per call.
Methods
SanitizeWithBitmap(PdfDocument)
Sanitize PDF by convert PDF To an Bitmap image and convert it back to PDF. Returns a new PdfDocument object with additional zero margins, preserving the original layout.
Declaration
public static PdfDocument SanitizeWithBitmap(PdfDocument pdfDocument)
Parameters
| Type | Name | Description |
|---|---|---|
| PdfDocument | pdfDocument | PDF document to sanitize. |
Returns
| Type | Description |
|---|---|
| PdfDocument |
SanitizeWithBitmap(PdfDocument, ChromePdfRenderOptions)
Sanitize PDF by converting it to a Bitmap image and then back to a PDF, using custom render options.
This method will override the VirtualPaperLayoutManager (PaperFit) and paper size settings on the provided
renderOption object to ensure the sanitized output matches the original document's dimensions.
Other settings, such as margins, will be respected.
- Slower than SanitizeWithSvg(PdfDocument, ChromePdfRenderOptions)
- Visually looks the same
- Result is a non-searchable PDF
Declaration
public static PdfDocument SanitizeWithBitmap(PdfDocument pdfDocument, ChromePdfRenderOptions renderOption)
Parameters
| Type | Name | Description |
|---|---|---|
| PdfDocument | pdfDocument | PDF document to sanitize. |
| ChromePdfRenderOptions | renderOption | Custom render options for the output PDF (margins respected, paper size/fit overridden). |
Returns
| Type | Description |
|---|---|
| PdfDocument |
SanitizeWithBitmap(String)
Sanitize PDF by convert PDF To an Bitmap image and convert it back to PDF. Returns a new PdfDocument object.
Declaration
public static PdfDocument SanitizeWithBitmap(string pdfFilePath)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | pdfFilePath | Path to the PDF file to sanitize. |
Returns
| Type | Description |
|---|---|
| PdfDocument |
SanitizeWithBitmap(String, ChromePdfRenderOptions)
Sanitize PDF by converting it to a Bitmap image and then back to a PDF, using custom render options. Returns a new PdfDocument object.
Declaration
public static PdfDocument SanitizeWithBitmap(string pdfFilePath, ChromePdfRenderOptions renderOption)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | pdfFilePath | Path to the PDF file to sanitize. |
| ChromePdfRenderOptions | renderOption | Custom render options for the output PDF (margins respected, paper size/fit overridden). |
Returns
| Type | Description |
|---|---|
| PdfDocument |
SanitizeWithSvg(PdfDocument)
Sanitize PDF by convert PDF To an SVG image and convert it back to PDF. Returns a new PdfDocument object.
- Quicker than SanitizeWithBitmap(PdfDocument)
- Result is a searchable PDF
- Layout might be inconsistent.
Declaration
public static PdfDocument SanitizeWithSvg(PdfDocument pdfDocument)
Parameters
| Type | Name | Description |
|---|---|---|
| PdfDocument | pdfDocument | PDF document to sanitize. |
Returns
| Type | Description |
|---|---|
| PdfDocument |
SanitizeWithSvg(PdfDocument, ChromePdfRenderOptions)
Sanitize PDF by converting it to an SVG image and then back to a PDF, using custom render options.
This method will override the VirtualPaperLayoutManager (PaperFit) and paper size settings on the provided
renderOption object to ensure the sanitized output matches the original document's dimensions.
Other settings, such as margins, will be respected.
- Quicker than SanitizeWithBitmap(PdfDocument, ChromePdfRenderOptions)
- Result is a searchable PDF
- Layout might be inconsistent.
Declaration
public static PdfDocument SanitizeWithSvg(PdfDocument pdfDocument, ChromePdfRenderOptions renderOption)
Parameters
| Type | Name | Description |
|---|---|---|
| PdfDocument | pdfDocument | PDF document to sanitize. |
| ChromePdfRenderOptions | renderOption | Custom render options for the output PDF (margins respected, paper size/fit overridden). |
Returns
| Type | Description |
|---|---|
| PdfDocument |
SanitizeWithSvg(String)
Sanitize PDF by convert PDF To an SVG image and convert it back to PDF. Returns a new PdfDocument object.
- Quicker than SanitizeWithBitmap(PdfDocument)
- Result is a searchable PDF
- Layout might be inconsistent.
Declaration
public static PdfDocument SanitizeWithSvg(string pdfFilePath)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | pdfFilePath | Path to the PDF file to sanitize. |
Returns
| Type | Description |
|---|---|
| PdfDocument |
SanitizeWithSvg(String, ChromePdfRenderOptions)
Sanitize PDF by converting it to an SVG image and then back to a PDF, using custom render options. Returns a new PdfDocument object.
- Quicker than SanitizeWithBitmap(String, ChromePdfRenderOptions)
- Result is a searchable PDF
- Layout might be inconsistent.
Declaration
public static PdfDocument SanitizeWithSvg(string pdfFilePath, ChromePdfRenderOptions renderOption)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | pdfFilePath | Path to the PDF file to sanitize. |
| ChromePdfRenderOptions | renderOption | Custom render options for the output PDF (margins respected, paper size/fit overridden). |
Returns
| Type | Description |
|---|---|
| PdfDocument |
ScanPdf(PdfDocument, String[])
Scan for any risk that might exists in a PDF.
Declaration
public static CleanerScanResult ScanPdf(PdfDocument pdfDocument, string[] yaraFiles = null)
Parameters
| Type | Name | Description |
|---|---|---|
| PdfDocument | pdfDocument | a PdfDocument object |
| System.String[] | yaraFiles | Optional external yara rule files, this will override the default yara rules |
Returns
| Type | Description |
|---|---|
| CleanerScanResult | scan result as an CleanerScanResult object |
ScanPdf(Byte[], String[])
Scan for any risk that might exists in a PDF.
Declaration
public static CleanerScanResult ScanPdf(byte[] pdfBytes, string[] yaraFiles = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | pdfBytes | a PDF bytes |
| System.String[] | yaraFiles | Optional external yara rule files, this will override the default yara rules |
Returns
| Type | Description |
|---|---|
| CleanerScanResult | scan result as an CleanerScanResult object |
ScanPdf(String, String[])
Scan for any risk that might exists in a PDF.
Declaration
public static CleanerScanResult ScanPdf(string pdfFilePath, string[] yaraFiles = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | pdfFilePath | A PDF File path |
| System.String[] | yaraFiles | Optional external yara rule files, this will override the default yara rules |
Returns
| Type | Description |
|---|---|
| CleanerScanResult | scan result as an CleanerScanResult object |