Skip to main content
A newer version of this page is available. .

XRPdfContent Class

A control that renders PDF content in a report.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v20.1.dll

NuGet Packages: DevExpress.Reporting.Core, DevExpress.WindowsDesktop.Reporting.Core

Declaration

[DefaultBindableProperty("Source")]
public class XRPdfContent :
    XRControl,
    IComplexControl

Remarks

PDF content is rendered on separate pages and uses its own page settings.

Use one of the following options to specify PDF content:

Add an XRPdfContent Control to a Report

At design time, drop the XRPdfContent item from the Toolbox onto a band on the design surface.

You can also copy a PDF document from an external application and paste it in your report, or drag a document and drop it onto the design surface. The dragged file’s content is assigned to the control’s Source property as binary data.

At runtime, create a new XRPdfContent class instance and add this instance to a report band’s Controls collection. Code samples are available in the Specify Binary PDF Data and Specify a Reference to a PDF Document sections.

Specify Binary PDF Data

You can assign binary data to the control’s Source property.

At design time, expand the XRPdfContent‘s smart tag and click the Source property’s ellipsis button to obtain the binary data from a file.

When users save a report, the Source property value persists in the report definition file.

Tip

See the Use Expressions section below for information on how to conditionally specify the Source property value, or bind it to a report parameter or data source field.

At runtime, obtain PDF binary data and assign it to the control’s Source property.

using System.IO;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Expressions;
// ...
// Create a report that has a Detail band and uses Landscape page orientation.
XtraReport report = new XtraReport(){
    Landscape = true,
    Bands = {
        new DetailBand() {
            Name = "DetailBand",
            HeightF = 25,
        }
    }
};
// Create an XRPdfContent class instance.
XRPdfContent pdfContent = new XRPdfContent();
// Read the binary PDF content into the XRPdfContent's Source property.
pdfContent.Source = System.IO.File.ReadAllBytes("MasterDetailReport.pdf");
// Add the XRPdfContent class instance to the report's Detail band.
report.Bands[BandKind.Detail].Controls.Add(pdfContent);

Specify a Reference to a PDF Document

You can use an external PDF document as a source of PDF data. Set the SourceUrl property to a local file system path or URL.

At design time, expand the XRPdfContent‘s smart tag and click the Source URL property’s ellipsis button to specify the PDF document location in the file system.

To specify the PDF document’s location on the Web, use the URL as the Source URL property’s value.

When users save a report, the URL or path specified in the Source URL property is included in the report definition file. The PDF document should be available at the specified location when a report is printed or rendered in a Document Viewer.

Tip

See the Use Expressions section for information on how to conditionally specify the SourceUrl property value, or bind it to a report parameter or data source field.

At runtime, set the XRPdfContent class instance’s SourceUrl property to a string value that specifies a URL or path to a PDF document.

using System.IO;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Expressions;
// ...
// Create a report that has a Detail band and uses Landscape page orientation.
XtraReport report = new XtraReport(){
    Landscape = true,
    Bands = {
        new DetailBand() {
            Name = "DetailBand",
            HeightF = 25,
        }
    }
};
// Create an XRPdfContent class instance.
XRPdfContent pdfContent = new XRPdfContent();
// The PDF content is loaded from the MasterDetail Report.pdf file.
pdfContent.SourceUrl = "MasterDetail Report.pdf";
// Add the XRPdfContent class instance to the report's Detail band.
report.Bands[BandKind.Detail].Controls.Add(pdfContent);

The SourceUrl property value takes precedence over the Source property value. If you specify both properties, XRPdfContent includes the content specified by SourceUrl. However, if the file specified in the SourceUrl property cannot be loaded, the binary data from the Source property is used.

Use Expressions

Add an ExpressionBinding item to the control’s ExpressionBindings collection to set an expression that specifies the Source or SourceUrl property value. An expression can include report parameters or data source fields, or it can conditionally specify a property value.

At design time, expand the XRPdfContent‘s smart tag.

  • Click the Expression property’s ellipsis button below the Source property. Use the invoked Expression Editor to create an expression that identifies the source of binary PDF data.

  • Click the Expression property’s ellipsis button below the Source URL property. Use the invoked Expression Editor to create an expression the value of which identifies a URL or path to a PDF document.

At runtime, create an ExpressionBinding class instance with the property name (Source or SourceUrl) and an expression string, and add this instance to the ExpressionBindings collection.

The code below creates an XRPdfContent control and adds it to a report’s Detail band. The sample then creates an expression that binds the control’s SourceUrl property to the report’s PdfParameter parameter.

using System.IO;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Expressions;
// ...
// Create a report that has a Detail band and uses Landscape page orientation.
// The "PdfParameter" report parameter specifies a PDF file's location.
XtraReport report = new XtraReport(){
    Landscape = true,
    Parameters = {
        new DevExpress.XtraReports.Parameters.Parameter() {
            Name = "PdfParameter",
            Type = typeof(string),
            Value = "MasterDetailReport.pdf",
            Visible = true
        },
    },
    Bands = {
        new DetailBand() {
            Name = "DetailBand",
            HeightF = 25,
        }
    }
};
// Create an XRPdfContent class instance.
XRPdfContent pdfContent = new XRPdfContent();
// Create an expression that binds the XRPdfContent's SourceUrl property to the report's "PdfParameter" parameter.
pdfContent.ExpressionBindings.Add(new ExpressionBinding("SourceUrl", "?PdfParameter"));
// Add the XRPdfContent class instance to the report's Detail band.
report.Bands[BandKind.Detail].Controls.Add(pdfContent);

The code below creates an XRPdfContent control and uses an expression to bind the control’s Source property to the PdfData field.

using System.IO;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Expressions;
// ...
// Create a report that has a Detail band and uses Landscape page orientation.
XtraReport report = new XtraReport(){
    Landscape = true,
    Bands = {
        new DetailBand() {
            Name = "DetailBand",
            HeightF = 25,
        }
    }
};
// Create an XRPdfContent class instance.
XRPdfContent pdfContent = new XRPdfContent();
// Create an expression that binds the XRPdfContent's Source property to the data source's "PdfData" field.
pdfContent.ExpressionBindings.Add(new ExpressionBinding("Source", "[PdfData]"));
// Add the XRPdfContent class instance to the report's Detail band.
report.Bands[BandKind.Detail].Controls.Add(pdfContent);

Limitations

  • PDF content always starts on a new page. Report content is printed on a new page after the PDF content is finished.

  • PDF content is displayed as an image in Preview. Users cannot select text in PDF content. To allow users to select text, export the report to PDF.

  • The XRPdfContent control uses the CreateBitmap method, which does not work in Linux-based environments or on Azure hosting. Export to PDF is the only option available on these platforms.

  • You cannot add the XRPdfContent control to the following bands:

See Also