A newer version of this page is available. Switch to the current version.

XtraReport.ModifyDocument(Action<IDocumentModifier>) Method

Adds and/or removes the report's document pages.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v18.2.dll


public void ModifyDocument(
    Action<IDocumentModifier> callback
Public Sub ModifyDocument(
    callback As Action(Of IDocumentModifier)


Name Type Description
callback Action<IDocumentModifier>

A delegate method that allows you to modify the report document using the IDocumentModifier object passed as a parameter.


In the delegate method, modify the report document's page set using the following members exposed by the IDocumentModifier object that is passed as a parameter:

  • PageCount
    Specifies the report document's page count.

  • GetPageIndexByID
    Use a page's ID instead of the Index property to identify the page, because the page index can change while changing the document's page set. Call the GetPageIndexByID method to get a page's current index by passing the page's ID.

  • InsertPage
    Inserts the specified page at a specified position.

  • RemovePageAt
    Removes the specified page at a specified position.

Call the ModifyDocument method when the report's document is already created. Use the AfterPrint event or call the CreateDocument() method beforehand.

If you use the ModifyDocument method to extend a report document with pages from another document, create the other document using the CreateDocument() method beforehand.

public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport {
    long? categoryStartPageID;
    private void XtraReport1_AfterPrint(object sender, EventArgs e) {  
        //Create the 2nd report and generate its document.
        XtraReport2 report2 = new XtraReport2();

        if(IsDisposed || categoryStartPageID == null)
        // Add the 2nd report's pages alternating them with the 1st report pages,
        // starting from the 'categoryStartPageID' page
        ModifyDocument(x => {
            int categoryStartPageIndex = x.GetPageIndexByID(categoryStartPageID.Value);
            categoryStartPageID = null;

            for(int i = 0; i < report2.Pages.Count; i++) {
                int insertIndex = categoryStartPageIndex + 1 + i * 2;
                if(insertIndex >= x.PageCount)
                x.InsertPage(insertIndex, report2.Pages[i]);
    private void lbCategoryName_PrintOnPage(object sender, PrintOnPageEventArgs e) {
        if(IsDisposed || categoryStartPageID != null)
        categoryStartPageID = Pages[e.PageIndex].ID;

Use the CachedReportSource/CachedReportSourceWeb component's CreateDocument and ModifyDocument methods to merge reports that include a large amount of data.

See Also