The RadFixedDocumentEditor class allows you to create a RadFixedDocument in a flow-like manner. The editor provides methods that enable the generation of documents, which automatically flows to pages.
Example 1 demonstrates how a RadFixedDocumentEditor instance can be created.
Example 1: Create RadFixedDocumentEditor
RadFixedDocumentEditor editor = new RadFixedDocumentEditor(radFixedDocument);
RadFixedDocumentEditor inherits from IDisposable so it should be properly disposed when the document is created. Otherwise, some of the content may not be finished, i.e. it might not appear on the PDF document.
Section is a sequence of RadFixedPages with the same properties.
The section properties are responsible for the page size, margins and orientation of RadFixedPages in a section. Below is the complete list of section properties:
PageSize: The size of the pages that are part of the section.
PageMargins: The page margins of a page.
PageRotation: The page rotation. This is enum that can take one of the following values:
- Rotate0: The page is not rotated. This is the default value.
- Rotate90: The page is rotated to 90°.
- Rotate180: The page is rotated to 180°.
- Rotate270: The page is rotated to 270°.
The first section of a document starts as soon as a content is inserted to the editor. You can change the Section properties before inserting any content and they will be applied to the section that is automatically created.
Adding an additional section is achieved with the InsertSectionBreak() method as demonstrated in Example 2.
Example 2: Start a section
If you want to change the properties of the next section, make sure to do it before you insert the section break. New properties are only used for newly created sections.
All pages that have the same SectionProperties are part of the current section. To start a new page, you can use the following code:
Example 3: Start new page
Paragraphs are blocks of flowing inlines - images and text.
Similar to the section properties, paragraph has its own properties that are responsible for the way it looks.
SpacingBefore: Represents the spacing before.
SpacingAfter: Represents the spacing after.
LineSpacing: The spacing between the lines.
LineSpacingType: Specifies how to interpret the line spacing.
FirstLineIndent: The indent for the first line.
LeftIndent: The left indent.
RightIndent: The right indent.
BackgroundColor: The background color.
HorizontalAlignment: The horizontal alignment of the content.
ListId: The id of the list the paragraph belongs to. If null, then the paragraph belongs to no list.
ListLevel: The list level the paragraph belongs to.
The first paragraph is created as soon as content is inserted in the editor. You can change paragraph properties before inserting content and when the first paragraph is created automatically, it will use the desired properties.
In order to start a new paragraph, use the code in Example 4.
Example 4: Start a paragraph
The result of this method is that a new paragraph is started and it uses the current paragraph properties. Until a new paragraph is started, changes in the paragraph properties are not applied.
A Paragraph is built of two types of inlines - runs and images.
Run represents a collection of characters that have the same properties.
The character properties that are responsible for the look of the runs are listed below.
FontSize: The font size.
Font: The font.
ForegroundColor: The foreground color.
HighlightColor: The highlight color.
BaselineAlignment: Describes how the baseline for a text-based element is positioned on the vertical axis, relative to the established baseline for text.
- Baseline: A baseline that is aligned at the actual baseline of the containing box.
- Subscript: A baseline that is aligned at the subscript position of the containing box.
- Superscript: A baseline that is aligned at the superscript position of the containing box.
UnderlinePattern: Тhe underline pattern. Two patterns are supported.
- None: There is no underline. This is the default value.
- Single: The underline is a single line.
UnderlineColor: The color of the underline.
There are a number of overloads that insert a run. The code snippet in Example 5 inserts new runs with specific font family, style and weight.
Example 5: Insert run
editor.InsertRun("text"); editor.InsertRun(fontFamily, "text");
There are a number of overloads that insert a run. The code snippet in Example 5 inserts a couple of new runs, one of which with a specific font family.
The '\r' and '\n' characters don't have the usual meaning of "go to next line" when they are inserted into a PDF document and you cannot simply insert text containing these characters to produce multiline text. Instead, you should split the text and insert a line break.
The code in Example 6 inserts a new run and a line break after it.
Example 6: Insert run and line break
editor.InsertLine("Line of text");
Image inline is a combination of an ImageSource object and its desired size.
You can insert image inline using one of the following methods:
Example 7: Insert image
editor.InsertImageInline(imageSource); editor.InsertImageInline(imageSource, size);
The Table class implements the IBlockElement interface and an instance of this class can be easily inserted as a new block in the document. You could insert the table using the InsertTable() method like illustrated in Example 8. RadFixedDocumentEditor takes care for positioning, measuring and splitting the table onto pages.
Example 8: Insert table
For more detailed information on tables, check the Table documentation article.
The IBlockElement interface allows you to easily draw and split some block content onto pages. The interface is implemented by Block and Table classes. You can easily add some block element instance with RadFixedDocumentEditor using the InsertBlock() method like illustrated in Example 9.
Example 9: Insert Block element
You can easily insert list items with RadFixedDocumentEditor. The first thing you have to do is add a List in editor’s ListCollection by using the Lists property. Then, each time you want to add list item you have to set the appropriate ListId and ListLevel property values through RadFixedDocumentEditor’s ParagraphProperties. Inserting a new paragraph will result in adding a new list item.
The following code snippet shows how to add a new list to RadFixedDocumentEditor’s ListCollection and after that insert a paragraph with the corresponding list properties:
Example 10: Insert list
List list = editor.Lists.AddList(ListTemplateType.NumberedDefault); editor.ParagraphProperties.ListId = list.Id; editor.ParagraphProperties.ListLevel = 0; editor.InsertParagraph();
With the RadFixedDocumentEditor class you can insert a Form (Form-XObject) element.
Example 11: Insert a form