Set to Grayscale
Converting a colored PDF document to grayscale can offer several advantages, such as removing the consideration of color and focusing solely on color intensity.
The feature to generate grayscale PDFs is only available when converting HTML to PDF with IronPDF's HTML to PDF Conversion Feature. You can apply a rendering option that includes a grayScale
property, which can be set to true
or false
. Setting this property to true
will generate a grayscale PDF instead of a colored one.
Below is a sample code snippet demonstrating how to convert an HTML file to a grayscale PDF using IronPDF in C#:
Explanation of the Code
- Using IronPdf: Include the IronPdf library to access PDF rendering functionalities.
- HtmlToPdf Renderer Initialization: Create an instance of the
HtmlToPdf
class, which facilitates the HTML to PDF conversion process. - Setting Render Options: Define the rendering options through the
PdfPrintOptions
class. The key property here isGrayScale
, which, when set totrue
, ensures that the resulting PDF is rendered in grayscale. - Rendering HTML to PDF: Use
RenderHtmlAsPdf
to convert HTML content into a PDF document. - Saving the PDF: The resulting grayscale PDF is saved to the specified file path "output.pdf".
- Console Notification: Display a message on the console to inform the user that the PDF has been created successfully.
This code provides a clear example of how to convert an HTML document into a grayscale PDF using IronPDF's HTML to PDF conversion tools.
Discover how to seamlessly convert PDFs to grayscale using IronPDF for Node.js!