PrintDocument for WinForms | ComponentOne
PrintDocument Library / MultiDocument
In This Topic
    MultiDocument
    In This Topic

    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.

    Tasks Menu

    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.

    Snapshot of smart tag

    The C1MultiDocument Tasks menu operates as follows:

    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.

    Create and Preview MultiDocument

    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:

    1. In Design View, double-click on the form to open the Code Editor.
    2. Add the following code to the Load event:
      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.

    Export MultiDocument

    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);
    

    Print MultiDocument

    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.

    Outlines

    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: