简体   繁体   中英

Crystal Reports takes hours to export to pdf by code

I´m facing this issue a long time, after months i´m still not able to find any solution. Here´s the scenario: VS 2019, Framework 4.6 and Crystal reports 13_0_27.

The following code takes hours to export a pdf (about 400 pages and 30.000 rows). If i open the report with crystal reports and export the document, same query by code, only takes seconds.

I tried a couple things, like ExportToStream and save the stream to file, or exporting direcly to disk and other post did read that "pdfFormatOptions.UsePageRange = True" should help, but same result.

The code works fine with smalls pdfs with, for example, 100 rows.

Informe.Load(Application.StartupPath + @"\informes\report.rpt");

        for (i = 0; i < Informe.Database.Tables.Count; ++i)
        {
            logOnInfo.ConnectionInfo.ServerName = "Server";
            logOnInfo.ConnectionInfo.DatabaseName = "BBDD";
            logOnInfo.ConnectionInfo.UserID = "user";
            logOnInfo.ConnectionInfo.Password = "user";
            Informe.Database.Tables[i].ApplyLogOnInfo(logOnInfo);
        }

        diskOpts.DiskFileName = PDFPath + _cabe.Guid + "_minutos.pdf";
        ExportOptions exportOpts2 = Informe.ExportOptions;
        exportOpts2.DestinationOptions = diskOpts;
        exportOpts2.ExportFormatType = ExportFormatType.PortableDocFormat;
        exportOpts2.ExportDestinationType = ExportDestinationType.DiskFile;
        
        try
        {
            Informe.RecordSelectionFormula = @" {CabeceraFacturas.Guid}='{" + _cabe.Guid.ToString() + "}'";
            //Informe.Export();
            Stream oStream;
            oStream = (Stream)Informe.ExportToStream(ExportFormatType.PortableDocFormat);

            using (FileStream fileStream = File.Create(RutaGeneracionPDF + _cabe.Guid + "_minutos.pdf", (int)oStream.Length))
            {
                byte[] bytesInStream = new byte[oStream.Length];
                oStream.Read(bytesInStream, 0, bytesInStream.Length);
                fileStream.Write(bytesInStream, 0, bytesInStream.Length);
                fileStream.Close();
            }


        }

Thanks!

After expending days and hours and headaches i finally did the trick.

in each detail (About 30.000 rows) i had a formula wich calculated some value with two fields of the detail and two from a joined view. the view was the problem when i was exporting by code (Exporting within Crystal Reports worked ok with no delay). I had to create a new table in SQL, inserting all the rows in view in this new table and add this table to report and..voilá, it worked, exported report in seconds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM