0

I am trying to display an image on a rdlc report and I have an image object and a parameter saved called BoxImage.

public void Run(string BoxImage, string LogoImage)
{
    try 
    { 
        LocalReport report = new LocalReport();

        var path = System.Windows.Forms.Application.StartupPath;
        log.Info(Path.Combine(path, @"Reporting\QCLabelV2.rdlc"));
        report.ReportPath = Path.Combine(path, @"Reporting\QCLabelV2.rdlc");
        report.EnableExternalImages = true;
        ReportParameter boxImage = new ReportParameter("BoxImage");
        boxImage.Values.Add(BoxImage);
        report.SetParameters(boxImage);

        report.DataSources.Clear();
        report.DataSources.Add(new ReportDataSource("dsList", LoadSalesData()));

        report.Refresh();
        log.Info("Finished Refresh");
        Export(report);
        log.Info("Export Complete");
        Print();
        log.Info("Print Complete");
    }
    catch (Exception ex)
    {

    }
}

This is my print function

private void Print()
{
    ProcessStartInfo info = new ProcessStartInfo();
    info.Verb = "print";
    var path = System.Windows.Forms.Application.StartupPath;
    info.FileName = Path.Combine(path, @"Reporting\BoxLabel.pdf");
    info.CreateNoWindow = true;
    info.WindowStyle = ProcessWindowStyle.Hidden;

    Process p = new Process();
    p.StartInfo = info;
    p.Start();

    p.WaitForInputIdle();
    System.Threading.Thread.Sleep(3000);
    if (false == p.CloseMainWindow())
        p.Kill();
}

And this is my export function which generates the pdf.

private void Export(LocalReport report)
{ 

        byte[] Bytes = report.Render(format: "PDF", deviceInfo: "");

        var path = System.Windows.Forms.Application.StartupPath;
        log.Info("About to create file - " + Path.Combine(path, @"Reporting\BoxLabel.pdf"));
        using (FileStream stream = new FileStream(Path.Combine(path, @"Reporting\BoxLabel.pdf"), FileMode.Create))
        {
            stream.Write(Bytes, 0, Bytes.Length);
        }
        path = Properties.Settings.Default.AssemblyLabelLocation;
        log.Info("About to create file - " + Path.Combine(path, _objectList.First().BarcodeValue.Replace("*", "") + " - " + _objectList.First().ProductCode + ".pdf"));
        using (FileStream stream = new FileStream(Path.Combine(path, _objectList.First().BarcodeValue.Replace("*", "") + " - " + _objectList.First().ProductCode + ".pdf"), FileMode.Create))
        {
            stream.Write(Bytes, 0, Bytes.Length);
        }



}

But no matter what I set I still get a blank image on the report. And as you see below, indeed there's an image!

enter image description here

Parameter setup for the image properties enter image description here

Daniel B
  • 3,109
  • 2
  • 33
  • 42
David B
  • 315
  • 3
  • 13

1 Answers1

0

It seems that you are using a file so the image source must be set to External.

You already set ReportViewer.LocalReport.EnableExternalImage = True so the last thing to do is passing a file path converted as URI (Convert file path to a file URI?).

tezzo
  • 10,858
  • 1
  • 25
  • 48