All docs
V20.1
20.1
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

XRPdfContent Class

A control that renders PDF content in a report.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v20.1.dll

Declaration

[DefaultBindableProperty("Source")]
public class XRPdfContent :
    XRControl,
    IComplexControl
<DefaultBindableProperty("Source")>
Public Class XRPdfContent
    Inherits XRControl
    Implements 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.

TIP

You cannot add the XRPdfContent control to Top Margin, Bottom Margin, Page Header, and Page Footer bands.

Specify Binary PDF Data

You can assign the 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 with a Detail band and 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();
// Obtain the binary PDF data and assign it to the XRPdfContent's Source property.
pdfContent.Source = System.IO.File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(typeof(ReportCreator).Assembly.Location), "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 with a Detail band and 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 MasterDetailReport.pdf file.
pdfContent.SourceUrl = Path.Combine(Path.GetDirectoryName(typeof(ReportCreator).Assembly.Location), "MasterDetailReport.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 with a Detail band and 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 = Path.Combine(Path.GetDirectoryName(typeof(ReportCreator).Assembly.Location), "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 with a Detail band and 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 that does not work in Linux-based environments or on Azure hosting. Export to PDF is the only option available on these platforms.

See Also