Printing the Infragistics XamDataGrid (or other DataPresenterBase object) to PDF

02 Feb

In a two-step process, I was able to get Infragistics’ XamDatagrid (or any of their controls that implement DataPresenterBase) to PDF.

  1. Download GhostScript’s GhostPDL for windows (I got it from here).
  2. Use Infragistics’ Report Object to output an XPS (supported functionality)
  3. User GhostPDL to convert the XPS document to PDF
  4. Delete the temporary XPS document

Here’s the method I used successfully:

public void GeneratePdf(DataPresenterBase dataPresenterBase, string filePath) {
    dataPresenterBase.AutoFit = true;
    var reportObj = new Report();
    reportObj.Sections.Add(new EmbeddedVisualReportSection(dataPresenterBase));
    reportObj.ReportSettings.Margin = new Thickness(5, 5, 5, 5);
    reportObj.ReportSettings.PageOrientation = PageOrientation.Landscape;
    reportObj.ReportSettings.PageSize = NorthAmerica11X17;
    reportObj.ReportSettings.HorizontalPaginationMode = HorizontalPaginationMode.Scale;
    var xpsTempFile = filePath.Replace(“.pdf”, “.xps”);
    reportObj.Export(OutputFormat.XPS, xpsTempFile, false);
    dataPresenterBase.AutoFit = false;

    var p = new Process {
        StartInfo = {
            UseShellExecute = false,
            CreateNoWindow = true,
            RedirectStandardOutput = true,
            FileName = @”gxps-871.exe”,
            Arguments = string.Format(“-sDEVICE=pdfwrite -sOutputFile=\”{0}\” -dNOPAUSE \”{1}\””, filePath, xpsTempFile)

Hope this helps!

About these ads

Posted by on 2012/02/02 in Uncategorized


4 responses to “Printing the Infragistics XamDataGrid (or other DataPresenterBase object) to PDF

  1. Hodgie

    2012/02/02 at 12:23 pm

    Thanks Jason, just one question. What is a PDF?

    • Me

      2012/02/03 at 1:14 am


  2. krishna

    2012/07/05 at 6:26 am

    Is there any other way to convert xps to pdf for free?

    Thanks in advance

  3. huntjason

    2012/07/05 at 8:14 am

    @krishna Not that I have found.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: