Telerik blogs
XamarinT2 Dark_1200x303

Need to generate Docx, HTML, RTF or PDF documents in your Xamarin App? Telerik UI for Xamarin has a solution for you - our new WordsProcessing library.

telerik-ui-for-xamarin-wordsprocessing

It has never been easier to generate, modify and export a document in your mobile application! The RadWordsProcessing library enables you to easily generate and export documents in various formats, including:

  • PDF
  • Docx
  • RTF
  • HTML
  • Plain text

The library comes in handy all cases where document or PDF generation is needed, such as PDF invoice generation for an e-commerce app, or to serve the user with a filled application form in Docx format.

With our document processing library you can quickly access each element in a given document, modify, remove it or add a new one. Additionally, the generated content can be saved as a stream, file, or send to the client browser.

In this blog post, we will familiarize you with the RadWordsProcessing structure and the features it provides.

WordsProcessing Structure

The document model of RadWordsProcessing for Xamarin includes all necessary elements and features of a document, including:

  • Sections that can be customized using the properties exposed by the corresponding class. Headers, footers, and watermarks for a section can be customized as well.
  • Paragraphs whose properties and methods enable you to change its collection of inlines and appearance.
  • Tables equipped with an API, allowing you to easily insert, edit, and remove from the document. Their rows, cells, appearance, and content are also flexible, with various changes and manipulations possible.
  • Inlines, including Runs, Images, as well as inline and floating images, Fields, Breaks, Bookmarks, Hyperlinks and Tab stops.
  • Styles: the documents processing model includes a repository of Style objects containing sets of character, paragraph or table style properties. Additionally, you can create custom styles and use them throughout the document.

Supported Formats

In addition to the smooth creation, modification, import and export of files, RadWordsProcessing gives you the ability to convert between variety of formats - convert Docx to PDF or HTML to Docx in your Xamarin apps. The currently supported formats are Docx, RTF, HTML, PDF and plain text.

The processing library doesn’t need any external dependencies in order to convert documents from/to the supported formats - the document model is UI-independent and can be used on both server and client-side.

Features

In addition to being able to create, modify, and export a document, RadWordsProcessing has some additional sweet features, including:

  • Inline & floating images: support for inline & floating images for the most popular formats, including support for working with image properties such as Source, Size, Flip, Rotation, AspectRatio, etc.
  • Bookmarks & hyperlinks: enable your users to easily navigate a document with bookmarks and hyperlinks
  • Watermarks: identify document status or mark it as confidential with watermarks
  • Create documents in different file formats, for example:

    generate documents

private RadFlowDocument CreateDocument()
{
RadFlowDocument document = new RadFlowDocument();
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
editor.ParagraphFormatting.TextAlignment.LocalValue = Alignment.Justified;
editor.InsertLine("Dear Telerik User,");
editor.InsertText("We’re happy to introduce the new Telerik RadWordsProcessing component for Xamarin Forms. High performance library that enables you to read, write and manipulate documents in DOCX, RTF and plain text format. The document model is independent from UI and ");
Run run = editor.InsertText("does not require");
run.Underline.Pattern = UnderlinePattern.Single;
editor.InsertLine(" Microsoft Office.");
editor.InsertText("The current community preview version comes with full rich-text capabilities including ");
editor.InsertText("bold, ").FontWeight = FontWeights.Bold;
editor.InsertText("italic, ").FontStyle = FontStyles.Italic;
editor.InsertText("underline,").Underline.Pattern = UnderlinePattern.Single;
editor.InsertText(" font sizes and ").FontSize = 20;
editor.InsertText("colors ").ForegroundColor = GreenColor;
editor.InsertLine("as well as text alignment and indentation. Other options include tables, hyperlinks, inline and floating images. Even more sweetness is added by the built-in styles and themes.");
editor.InsertText("Here at Telerik we strive to provide the best services possible and fulfill all needs you as a customer may have. We would appreciate any feedback you send our way through the ");
editor.InsertHyperlink("public forums", "http://www.telerik.com/forums", false, "Telerik Forums");
editor.InsertLine(" or support ticketing system.");
editor.InsertLine("We hope you’ll enjoy RadWordsProcessing as much as we do. Happy coding!");
editor.InsertParagraph();
editor.InsertText("Kind regards,");
return document;
}
  • Easily Find all instances of a string And Replace it with another through the ReplaceText() method of the RadFlowDocumentEditor.
private void ReplaceText()
{
if (string.IsNullOrEmpty(this.findWhat))
{
return;
}
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(this.replacedDocument);
if (this.useRegex)
{
Regex oldTextRegex = new Regex(this.findWhat);
editor.ReplaceText(oldTextRegex, this.replaceWith);
}
else
{
editor.ReplaceText(this.findWhat, this.replaceWith, this.matchCase, this.matchWholeWord);
}
}

The full demo project can be found here.

  • Insert Documents at a Specific Position using the InsertDocument() method.
  • Merge two RadFlowDocument instance using the Merge() method.
RadFlowDocument target = new RadFlowDocument();
RadFlowDocument source = new RadFlowDocument();
//...
// target will contain merged content and styles.
target.Merge(source);

Here the document you wish to add content to is called target and the document from which you wish to take the content is called source.

Export documents in different formats:

export documents

Tell Us What You Think

Have we caught your interest with the new RadWordsProcessing library for Xamarin.Forms and its features? You can find various demos of the processing library in our Telerik UI for Xamarin Demo application.

I hope that this information will get you started with the processing library— as always, any feedback on it is highly appreciated. If you have any ideas for features, not hesitate to share this information with us on our Telerik Document Processing Feedback Portal.

If this is the first time you're hearing about Telerik UI for Xamarin, you can find more information about it on our website or dive right into a free 30-day trial today.

Happy coding with our controls!


Dobrinka Yordanova
About the Author

Dobrinka Yordanova

Dobrinka Yordanova is a Technical Support Engineer, part of the Progress Telerik UI for Xamarin & UWP team in Sofia, Bulgaria. She holds a master's degree in Computer Systems and Technologies. Her passion is traveling around the world and exploring multicultural environments. In her spare time she likes making sushi, playing console games and hanging out with friends.

Related Posts

Comments

Comments are disabled in preview mode.