【发布时间】:2018-12-07 12:27:07
【问题描述】:
我正在尝试在 rdlc 报告上显示图像,并且我保存了一个图像对象和一个名为 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)
{
}
}
这是我的打印功能
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();
}
这是我生成 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);
}
}
但无论我设置什么,我仍然会在报告中看到一个空白图像。正如你在下面看到的,确实有一张图片!
【问题讨论】:
-
数以百万计的 stack 用户难以相信,没有人能给出答案
标签: c# rdlc reportviewer