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

XRPdfContent.SourceUrl Property

Specifies the PDF document to be rendered in the report. Use a local file system path or URL to reference a document.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v21.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

[DefaultValue("")]
[SRCategory(ReportStringId.CatData)]
public string SourceUrl { get; set; }

Property Value

Type Default Description
String String.Empty

The URL or path to a PDF document that should be rendered in the report.

Remarks

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

You can use expressions to conditionally specify the SourceUrl property value or bind it to a report parameters or data source field. Add an item to the XRPdfContent.ExpressionBindings collection to set an expression.

Use the Source property instead of SourceUrl to include the binary PDF content in a report.

Tip

The SourceUrl property value takes precedence over the Source value. If you specify both properties, the XRPdfContent control 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.

Specify a PDF File Path

You can assign an absolute or relative path to the SourceUrl property.

A relative path refers to a location that is relative to the base directory. In ASP.NET you can use the ~ operator in combination with folders to specify a path based on the current root (the path “~/myPDF.pdf” is the relative path to the myPDF.pdf file located in the root directory).

You should allow access to the root directory in ASP.NET applications explicitly because reporting components have access only to URLs. For this, run the following code at application startup:

using DevExpress.Security.Resources;
// ...
    AccessSettings.StaticResources.TrySetRules(
        DevExpress.Security.Resources.DirectoryAccessRule.Allow(Server.MapPath("~/")));
// ...

Examples

The code below creates an XRPdfContent control, adds it to a report’s Detail band, and sets the control’s SourceUrl property to the 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();
// 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);

The code below creates an XRPdfContent control and uses an expression to bind 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);
See Also