Objects placed after floating boxes are misaligned

Elements (i.e. table, textfragment, etc) that are added to a page following a floating box are out of position. Their x coordinates correspond to the floating box instead of the expected position. I have figured out ways around this but it seems like floating boxes should not impact the position of relatively positioned elements. Here’s a code example:

public void CreateTestPage()
    {
        Document doc = new();
        doc.PageInfo.Margin = new(20, 20, 20, 20);
        Page page = doc.Pages.Add();

        TextFragment firstFragment = new TextFragment("Before floating box");
        TextFragment secondFragment = new TextFragment("After floating box");
        
        FloatingBox fBox = new() { Left = 200, Top = 200 };
        fBox.Paragraphs.Add(new TextFragment("Floating box"));
        
        page.Paragraphs.Add(firstFragment);
        page.Paragraphs.Add(fBox);
        page.Paragraphs.Add(secondFragment);

        string path = string.Empty;
        using FileStream ms = new FileStream(path, FileMode.Create);
        doc.Save(ms);
    }

@canonmc

It seems that you are experiencing alignment issues with elements added after a floating box in your PDF document. This behavior can occur because floating boxes can affect the positioning of subsequent elements, as they are designed to allow flexible content placement.

To address this, you can try adjusting the positioning of the elements that follow the floating box. Here’s a modified version of your code that explicitly sets the position of the second text fragment to ensure it appears correctly after the floating box:

public void CreateTestPage()
{
    Document doc = new();
    doc.PageInfo.Margin = new(20, 20, 20, 20);
    Page page = doc.Pages.Add();

    TextFragment firstFragment = new TextFragment("Before floating box");
    FloatingBox fBox = new() { Left = 200, Top = 200 };
    fBox.Paragraphs.Add(new TextFragment("Floating box"));

    // Add the first fragment
    page.Paragraphs.Add(firstFragment);
    // Add the floating box
    page.Paragraphs.Add(fBox);
    
    // Adjust the position of the second fragment
    TextFragment secondFragment = new TextFragment("After floating box")
    {
        Position = new Position(200, 150) // Adjust the Y position as needed
    };

    // Add the second fragment
    page.Paragraphs.Add(secondFragment);

    string path = "output.pdf"; // Specify your output path
    using FileStream ms = new FileStream(path, FileMode.Create);
    doc.Save(ms);
}

In this example, I set the position of the second text fragment manually. You may need to adjust the Y coordinate based on the height of the floating box to ensure that it does not overlap.

If you continue to face issues, consider reviewing the documentation on floating boxes and their alignment properties, as they provide useful insights on how to manage content layout effectively in Aspose.PDF.

Feel free to reach out if you have further questions or need additional assistance!

Sources:
[1]: Text Alignment For Floating Box Contents In PDF File - Aspose

I understand the problem and how to fix it, but is this intentional behavior? It seems more like a bug than a feature.

@canonmc

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-58579

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.