Wigstyle TextFrame MigraDoc на разрыв страницы - PullRequest
0 голосов
/ 02 мая 2019

Я использую TextFrames в MigraDoc, чтобы иметь возможность отображать встроенные таблицы (по 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;
    }

Если я продолжу заставлять таблицы, чтобы они все были на следующей странице, они возвращались к одной строке?!

Кто-нибудь знает, где я могу пойти не так, пожалуйста?

...