【问题标题】:RDLC Dynamic Footer SizeRDLC 动态页脚大小
【发布时间】:2018-05-11 11:08:50
【问题描述】:

我想知道您是否可以为报表设置不同的页脚大小。

我想要达到的目标如下:

  • 首页有 0.75" 页脚
  • 其他页面的页脚为 1.25 英寸

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

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

【问题讨论】:

    标签: reporting-services rdlc subreport


    【解决方案1】:

    我无法使用 RDLC 找到解决此问题的方法。该技术的文档中指出,用于页眉和页脚的空间将为所有页面保留,即使您隐藏特定页面的页眉/页脚,并且子报表将仅使用主报表的页眉和页脚。我还阅读了一些文章,指出与 Crystal Reports 相比,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 文件。

    希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-30
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多