All docs
V21.2
21.2 (EAP/Beta)
21.1
20.2
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.
You are viewing help content for pre-release software. This document and the features it describes are subject to change. Switch to the current version.

XRPdfContent Class

A control that renders PDF file content in a report.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v21.2.dll

Declaration

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

Remarks

The XRPdfContent control allows you to render PDF file content in two ways:

  • Default. Render each PDF file page as a separate report page.

    Render PDF content on separate pages

  • Embed PDF content into a report.

    Embed PDF content to a report

    Refer to the following documentation section for more details: Embed PDF File Content into a Report.

Add the XRPdfContent Control to a Report

Design Time

Drop the XRPdfContent item from the Toolbox onto a band on the design surface.

Drop the XRPdfContent control from Toolbox

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.

Drag a PDF file from an external resource to a report band

The dragged file’s content is assigned to the control’s Source property as binary data.

Runtime

Create an XRPdfContent class instance and add this instance to a report band’s Controls collection. Refer to the following sections for code samples:

Specify PDF Content

Use one of the following methods:

Specify Binary PDF Data

Design Time

Expand the XRPdfContent control’s smart tag, click the Source property’s ellipsis button, and select a PDF file.

Click the Source property's ellipsis button and select PDF file

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

You can also use report parameters to conditionally specify the Source property value or bind the property to a data source field. Refer to the following section for details: Use Expressions.

Runtime

Assign a path to a PDF file 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();
// Assign binary PDF content to the XRPdfContent's Source property.
pdfContent.Source = System.IO.File.ReadAllBytes("MasterDetailReport.pdf");
// Add the XRPdfContent control to the Detail band.
report.Bands[BandKind.Detail].Controls.Add(pdfContent);

Specify a Reference to a PDF Document

Design Time

Expand the XRPdfContent control’s smart tag, click the Source URL property’s ellipsis button, and select a PDF file.

Click the Source URL property's ellipsis button and select PDF file

To specify a PDF document location on the Web, assign a document URL to the Source URL property.

Assign a Web URL to the Source URL property

You can also use report parameters to conditionally specify the SourceUrl property value or bind the property to a data source field. Refer to the following section for details: Use Expressions.

When users save a report, the URL or path assigned to 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.

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

Runtime

Assign a PDF file path or URL to an XRPdfContent class instance’s SourceUrl 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();
// PDF content is loaded from the MasterDetail Report.pdf file.
pdfContent.SourceUrl = "MasterDetail Report.pdf";
// Add the XRPdfContent control to the Detail band.
report.Bands[BandKind.Detail].Controls.Add(pdfContent);

Use Expressions

Design Time

Expand the XRPdfContent‘s smart tag and click the Expression property’s ellipsis button below the Source or Source URL property.

Assign an expression to the Source URL property

Use the invoked Expression Editor to create an expression that identifies the source of a PDF file.

Runtime

Create an ExpressionBinding class instance. Pass the Source or SourceUrl property name as the first constructor parameter and an expression string as the second parameter. Then, 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 the PDF file 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 control to the 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 control to the Detail band.
report.Bands[BandKind.Detail].Controls.Add(pdfContent);

Embed PDF File Content into a Report

Add the XRPdfContent control to a report, specify a PDF file location, and disable the control’s Generate Own Pages property.

Disable the Generate Own Pages property

Use Cases

  • Create a report with PDF file content and headers / footers that are printed on PDF file pages.

  • Print pictures, bar codes, page numbers, a report watermark, and other elements over the content of a PDF file.

  • Create a report document with paper kind that differs from PDF pages paper kind. Refer to the following section for instructions: Fit PDF File’s Page Size to Report’s Page Size.

  • Append PDF file content to report content and add sequential numbering to all report pages. For this, add PDF file content as a subreport to your report as described in the following section: Fit PDF File’s Page Size to Report’s Page Size. Then, add page numbers to both the subreport and main report.

  • Design a pre-printed form and use PDF file as a watermark.

    If your PDF file contains one page, follow the steps below:

    1. Embed this page into a report’s Detail band.
    2. Remove the report’s margins to prevent duplication with PDF page margins.
    3. Adjust the page size to make it fit the entire Detail band.

    If your PDF file contains multiple pages, do the following:

    1. Create a subreport for each of the pages. Follow the instructions in this section: Fit PDF File’s Page Size to Report’s Page Size. Use the XRPdfContent control’s PageRange property to specify the PDF file page that should be included to a subreport.
    2. Include each of these subreports to one report.

Fit PDF File’s Page Size to Report’s Page Size

A PDF file and a report to which you embed PDF file content might have different paper kind. PDF file pages can also be generated with double margins: page margins and report margins.

This section explains how to set the same paper kind for a report and its embedded PDF file and how to include only the PDF file’s page margins to the report. The main idea is to create a subreport that includes PDF pages in embedded mode, and then, add this subreport to the main report that contains initial content.

  1. Create a blank report. Set the report’s Paper Kind property to the paper kind of the main report to which you want to embed PDF content.

  2. Drop the XRPdfContent control from the Toolbox onto the created report’s Detail band, specify a PDF file source, and disable the control’s Generate Own Pages property.

    Add XRPdfContent control to a report

  3. Remove the report’s margins and adjust the XRPdfContent control size to make PDF content fit the entire Detail band.

    Adjust the XRPdfContent control's size

  4. Add the report as a subreport to your main report. Use the XRSubreport control with the Generate Own Pages property enabled.

    Add the XRPdfContent control as a subreport to the main report

    The following image demonstrates the main report’s Preview:

    The main report's Preview

Limitations

See Also