In a two-step process, I was able to get Infragistics’ XamDatagrid (or any of their controls that implement DataPresenterBase) to PDF.
- Download GhostScript’s GhostPDL for windows (I got it from here).
- Use Infragistics’ Report Object to output an XPS (supported functionality)
- User GhostPDL to convert the XPS document to PDF
- 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!
Thanks Jason, just one question. What is a PDF?
seriously?
Is there any other way to convert xps to pdf for free?
Thanks in advance
@krishna Not that I have found.