xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xtrareport-47957207.md
Creates a document from the report instance to display or print at a later time.
Namespace : DevExpress.XtraReports.UI
Assembly : DevExpress.XtraReports.v25.2.dll
NuGet Package : DevExpress.Reporting.Core
public void CreateDocument()
Public Sub CreateDocument
The CreateDocument method creates a report document that is ready to preview, print, and export. The created document is bound to the report instance from which it was created. When you view the report later, the preview component loads the already created document as long as no changes are made to the report instance.
The newly created document is accessible through the following notation:
report.PrintingSystem.Document
The page collection is accessible through the XtraReport.Pages property.
You can merge document pages to create a complex report. For more information, review the following help topic: Merge Reports.
Once the document creation process starts, it will continue until the document is complete. The process cannot be interrupted or canceled. To create a report document asynchronously in a separate task, use the CreateDocumentAsync(CancellationToken) method instead.
If you want to access document pages progressively as they are created, and to stop or cancel document creation, call the CreateDocument method overload with the buildForInstantPreview parameter set to true.
You do not need to call CreateDocument before calling one of the following methods, as they call the CreateDocument method internally:
The CreateDocument method itself does not invoke the Parameters dialog that allows the user to enter parameter values.
If the report contains parameters and the XtraReport.RequestParameters is set to true, you should add the DevExpress.XtraPrinting.v25.2.dll to the project reference list and call the CreateDocument method after the report is assigned to the ReportPrintTool:
using DevExpress.XtraReports.UI;
// ...
XtraReport1 report = new XtraReport1();
ReportPrintTool tool = new ReportPrintTool(report);
report.CreateDocument();
Imports DevExpress.XtraReports.UI
' ...
Dim report As New XtraReport1()
Dim tool As New ReportPrintTool(report)
report.CreateDocument()
The Parameters dialog is invoked:
Note
An attempt to call the CreateDocument method for a report that does not include a DetailBand results in an exception. This may happen when a report is created in code. You should add the DetailBand band to the report, even if it is not necessary for your task.
Web components call the CreateDocument method internally before a report is previewed, printed, or exported. You do not have to call the CreateDocument method manually unless your task is to merge reports or modify document pages.
In distributed systems, calls to the CreateDocument method may be used to properly configure the preview.
The following code snippet shows how to add all pages of one report to the end of another report, how to merge pages of two reports into a single report, and how to reorder report pages so that they can be printed as a booklet.
private void CombineTwoReports() {
// Create the 1st report and generate its document.
XtraReport1 report1 = new XtraReport1();
report1.CreateDocument();
// Create the 2nd report and generate its document.
XtraReport2 report2 = new XtraReport2();
report2.CreateDocument();
// Add all pages of the 2nd report to the end of the 1st report.
report1.Pages.AddRange(report2.Pages);
// Reset all page numbers in the resulting document.
report1.PrintingSystem.ContinuousPageNumbering = true;
// Show the Print Preview form.
report1.ShowPreviewDialog();
}
private void MergeTwoReports() {
// Create the 1st report and generate its document.
XtraReport1 report1 = new XtraReport1();
report1.CreateDocument();
// Create the 2nd report and generate its document.
XtraReport2 report2 = new XtraReport2();
report2.CreateDocument();
// Merge pages of two reports, page-by-page.
int minPageCount = Math.Min(report1.Pages.Count, report2.Pages.Count);
for (int i = 0; i < minPageCount; i++) {
report1.Pages.Insert(i * 2 + 1, report2.Pages[i]);
}
if (report2.Pages.Count != minPageCount) {
for (int i = minPageCount; i < report2.Pages.Count; i++) {
report1.Pages.Add(report2.Pages[i]);
}
}
// Reset all page numbers in the resulting document.
report1.PrintingSystem.ContinuousPageNumbering = true;
// Show the Print Preview form.
report1.ShowPreviewDialog();
}
private void CreateBooklet() {
// Create the 1st report and generate its document.
XtraReport1 report1 = new XtraReport1();
report1.CreateDocument();
// Preserve original page numbers on all pages.
report1.PrintingSystem.ContinuousPageNumbering = false;
// Create a booklet.
int centerPageIndex = Convert.ToInt32((report1.Pages.Count - 1) / 2);
for (int i = 0; i < centerPageIndex; i++) {
report1.Pages.Insert(i * 2 + 1, report1.Pages[report1.Pages.Count - 1]);
}
// Show the Print Preview form.
report1.ShowPreviewDialog();
}
}
Private Sub CombineTwoReports()
' Create the 1st report and generate its document.
Dim report1 As New XtraReport1()
report1.CreateDocument()
' Create the 2nd report and generate its document.
Dim report2 As New XtraReport2()
report2.CreateDocument()
' Add all pages of the 2nd report to the end of the 1st report.
report1.Pages.AddRange(report2.Pages)
' Reset all page numbers in the resulting document.
report1.PrintingSystem.ContinuousPageNumbering = True
' Show the Print Preview form.
report1.ShowPreviewDialog()
End Sub
Private Sub MergeTwoReports()
' Create the 1st report and generate its document.
Dim report1 As New XtraReport1()
report1.CreateDocument()
' Create the 2nd report and generate its document.
Dim report2 As New XtraReport2()
report2.CreateDocument()
' Merge pages of two reports, page-by-page.
Dim minPageCount As Integer = Math.Min(report1.Pages.Count, report2.Pages.Count)
For i As Integer = 0 To minPageCount - 1
report1.Pages.Insert(i * 2 + 1, report2.Pages(i))
Next i
If report2.Pages.Count <> minPageCount Then
For i As Integer = minPageCount To report2.Pages.Count - 1
report1.Pages.Add(report2.Pages(i))
Next i
End If
' Reset all page numbers in the resulting document.
report1.PrintingSystem.ContinuousPageNumbering = True
' Show the Print Preview form.
report1.ShowPreviewDialog()
End Sub
Private Sub CreateBooklet()
' Create the 1st report and generate its document.
Dim report1 As New XtraReport1()
report1.CreateDocument()
' Preserve original page numbers on all pages.
report1.PrintingSystem.ContinuousPageNumbering = False
' Create a booklet.
Dim centerPageIndex As Integer = Convert.ToInt32((report1.Pages.Count - 1) \ 2)
For i As Integer = 0 To centerPageIndex - 1
report1.Pages.Insert(i * 2 + 1, report1.Pages(report1.Pages.Count - 1))
Next i
' Show the Print Preview form.
report1.ShowPreviewDialog()
End Sub
The following code snippets (auto-collected from DevExpress Examples) contain references to the CreateDocument() method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
reporting-winforms-salary-reports/CS/SalaryReports/UserControls/DocumentViewerUserControl.cs#L34
if (report != null)
report.CreateDocument();
}
reporting-winforms-custom-table-of-contents/CS/CustomTableOfContents/Form1.cs#L21
CategoriesReport categoriesReport = new CategoriesReport();
categoriesReport.CreateDocument();
reportsModule.ReportsDataSourceHelper.SetupBeforePrint(report);
report.CreateDocument();
PrintToolBase tool = new PrintToolBase(report.PrintingSystem);
reporting-winforms-master-detail-subreport/CS/dxSampleMasterDetailSubreport/Form1.cs#L20
var report = new MasterReport();
report.CreateDocument();
this.documentViewer1.DocumentSource = report;
reporting-winforms-create-hierarchical-report-from-flat-table/CS/TreeViewReport/TreeReport.cs#L37
this.DataSource = nodesList;
this.CreateDocument();
}
reporting-winforms-salary-reports/VB/SalaryReports/UserControls/DocumentViewerUserControl.vb#L30
If report_Renamed IsNot Nothing Then
report_Renamed.CreateDocument()
End If
reporting-winforms-custom-table-of-contents/VB/CustomTableOfContents/Form1.vb#L24
Dim categoriesReport As CustomTableOfContents.CategoriesReport = New CustomTableOfContents.CategoriesReport()
categoriesReport.CreateDocument()
Dim productsReport As CustomTableOfContents.ProductsReport = New CustomTableOfContents.ProductsReport()
reporting-winforms-master-detail-subreport/VB/dxSampleMasterDetailSubreport/Form1.vb#L13
Dim report As New MasterReport()
report.CreateDocument()
DocumentViewer1.DocumentSource = report
winforms-scheduler-print-appointments-using-reports/VB/PrintingViaReports/Form1.vb#L170
' Create a report and preview it.
xr.CreateDocument()
Dim designForm As New XRDesignFormEx()
reporting-winforms-change-formatting-xrrichtext-rtf-content/VB/Form1.vb#L17
report.OverrideRtfFormatting = checkBox1.Checked
report.CreateDocument()
report.ShowPreviewDialog()
See Also