Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
350
Exporting PDF report to file, file is invalid.
posted

I'm attempting to generate a report in a .NET console application using the following code:

 

This executes without error, however the output file testReport.pdf is just an empty file (0 bytes) and Adobe Reader displays an error when I try to open it. The TestReport.igr is just a report with an "I AM A REPORT" text block in it. There are no databindings or parameters in it yet.

 

Am I missing something? This will be an application that runs nightly with no user interaction. I need to be able to generate reports and save them to file. Is there a better way of going about this?

Parents
  • 53790
    posted

    Hello Tyler,

     

    There are different reasons that could cause your issue. One possible reason could be if you have not permissions to that folder, another possible reasons could be if you try to  export  your .pdf file, before finishing the report. In that case you could handle this exception with try / catch -  “This operation requires a viewer with a report that has finished loading.”    Looking at your code, I suppose that the most probable reason for your issue, could be if you didn`t include your UltraReportViewer in the control collection.  It is very easy to reproduce this scenario. Please take a look on attached video file for more  details.  Here is the code that I used in my samples:

     

       UltraReportViewer rv = new UltraReportViewer();

                Infragistics.Win.UltraWinReportViewer.ClientRenderSettings clientRenderSettings11 = new Infragistics.Win.UltraWinReportViewer.ClientRenderSettings();

                Controls.Add(rv);

                rv.AutoRender = true;

                rv.CurrentPage = 0;

                rv.IsParametersPaneVisible = true;

                rv.MergedDictionary = null;

                rv.Name = "RV1";

                rv.PageFit = Infragistics.Controls.Reports.PageFit.ZoomScale;

                clientRenderSettings11.DefinitionStream = null;

                clientRenderSettings11.DefinitionUri = new System.Uri("/Test 5555;component/Report1.igr", System.UriKind.Relative);

                rv.RenderSettings = clientRenderSettings11;

                rv.TabIndex = 0;

                rv.ZoomScale = 100;

                IClientExporter exporter = rv.CreateExporter(clientRenderSettings11.DefinitionUri);

                FileStream fileStream = new FileStream("..\\..\\TTTT.pdf", FileMode.Create);

                exporter.ExportCompleted += new EventHandler<ExportCompletedEventArgs>(exporter_ExportCompleted);

                exporter.ExportAsync(fileStream, "PDF");

     

     

    Tyler Olivier said:
    This will be an application that runs nightly with no user interaction. I need to be able to generate reports and save them to file. Is there a better way of going about this?

    There are many approaches to solve this task.  You could create application which using continues loop thread to  create your reports, another possible solution could be with windows service (this is my favorite approach). In this case, please do not forget to allow the service to interact with desktop. Another solution could be with WCF service or Windows Tray Application and so on.  But maybe the easiest way to solve this task, could be if you are using “Task Sheduler” of your OS or Windows Tray Application.

     

    Please take a look on attached video file where I used two different approaches (with threads and Windows Service) Of course these approaches are more complicate but they have another advantages. Please note that in  both scenarios my UltraReportViewer is include in control collections.

    Let me know if you have any questions.

     

    Video327.rar
Reply Children