Inserting XAML Content into a PDF Document
Environment
| Version | Product | Author |
|---|---|---|
| 2024.2.426 | RadWordsProcessing | Desislava Yordanova |
Description
In WPF applications, you can collect input from a RichTextBox and save it as an XAML string. This input can include links, font styles (bold, italic), bullet points, tables, and other elements. You can then import this XAML content into an existing PDF document.
This article demonstrates a sample approach for handling this scenario with the Telerik Document Processing Libraries.
Solution
The XamlFormatProvider is applicable for the WPF RadRichTextBox control. The format providers offered by the RadRichTextBox control are different from the format providers in the Document Processing Libraries. As a result, they may support different features and produce different output results.
To insert XAML content into a PDF while retaining formatting, follow these steps:
-
Export the XAML content from the RadRichTextBox to a DOCX format using the DocxFormatProvider.
-
Use the RadWordsProcessing library to import the DOCX file.
-
Export the DOCX content to PDF format. This preserves the content formatting as closely as possible.
-
If you need to merge the newly created PDF content (from the XAML content) with another PDF document, use the PdfStreamWriter to merge the documents.
The XAML SDK repository on GitHub contains examples showing the capabilities of
PdfStreamWriter. The Manipulate Pages example shows different use cases ofPdfStreamWriter. Review theMergeDifferentDocumentsPagesmethod.