RDLC 动态页脚大小

RDLC Dynamic Footer Size

我想知道您是否可以为一份报告设置不同的页脚尺寸。

我想要实现的是:

我试过使用子报表,但遗憾的是子报表的页眉和页脚没有显示,我发现这是 RDLC 中的设计限制。

我怎样才能做到这一点? TIA.

我无法使用 RDLC 找到解决此问题的方法。在该技术的文档中指出,用于页眉和页脚的 space 将保留用于所有页面,即使您隐藏了特定页面的 header/footer 并且子报表将仅使用主报告的页眉和页脚。我还阅读了一些文章,指出与 Crystal 报告相比,RDLC 对设计的控制较少,根据我的经验,这是真实的。

有了这个,我采用了我的最后一个选项,即构建 2 个单独的 PDF 文件并使用 iTextSharp 合并它们。幸好 iTextSharp 具有获取 pdf 页数的功能。

PdfReader pdfReader = new PdfReader(renderedBytes); 
// renderedBytes is the byte array generated by localReport.Render

pageCount = pdfReader.NumberOfPages;

这是我的部分代码:

int subreportPageCount = 0;
double gpa = 0;

byte[] subreportBytes = GenerateTranscriptOfRecordsSubreportPDF(unitOfWork, student, torType, out subreportPageCount, out gpa);
byte[] mainBytes = GenerateTranscriptOfRecordsMainPDF(unitOfWork, student, torType, torPurpose, subreportBytes, subreportPageCount, gpa);
byte[] renderedBytes = MergePDF(new List<byte[]>() { mainBytes, subreportBytes });

string reportFormat = Constant.REPORT_FORMAT_PDF;
string fileExtension = GetReportFileExtension(reportFormat);
string fileName = Constant.REPORT_TOR_FILENAME;
string fileNameWithExtension = string.Format("{0}{1}", fileName, fileExtension);
string mimeType = "application/pdf";
string fileNameExtension = "pdf";
string fileInfoName = string.Format("{0}.{1}", fileName, fileNameExtension);

ReportFile reportFile = new ReportFile();
reportFile.Content = renderedBytes;
reportFile.FileName = fileInfoName;
reportFile.MimeType = mimeType;

Session[Constant.SESSION_REPORT_FILE] = reportFile;

合并PDF:

byte[] MergePDF(ICollection<byte[]> pdfs)
{
    byte[] renderedBytes = null;

    using (MemoryStream ms = new MemoryStream())
    {
        Document document = new Document();
        PdfCopy pdf = new PdfCopy(document, ms);
        PdfReader pdfReader = null;

        try
        {
            document.Open();
            foreach (byte[] pdfBytes in pdfs)
            {
                pdfReader = new PdfReader(pdfBytes);
                pdf.AddDocument(pdfReader);
                pdfReader.Close();
            }
        }
        catch (Exception)
        {
            renderedBytes = null;
        }
        finally
        {
            if (pdfReader != null)
            {
                pdfReader.Close();
            }
            if (document != null)
            {
                document.Close();
            }
        }

        renderedBytes = ms.ToArray();

        return renderedBytes;
    }
}

我将此作为最后的手段,因为我将无法为我的报告生成 XML 和 DOC 文件,除非我从头开始重新构建它们。幸运的是,我的要求是简单地生成一个 PDF 文件。

希望对您有所帮助!