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
GdPictureDocumentConverter
object. - Load the source document by passing its path to the
LoadFromFile
method. Recommended: Specify the source document format with a member of theDocumentFormat
enumeration. - Save the output in a new PDF document with the
SaveAsPDF
method.
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 Using
Used methods
Related topics
Optional PDF configuration properties
Optionally, configure the conversion with the following properties of the GdPictureDocumentConverter
object:
PdfBitonalImageCompression
is a member of thePdfCompression
enumeration that specifies the compression scheme used for bitonal images in the output PDF file.PdfColorImageCompression
is a member of thePdfCompression
enumeration that specifies the compression scheme used for color images in the output PDF file.PdfEnableColorDetection
is a Boolean value that specifies whether to use automatic color detection during the conversion that preserves image quality and reduces the output file size.PdfEnableLinearization
is a Boolean value that specifies whether to linearize the output PDF to enable Fast Web View mode.PdfImageQuality
is 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 Using
Used methods and properties
Related topics