Convert RTF to PDF in C#
RTF to PDF
This article explains how to convert RTF files to PDFs.
Creating a PDF from an RTF file
To create a PDF from an RTF file, follow the steps below:
- Create a
GdPictureDocumentConverterobject. - Load the source document by passing its path to the
LoadFromFilemethod. Recommended: Specify the source document format with a member of theDocumentFormatenumeration. - Save the output in a new PDF document with the
SaveAsPDFmethod.
The example below creates a PDF document from an RTF file:
using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();// Load the source document.gdpictureDocumentConverter.LoadFromFile(@"C:\temp\source.rtf", GdPicture14.DocumentFormat.DocumentFormatRTF);// Save the output in a new PDF document.gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter() ' Load the source document. gdpictureDocumentConverter.LoadFromFile("C:\temp\source.rtf", GdPicture14.DocumentFormat.DocumentFormatRTF) ' Save the output in a new PDF document. gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")End UsingUsed methods
Related topics
Optional PDF configuration properties
Optionally, configure the conversion with the following properties of the GdPictureDocumentConverter object:
PdfBitonalImageCompressionis a member of thePdfCompressionenumeration that specifies the compression scheme used for bitonal images in the output PDF file.PdfColorImageCompressionis a member of thePdfCompressionenumeration that specifies the compression scheme used for color images in the output PDF file.PdfEnableColorDetectionis a Boolean value that specifies whether to use automatic color detection during the conversion that preserves image quality and reduces the output file size.PdfEnableLinearizationis a Boolean value that specifies whether to linearize the output PDF to enable Fast Web View mode.PdfImageQualityis an integer from 0 to 100 that specifies the image quality in the output PDF file.
The example below creates a PDF document from an RTF file with a custom configuration:
using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();// Load the source document.gdpictureDocumentConverter.LoadFromFile(@"C:\temp\source.rtf", GdPicture14.DocumentFormat.DocumentFormatRTF);// Configure the conversion.gdpictureDocumentConverter.PdfColorImageCompression = PdfCompression.PdfCompressionJPEG;gdpictureDocumentConverter.PdfImageQuality = 50;// Save the output in a new PDF document.gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter() ' Load the source document. gdpictureDocumentConverter.LoadFromFile("C:\temp\source.rtf", GdPicture14.DocumentFormat.DocumentFormatRTF); ' Configure the conversion. gdpictureDocumentConverter.PdfColorImageCompression = PdfCompression.PdfCompressionJPEG gdpictureDocumentConverter.PdfImageQuality = 50 ' Save the output in a new PDF document. gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")End UsingUsed methods and properties
Related topics