RDLC报表后台输出PDF文件
RDLC报表后台输出PDF文件示例
private List<Stream> _pdfStreamList;
//先生成PDF数据
public void ExportPDF(LocalReport pReport) {
//pReport.Render(
Warning[] pWarnings; //存储警告项
string[] pStreamids;
string pMimeType;
string pEncoding;
string pExtensions;
byte[] pBytes = pReport.Render("PDF", null, out pMimeType, out pEncoding,out pExtensions,out pStreamids,out pWarnings);
if (_pdfStreamList == null) {
_pdfStreamList = new List<Stream>();
}
MemoryStream pStream = new MemoryStream();
//if (_pdfStream == null) {
// _pdfStream = new MemoryStream();
//}
//else {
//}
pStream.Write(pBytes, 0, pBytes.Length);
_pdfStreamList.Add(pStream);
}
//把PDF数据写入文件
public void savePDFFile(string pFileName) {
if (_pdfStreamList == null) {
throw new RDLFProxyException("在未调用ExportPDF生成报表数据之前,不能调用savePDFFile生成pdf文件");
}
FileStream pFileStream = new FileStream(pFileName, FileMode.Create);
foreach (MemoryStream pStream in _pdfStreamList) {
byte[] pBuffer = new byte[(int)pStream.Length];
pStream.Seek(0, SeekOrigin.Begin);
pStream.Read(pBuffer, 0, (int)pStream.Length);
pFileStream.Write(pBuffer, 0, pBuffer.Length);
break;
}
pFileStream.Close();
}