我正在尝试在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);
}
}
但是无论我设置了什么,报告上仍然会显示空白图像。正如您在下面看到的,确实有一张图片!
答案 0 :(得分:0)
您似乎正在使用文件,因此图像源必须设置为{
"request" : {
"method": "GET",
"urlPattern": "^\/my\/service\/url\\?.*(specificParam.*(M[0-9]{9})).*$"
},
"response": {
...
}
}
。
您已经设置了External
,所以最后要做的是传递转换为URI(Convert file path to a file URI?)的文件路径。