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:

  1. Create a GdPictureDocumentConverter object.
  2. Load the source document by passing its path to the LoadFromFile method. Recommended: Specify the source document format with a member of the DocumentFormat enumeration.
  3. 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");

Optional PDF configuration properties

Optionally, configure the conversion with the following properties of the GdPictureDocumentConverter object:

  • PdfBitonalImageCompression is a member of the PdfCompression enumeration that specifies the compression scheme used for bitonal images in the output PDF file.
  • PdfColorImageCompression is a member of the PdfCompression 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");