【问题标题】:MigraDoc text overflow into next page headerMigraDoc 文本溢出到下一页页眉
【发布时间】:2018-08-13 17:25:05
【问题描述】:

我正在使用 MigraDoc 在 PDF 中创建字母以进行批量打印。这意味着我有多家企业需要通知上市批准。我创建了一个包含通用信息的模板,并在 foreach 循环中为每个企业填写了信函的详细信息,如下所示:

   public TemplateClass(string title, string subject, string author, string memo_field)
    {
        try
        {
            //---------------------------------------------------
            // Set up the document and section
            //--------------------------------------------------
            _document = new Document();
            _section = new Section();

            //--------------------------------------------------------------
            // Define the margins, style
            //--------------------------------------------------------------
            this.DefineBorder();
            this.DefineStyle(_document);
            this.FillHeaderAndFooter(memo_field);              
        }
        catch { }
    }

private void FillHeaderAndFooter(string memo_field)
    {
        //------------------------------------------------
        // Add the main section of the document
        //-----------------------------------------------------
        this._section = this._document.AddSection();
        {
            this._section.PageSetup.Orientation = Orientation.Portrait;
            this._section.PageSetup.PageFormat = PageFormat.Letter;
            this._section.PageSetup.OddAndEvenPagesHeaderFooter = true;

            //-----------------------------------------------
            // Add the header
            //-----------------------------------------------
            Image primaryImage = this._section.Headers.Primary.AddImage(Image.png");
            primaryImage.Height = "4.0cm";
            primaryImage.LockAspectRatio = true;
            primaryImage.RelativeVertical = RelativeVertical.Line;
            primaryImage.RelativeHorizontal = RelativeHorizontal.Margin;
            primaryImage.Top = ShapePosition.Top;
            primaryImage.Left = ShapePosition.Center;
            primaryImage.WrapFormat.Style = WrapStyle.Through;

            //------------------------------------------------
            // Add the header to the section
            //------------------------------------------------
            this._section.Headers.Primary.Add(this.Header());
            this._section.Headers.EvenPage.Add(this.Header());

            this._section.Footers.Primary.Add(this.Footer());
            this._section.Footers.EvenPage.Add(this.Footer());
        }
    }

public void GenerateLetters()
{
    template = new TemplateClass("", "", "", "Business Letter");
        {
            int i = 0;
            base.DocumentName = "Business Letter";
            var businesses = new List<Business>() { new Business() { ID=333, Name="XYZ", Address = "123 Main St" }, new Business() { ID=666, Name="PQR", Address="123 Main St"}}

            foreach (var business in businesses)
            {                    
                template.ReportSection.Add(AddBusinessInfo(business));
                template.ReportSection.Add(FillTopSection());
                template.ReportSection.Add(FillMessage());                   

                template.ReportSection.Add(FillDetails(business));
                template.ReportSection.Add(FillBottomSection());
                template.ReportSection.Add(FillSignature());

                if (i != businesses.Count)
                    template.ReportSection.AddPageBreak();

                i++;
            }
}

我不会分享这里调用的一些私有方法的代码。 FillDetails(business) 是一个可以有一行或多行的表。此表格信息及其下方的内容被推送到具有标题的下一页并在其上重叠。

我可以从第二页开始跳过每个业务的页眉和页脚信息,或者避免与页眉重叠并以某种方式将信函的正文保持为静态大小。

【问题讨论】:

    标签: c# pdfsharp migradoc


    【解决方案1】:

    使用 MigraDoc 时,您必须设置一个足够大的顶部边框以容纳标题。如果 header 大于保留区域,则 header 和 body 可能会重叠,MigraDoc 无法阻止。

    仅在第一页上显示标题是另一种选择。

    【讨论】:

    • 我希望只在首页上设置页眉,但在每个企业的所有页面上设置页脚。我怎样才能做到这一点?
    • 指定您想要不同的首页页眉/页脚 (DifferentFirstPageHeaderFooter)。为首页设置页眉和页脚,只为标准页设置页脚(主页眉/页脚)。
    • 正如您在我的代码中看到的,我在模板类中定义的 FillHeaderAndFooter() 中添加了一个部分。我是否需要将此代码移动到另一个类并在 GenerateLetters() 中设置 DifferentFirstPageHeaderFooter 属性?
    • 我只看到代码sn-ps,无法完整分析。即使您将多个逻辑文档合并到一个 PDF 中,您也可能必须为每个新的逻辑文档开始一个新部分。这样,每个逻辑文档都将从自己的第一页开始。
    • 我尝试了你的建议。它现在只将页眉放在第一页上。我想要每个企业的第一页。每个企业可以有多个页面,具体取决于内容。我有多家企业,信件是循环构建的。我需要在每一项业务上都有标题。
    猜你喜欢
    • 1970-01-01
    • 2017-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-20
    • 1970-01-01
    • 2012-09-03
    相关资源
    最近更新 更多