本文介绍了将代码渲染为PDF格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hai,
这是我的代码:
Hai,
This is my code:
DataTable dtDS = ds.Tables["tblDS"];
if (dtDS.Rows.Count != 0)
{
DataRow dr = dtDS.Rows[0];
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
LocalReport lr = viewer.LocalReport;
lr.ReportPath = ConfigUtil.GetAppSetting("DataSheetType_" + dr["DataSheetType"].ToString());
ReportDataSource rds = new ReportDataSource();
rds.Value = ds.Tables[0];
rds.Name = "report";
HTMLConverter rtf = new HTMLConverter();
if (dr["SO1_Address"].ToString() != "")
{
dr["SO1_Address"] = rtf.HTML2RTF(dr["SO1_Address"].ToString(), 16);
}
lr.DataSources.Add(rds);
string reportType = "PDF";
string mimeType = "application/pdf";
string encoding;
string fileNameExtension = Guid.NewGuid().ToString() + ".pdf";
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = lr.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);
Response.BinaryWrite(renderedBytes);
Response.End();
}
代码编译器在尝试执行lr.Render代码时返回异常。我不知道出了什么问题?
lr.ReportPath是一个rdlc报告文件。
The code compiler returns an exception while trying to execute the lr.Render code. I have no idea what's wrong?
lr.ReportPath is an rdlc report file.
推荐答案
这篇关于将代码渲染为PDF格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!