2

Long time lurker, first time poster.

I'm currently working an WPF app that makes use of OxyPlot to generate a graph. I wish to export the generated graph to a ReportDocument (RDLC) and print it as a PDF using CutePdf. I am able to do this successfully.

Currently the approach I have take to do this is by executing the below code snippet.

using (var memStream = new MemoryStream())
{
   PngExporter.Export(PlotModel, memStream, 850, 700, OxyColors.White, 120);
   var fromStream = Image.FromStream(memStream);
   fromStream.Save(memStream, ImageFormat.Png);
   imageArray = new byte[memStream.Length];
   memStream.Seek(0, SeekOrigin.Begin);
   memStream.Read(imageArray, 0, (int) memStream.Length);
}

var stringBytes = Convert.ToBase64String(imageArray);

To pass this to a RDLC, I have to convert the memory stream to a Base64String and pass that as a parameter. As so;

var parameter = new ReportParameter("Chart", stringBytes);

reportViewer.LocalReport.SetParameters(parameter);

However, whilst this is all fine and dandy, the image output in the PDF seems to be incredibly blurry and pixelated when I zoom into it, whilst the surrounding text on the page is crisp.

I've had a go at plainly saving the image to disk as PNG/BMP/JPG but that also seems to return a blurry image so it's not a sizing issue.

  using (var stream = File.Create("testChart.png"))
  {
     var pngExporter = new PngExporter();
     pngExporter.Export(PlotModel, stream);
  }

I've attached a copy of the PDF with this post to show what I mean.

Thanks!

Monza972
  • 51
  • 6
  • Link doesn't work anymore. Did you ever solve this? – Automate This Mar 07 '17 at 20:31
  • @PortlandRunner - Hi! I managed to lose my access to SO so only just seeing your question. Yes, I did manage to solve it. I had to export it to .png using `PngExporter.ExportToBitMap` and then convert it using .NET's `BmpBitmapEncoder`, setting a resolution, passing the bitmap stream to `Image.FromStream` and returning it back as a `byte[]`. I can't give exact code as it's part of a work solution but a lot of experimentation with it did the trick :) – Monza972 Oct 02 '19 at 17:07

0 Answers0