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.