Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用FastReport.net和asp.net导出pdf_C#_Asp.net Mvc_Fastreport - Fatal编程技术网

C# 使用FastReport.net和asp.net导出pdf

C# 使用FastReport.net和asp.net导出pdf,c#,asp.net-mvc,fastreport,C#,Asp.net Mvc,Fastreport,如何使用FastReport.net和asp.net导出pdf? 我想导出控制器中的文件。我通过FastReport网站支持的方式进行了尝试: public FileResult GetFile() { WebReport webReport = new WebReport(); // bind data System.Data.DataSet dataSet = new System.Data.DataS

如何使用
FastReport.net
asp.net
导出
pdf
? 我想导出控制器中的文件。我通过FastReport网站支持的方式进行了尝试:

public FileResult GetFile()
        {
            WebReport webReport = new WebReport();

            // bind data
            System.Data.DataSet dataSet = new System.Data.DataSet();
            dataSet.ReadXml(report_path + "nwind.xml");
            webReport.Report.RegisterData(dataSet, "NorthWind");

            // load report
            webReport.ReportFile = this.Server.MapPath("~/App_Data/report.frx");

            // prepare report
            webReport.Report.Prepare();

            // save file in stream
            Stream stream = new MemoryStream();
            webReport.Report.Export(new PDFExport(), stream);
            stream.Position = 0;

            // return stream in browser
            return File(stream, "application/zip", "report.pdf");
        }
但是
pdf
的大小总是0字节


有人知道我的问题的解决办法吗?

好的,现在我找到了解决办法。只需使用正常的
报告
(而不是
WebReport
),并将
WebMode
设置为
true
。pdf导出上的其他设置只是为了好玩

因此,这将实现以下目的:

public FileResult GetFile(Dataset dataset1)
{
    FastReport.Utils.Config.WebMode = true;
    Report rep = new Report();
    rep.Load(Request.PhysicalApplicationPath + "App_Data/report.frx");    

    rep.RegisterData(dataset1);

    if (rep.Report.Prepare())
    {
        // Set PDF export props
        FastReport.Export.Pdf.PDFExport pdfExport = new FastReport.Export.Pdf.PDFExport();
        pdfExport.ShowProgress = false;
        pdfExport.Subject = "Subject";
        pdfExport.Title = "xxxxxxx";
        pdfExport.Compressed = true;
        pdfExport.AllowPrint = true;
        pdfExport.EmbeddingFonts = true;

        MemoryStream strm = new MemoryStream();
        rep.Report.Export(pdfExport, strm);
        rep.Dispose();
        pdfExport.Dispose();
        strm.Position = 0;

        // return stream in browser
        return File(strm, "application/pdf", "report.pdf");
    }
    else
    {
        return null;
    } 
}
遗憾的是,这样的代码模板在开发人员的官方网站上是错误的。

在2017年对我有效。1

    public void GetFile()
    {
        SetReport();
        webReport.ExportPdf();
    }

    public void GetPrint()
    {
        SetReport();
        webReport.Prepare();
        webReport.PrintPdf();
    }