Completed
Last Updated: 17 May 2023 11:40 by ADMIN
Release R2 2023
Jase
Created on: 27 Feb 2023 10:34
Category: WordsProcessing
Type: Bug Report
0
WordsProcessing: Inserting a table right after a page break adds a paragraph in between

Using a RadFlowDocumentEditor to add a page break and then insert a table, adds an additional paragraph in between.

 

As a workaround you can call the CleanParagraphsBeforeTablesOnNewPage() method:

private void CleanParagraphsBeforeTablesOnNewPage()
{
    List<Paragraph> paragraphs = this.flowDocument.EnumerateChildrenOfType<Paragraph>().ToList();
    foreach (var paragraph in paragraphs)
    {
        BlockContainerBase parent = (BlockContainerBase)paragraph.Parent;
        int paragraphIndex = parent.Blocks.IndexOf(paragraph);
        int blocksCount = parent.Blocks.Count;

        bool isAfterPageBreak = paragraphIndex > 0 && this.PreviousBlockEndsWithPageBreak(parent.Blocks[paragraphIndex - 1]);

        int nextIndex = paragraphIndex + 1;
        bool nextBlockIsTable = nextIndex < blocksCount && parent.Blocks[nextIndex] is Table;

        if (isAfterPageBreak && nextBlockIsTable)
        {
            parent.Blocks.Remove(paragraph);
        }
    }
}

private bool PreviousBlockEndsWithPageBreak(BlockBase blockBase)
{
    bool isLastInlinePageBreak = false;
    bool isParagraph = blockBase is Paragraph;
    if (isParagraph)
    {
        Paragraph paragraph = (Paragraph)blockBase;
        InlineBase lastInline = paragraph.Inlines.Last();

        bool isBreak = lastInline is Break;
        if (isBreak)
        {
            isLastInlinePageBreak = ((Break)lastInline).BreakType == BreakType.PageBreak;
        }
    }

    return isLastInlinePageBreak;
}

0 comments