最好还是先把所有报表生成 PDF再供预览(我的项目是这样处理的)
生成PDF后再将多个PDF合并成一个PDF文件,(报表合并比PDF合并复杂)
代码明天贴出吧!
我的思路也是这样的,求实例或者实现源码!能实现功能一定重谢!
@DotNet码农:
报表转PDF比较简单就不贴了 重点在合并PDF的代码
public class CombinePDF { #region 调用方式 //e.g: //CombinePDF combinePDF = new CombinePDF(); //string[] pdflist = new string[2]; //pdflist[0] = "C:\\RPT01.pdf"; //pdflist[1] = "C:\\RPT02.pdf"; //combinePDF.mergePDFFiles(pdflist, "newpdf.pdf"); #endregion /// <summary> 合併PDF檔(集合) </summary> /// <param name="fileList">欲合併PDF檔之集合(一筆以上)</param> /// <param name="outMergeFile">合併後的檔名</param> public bool mergePDFFiles(string[] fileList, string outMergeFile) { try { if (fileList.Length <= 0) { return false; } //outMergeFile = HttpContext.Current.Server.MapPath("Upload/" + outMergeFile); PdfReader reader; Document document = new Document(); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(outMergeFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)); document.Open(); PdfContentByte cb = writer.DirectContent; PdfImportedPage newPage; for (int i = 0; i < fileList.Length; i++) { reader = new PdfReader(fileList[i]); int iPageNum = reader.NumberOfPages; for (int j = 1; j <= iPageNum; j++) { document.NewPage(); newPage = writer.GetImportedPage(reader, j); cb.AddTemplate(newPage, 0, 0); } } document.Close(); writer.Close(); return true; } catch (Exception ex) { return false; } } }
@Zery: 合并后如何区分每个报表打印的数量呢
还有源码吗?我也想批量打印不同的报表