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

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)
        }
    };
    p.Start();
    p.StandardOutput.ReadToEnd();
    p.WaitForExit();
    File.Delete(xpsTempFile);
}

Hope this helps!

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

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

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

    Thanks in advance

  3. @krishna Not that I have found.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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