Exep 发表于 2015-8-7 11:05:00

把dataset导出到pdf

请问如何能把一个查询出的dataset导出到pdf文件,谢谢

frank.zhang 发表于 2015-8-7 13:59:00

您好,
跟之前给导出的Excel的例子是一致的,改了相关导出PDF的方法。
            GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("~/Reports/" + report + ".rdlx")));
            _reportDef.Report.DataSources.DataSourceReference = "";
            _reportDef.Report.DataSources.ConnectionProperties.DataProvider = "OLEDB";
            _reportDef.Report.DataSources.ConnectionProperties.ConnectString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", Server.MapPath("~/Data/NWind_CHS.mdb"));

            GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);

            // Create an output directory
            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            // Provide settings for your rendering output.
            GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new
            GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
            GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = pdfSetting;
            //Set the rendering extension and render the report.
            GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension =
            new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
            GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
            _reportRuntime.Render(pdfRenderingExtension, outputProvider, pdfSetting);

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=客户订单.pdf");
            outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
            Response.BinaryWrite(ms.ToArray());
            Response.End();

Exep 发表于 2015-8-7 14:01:00

好的谢谢您的解答如果有什么问题我还会继续请教

frank.zhang 发表于 2015-8-7 15:47:00

好的,
没有问题。
页: [1]
查看完整版本: 把dataset导出到pdf