分页上的MigraDoc TextFrame Wrapstyle

时间:2019-05-02 13:29:18

标签: c# page-break migradoc

我正在MigraDoc中使用TextFrames来显示内联表(每行2个)-这似乎可以解决问题:

enter image description here

...直到页面结尾接近。

enter image description here (红色框是TextFrame边框-包括在内以帮助可视化事物)

似乎有一个阈值,尽管第一行的第二张表实际上比第一张表短,但它决定进入下一页。如果有空间,我希望两个表都放在同一页上。

我正在使用的代码如下。它存在于为一行中的每个表调用的方法中:

                        TextFrame newTF = new TextFrame();
                        newTF.Add(newTable.Clone());

                        Unit tfWidth = 0;
                        foreach (Column tableCol in newTable.Columns)
                            tfWidth += tableCol.Width;

                        newTF.Width = Unit.FromPoint(tfWidth);
                        newTF.WrapFormat.Style = WrapStyle.Through;
                        newTF.LineFormat.Color = GetColourFromHex("#FF0000");

                        int currentTableHeight = 14 * newTable.Rows.Count;
                        double currentPosition = GetMigraHeightPosition();

                        if (currentPosition + currentTableHeight > pageActiveHeight)
                            this.document.LastSection.AddPageBreak();

                        if (sourceTable.InLineRootTableId == sourceTable.Id) // If this is the first table of the row...
                        {
                            currentInlineTableCount = 1;
                            newTF.RelativeVertical = RelativeVertical.Line;
                            newTF.RelativeHorizontal = RelativeHorizontal.Margin;
                            maxInlineTableCount = sourceTable.InlineTablesNumber;
                            maxInlineTableHeight = currentTableHeight;
                            newTF.Height = Unit.FromPoint(maxInlineTableHeight);

                            this.document.LastSection.Add(newTF);
                        }
                        else
                        {
                            newTF.RelativeHorizontal = RelativeHorizontal.Character;

                            currentInlineTableCount++;
                            newTF.Left = Unit.FromPoint(newTF.Width + 50);

                            if (maxInlineTableHeight < currentTableHeight)
                                maxInlineTableHeight = currentTableHeight;

                            newTF.Height = Unit.FromPoint(maxInlineTableHeight);

                            if (currentInlineTableCount == maxInlineTableCount)   // If this is the LAST table in the row
                            {
                                newTF.WrapFormat.Style = WrapStyle.TopBottom;
                                currentInlineTableCount = 1;
                            }

                            this.document.LastSection.Add(newTF);
                        }


    public double GetMigraHeightPosition()
    {
        MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(this.document);
        docRenderer.PrepareDocument();

        RenderInfo[] RenderInfos = docRenderer.GetRenderInfoFromPage(docRenderer.FormattedDocument.PageCount);
        RenderInfo r = RenderInfos[RenderInfos.Count() - 1];
        return r.LayoutInfo.ContentArea.Y + r.LayoutInfo.ContentArea.Height;
    }

如果我继续强迫表格向下移动,使它们全部位于下一页,它们又回到同一行了吗?!

有人知道我可能在哪里出错吗?

0 个答案:

没有答案