The MultiDocument component is designed to allow creating, persisting, and exporting large documents that cannot be handled by a single PrintDocument object due to memory limitations.
A MultiDocument object provides a Items collection that can contain one or more elements of the type C1MultiDocumentItem. Each such element represents a PrintDocument. Use of compression and temporary disk storage allows combining several C1PrintDocument objects into a large multi-document that would cause an out of memory condition if all pages belonged to a single C1PrintDocument. The following snippet of code illustrates how a multi-document might be created and previewed:
C# |
Copy Code
|
---|---|
C1MultiDocument mdoc = new C1MultiDocument(); mdoc.Items.Add(C1PrintDocument.FromFile("myDoc1.c1dx")); mdoc.Items.Add(C1PrintDocument.FromFile("myDoc2.c1dx")); mdoc.Items.Add(C1PrintDocument.FromFile("myDoc3.c1dx")); C1PrintPreviewDialog pview = new C1PrintPreviewDialog(); pview.Document = mdoc; pview.ShowDialog(); |
MultiDocument supports links between contained documents, common TOC, common page numeration, and total page count.
Note that a C1MultiDocument does not store references to the C1PrintDocument objects added to it - rather, it serializes them (as .c1d/x) and stores the result. Thus, you can create really large multi-documents without running out of memory - provided, of course, that your code itself does not keep references to the individual C1PrintDocument objects that were added to the C1MultiDocument. So when using C1MultiDocument please make sure that you do not keep references to the individual document objects after you have added them to the multi-document. MultiDocument can be persisted as "C1 Open XML Multi Document" with the default extension of .c1mdx.
In Visual Studio, the MultiDocument component includes a smart tag. A smart tag represents a short-cut tasks menu that provides the most commonly used properties.
To access the C1MultiDocument Tasks menu, click the smart tag () in the upper-right corner of the MultiDocument component.
The C1MultiDocument Tasks menu operates as follows:
Viewers for this document
If any visual previewing controls such as C1PrintPreviewControl control are included in the application, the C1MultiDocument Tasks Menu will display them here. When the check box next to the name of a previewing control is checked, the C1MultiDocument component is associated with the previewing control and reports will appear in the previewing control.
Localize
Clicking Localize opens the Localize dialog box. In the Localize dialog box, you can customize your localization settings. For more information on the Localize dialog box, see Localization.
About
Clicking About displays the About dialog box, which is helpful in finding the version number of Reports for WinForms, as well as online resources.
If that limitation is not an issue for a particular application, then you can even use the C1MultiDocument component to "modularize" the application even if there are no memory problems.
To add an item to the C1MultiDocumentItemCollection, you can use the Add method. To load a file into the MultiDocument component you can use the Load method. To remove a file, you would use the Clear method. This method clears any file previously loaded into the C1MultiDocument component.
To add an item to the C1MultiDocumentItemCollection, you can use the Add method. Complete the following steps:
C# |
Copy Code
|
---|---|
C1PrintPreviewControl ppc = new C1PrintPreviewControl(); Controls.Add(ppc); ppc.Dock = DockStyle.Fill; C1PrintDocument pdoc = new C1PrintDocument(); C1PrintDocument pdoc2 = new C1PrintDocument(); C1MultiDocument mdoc = new C1MultiDocument(); pdoc.Body.Children.Add(new C1.C1Preview.RenderText("Hello!")); pdoc2.Body.Children.Add(new C1.C1Preview.RenderText("World!")); mdoc.Items.Add(pdoc); mdoc.Items.Add(pdoc2); ppc.Document = mdoc; mdoc.Generate(); |
This code loads two PrintDocument components into the MultiDocument component and displays the documents in a PrintPreviewControl at run time.
MultiDocument can be exported to most formats using any of the Export method overloads. For example, in the following example the C1MultiDocument will be exported to a PDF file. The Boolean value, True, indicates that a progress dialog box should be shown.
C# |
Copy Code
|
---|---|
this.c1MultiDocument1.Export(@"C:\exportedfile.pdf", true); |
MultiDocument can be printed using any of the Print and PrintDialog methods overloads. For example, the following code opens a Print dialog box.
C# |
Copy Code
|
---|---|
this.c1MultiDocument1.PrintDialog();
|
If you include the above code in a button's Click event handler, the Print dialog box will appear when the button is clicked at run time.
If you include the above code in a button's Click event handler, the C1MultiDocument's content will be exported to a PDF file when the button is clicked at run time.
MultiDocument includes outline support. A collection of outline nodes specific to the multi-document may be specified via the Outlines property. The resulting outline (such as for the preview) is built as a combination of outline nodes in that collection and outline nodes in the contained documents. This outline can be built programmatically using the MakeOutlines() method.
The multi-document's own Outlines collection is processed first, and nodes from that collection are included in the resulting outline. If a node is also specified as the value of the OutlineNode of a contained C1MultiDocumentItem (for example, the two properties reference the same object), the whole outline of the document or report represented by that item is inserted into the resulting outline. Depending on the value of the multi-document item's NestedOutlinesMode property, the outline of the document or report is either nested within the outline node, or replaces it. Finally, outlines of documents and reports represented by items that are not included in the multi-document's Outlines collection are automatically appended to the resulting outline sequentially.
Outlines support is provided by the following properties and methods: