1

我是新手,我想从InfragisticsXamdatagrid生成PDF。但是,由于 Infragistics 不提供此功能,我已经生成了Xamdatagrid的XPS ,并希望以编程方式将其转换为 XPS。有哪些可能的解决方法和第三方工具可以做到这一点?

4

3 回答 3

2

如果您将 xamDataGrid 导出为 excel 文件,那么使用起来非常简单,Excel.Interop并要求 excel 以 PDF 格式导出其工作簿

// Export an excel workbok in PDF format with landscape orientation
private static void ExportWorkbookToPDF(string workbook, string output)
{
    Microsoft.Office.Interop.Excel.Application excelApplication = 
                     new Microsoft.Office.Interop.Excel.Application();
    excelApplication.ScreenUpdating = false;
    excelApplication.DisplayAlerts = false;
    excelApplication.Visible = false;

    Microsoft.Office.Interop.Excel.Workbook excelWorkbook = 
                     excelApplication.Workbooks.Open(workbook);

    if (excelWorkbook == null)
    {
        excelApplication.Quit();
        excelApplication = null;
        excelWorkbook = null;
        throw new NullReferenceException("Cannot create new excel workbook.");
    }
    try
    {
        ((Microsoft.Office.Interop.Excel._Worksheet)excelWorkbook.ActiveSheet).PageSetup.Orientation = 
                Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;
        excelWorkbook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, output);
    }
    finally
    {
        excelWorkbook.Close();
        excelApplication.Quit();
        excelApplication = null;
        excelWorkbook = null;
    }
}
于 2012-08-24T12:08:56.953 回答
0

如果您只想创建 pdf。那么最简单的事情就是在机器上安装任何 pdf 打印机。一个像 PDF 创建器,然后只需在 XamDataGrid 上调用如下所示的打印内容。

确保在打印机选择对话框中选择 PDF 打印机。

             // 1. Create Report object
            Report reportObj = new Report();

            // 2. Create EmbeddedVisualReportSection section. 
            // Put the grid you want to print as a parameter of section's constructor
            EmbeddedVisualReportSection section = new EmbeddedVisualReportSection(xamdg);

            // 3. Add created section to report's section collection
            reportObj.Sections.Add(section);

            // Optional. If you have progress indicator set its Report property to created report
           // progressInfo.Report = reportObj;

            // 4. Call print method
            reportObj.Print(true, false);
于 2012-08-23T13:31:21.877 回答
0

您还可以使用 GhostXPS 等第三方软件。 http://www.ghostscript.com/download/gxpsdnld.html

只需使用正确的参数启动转换过程,它就会为您生成 PDF。缺点是您必须将文件临时保存到磁盘并检查返回码。还要确保您没有违反 GNU 许可证

于 2012-08-23T14:25:15.740 回答