ImageExport Metafile in MemoryStream is always empty

Good morning, we are planning to move away from MS rdlc reporting, and i'm making some test with your solution. Due to some circumstances i need to export my reports in a metadata image on a MemoryStream but i encountered a problem, the stream is always empty. To be sure about my report i exported it to a FileStream and it seems to work. The "test-direct.emf" has the report contents, "page.emf" is transparent.

Thank you in advance for any help you can give.

Alessandro.


Here is my test code:

using (FastReport.Report rpt = FastReport.Report.FromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("Report.frx")))

{

  // Prepare report

  IEnumerable<PartListItem> source = (IEnumerable<PartListItem>)grid_Data.DataSource;

  rpt.SetParameterValue(

    "Title",

    $"{ts_Main_tb_Code.Text} TRIM {ts_Main_tb_Trim.Text} : {source.FirstOrDefault()?.Article}"

  );


  rpt.RegisterData(source, "DS_Bom");

  bool done = rpt.Prepare();

  if (!done || rpt.PreparedPages.Count == 0)

  {

    // Empty

    return;

  }


  //Export to File

  using (var exportFile = new ImageExport

  {

    ImageFormat = ImageExportFormat.Metafile

  })

  using (var fs = new FileStream(@"C:\temp\test-direct.emf", FileMode.Create, FileAccess.Write))

  {

    rpt.Export(exportFile, fs);

    fs.Flush(); //fs length > 60000

  }


  //Export to MemoryStream (use a NEW ImageExport instance)

  using (var ms = new MemoryStream())

  {

    using (var exportStream = new ImageExport

    {

      ImageFormat = ImageExportFormat.Metafile,

    })

    {

      rpt.Export(exportStream, ms);

    }

    //ms length < 1000

    // rewind and persist

    ms.Position = 0;

    byte[] myBytes = ms.ToArray();

    File.WriteAllBytes(@"C:\temp\page.emf", myBytes);

  }

}

Comments

  • Good morning.

    Looking at the sources i've found the "culprit". The problem appears when

    SeparateFiles = false

    MemoryStream is forced to false into the ImageExport Class when the image is a MetaFile.

    With my old rdlc i was able to render multiple streams (1 per page), so i was able to manage multiple pages even on MemoryStream output. Is there a way to accomplish the same in FastReports?


    Thank you.

  • Good morning, i'll bring good news.

    I've solved the issue creating my own exporter, now i get all my MetaFile streams.


    Alessandro.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.