I want to export a multi page report (FastReport) to image

var stream = new MemoryStream();
rpt.Export(new ImageExport(), result);

reports with one page is OK, but multipage reports have this error :

empty path name is not legal

Have any idea to solve this?!

有帮助吗?

解决方案

You should use path, instead of stream.

Example with path:

using (FastReport.Report report = new FastReport.Report())
{
    report.Load(@"C:\test.frx");

    report.Prepare();                               
    report.Export(new FastReport.Export.Image.ImageExport(), "myReport.png");             
}

When report has more than one page, the following files will be created:

myReport.png
myReport.2.png
myReport.3.png
...

Here is solution with stream. You should set PageRange = PageRange.Current and set CurPage to appropriate value:

int count = 1;
using (FastReport.Report report = new FastReport.Report())
{
    report.Load(@"C:\test.frx");
    report.Prepare();

    foreach (PageBase item in report.Pages)
    {
        string fileName = string.Format("myReport_{0}.png", count);
        report.Export(new FastReport.Export.Image.ImageExport() { PageRange = PageRange.Current, CurPage = count }, fileName);
        count++;
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top