Available for: UI for ASP.NET MVC | UI for ASP.NET AJAX | UI for Blazor | UI for WPF | UI for WinForms | UI for Xamarin | UI for WinUI | UI for ASP.NET Core | UI for .NET MAUI

New to Telerik Document Processing? Download free 30-day trial

Using PdfFormatProvider

RadWordsProcessing provides a PdfFormatProvider class that allows you to export a RadFlowDocument to PDF.

All you have to do in order to use PdfFormatProvider is add references to the assemblies listed below:

  • Telerik.Windows.Documents.Core.dll
  • Telerik.Windows.Documents.Flow.dll
  • Telerik.Windows.Zip.dll
  • Telerik.Windows.Documents.Flow.FormatProviders.Pdf.dll
  • Telerik.Windows.Documents.Fixed.dll

Export

In order to export a document to PDF you need to use the Export() method of PdfFormatProvider.

The .NET Standard specification does not define APIs for getting specific fonts. PdfFormatProvider needs to have access to the font data so that it can read it and add it to the PDF file. That is why, to allow the library to create and use fonts, you will need to provide an implementation of the FontsProviderBase abstract class and set this implementation to the FontsProvider property of FixedExtensibilityManager. For detailed information, check the Cross-Platform Support article.

.NET Standard: In order to export images different than Jpeg and Jpeg2000 or ImageQuality different than High, the JpegImageConverter property inside the FixedExtensibilityManager has to be set. For more information check the FixedExtensibilityManager in the PdfProcessing`s Cross-Platform Support

The code snippet in Example 1 shows how to create a PdfFormatProvider instance and use it to export RadFlowDocument to a file.

The PdfFormatProvider class of RadWordsProcessing is located in the Telerik.Windows.Documents.Flow.FormatProviders.Pdf namespace.

Example 1: Export to PDF file

Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider provider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider(); 
using (Stream output = File.OpenWrite("sample.pdf")) 
{ 
    RadFlowDocument document = CreateRadFlowDocument(); 
    provider.Export(document, output); 
} 

The result from the method is a document that can be opened in any application that supports PDF documents.

Example 2 demonstrates how to export the contents of a RadFlowDocument to a RadFIxedDocument.

Example 2: Export to RadFixedDocument

RadFlowDocument document = CreateRadFlowDocument(); 
 
Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider provider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider(); 
RadFixedDocument fixedDocument = provider.ExportToFixedDocument(document); 

RadFixedDocument is the base class of the RadPdfProcessing library. Additional information on the library and its functionality can be found here.

In this article