Measuring row height is not working when it contains HtmlFragments

Hello.

I am using the property IsRowBroken on the Row class to keep some pieces of text in a single page.

More precisely, I have a table (containing TextFragments) inside another table and the parent table row has the IsRowBroken set accordingly (based on some row height calculations that I do), so that the contents of the inner table stick together in a single page.

Recently, I have replaced TextFragment with HtmlFragment, in order to use HTML content instead of text.
But there are several problems:

  1. I see that IsRowBroken = false does not work when I apply it on a row that contains HtmlFragments.

  2. It seems that measuring the row contents does not return correct values when HtmlFragments are used inside the row. For the same text input, I get a height of 44 instead of 122, which is quite a big difference. I use this code to measure the row height:

private double GetTableRowHeight(Row row)
{
    var newTable = new Table
    {
        ColumnWidths = TableCellWidths,
        DefaultCellPadding = new MarginInfo(2, 2, 2, 6),
        DefaultCellTextState = { Font = _defaultFont }
    };
    var rowClone = (Row)row.Clone(); // Cloning the row that contains the text data to measure.
    newTable.Rows.Add(rowClone);
    return newTable.GetHeight();
}
  1. For some weird reason, it seems that the first HtmlFragment that I use has some negative top margin on it, despite the fact that I set the top margin specifically on it.

Do you have any ideas on what might be wrong?

Thanks. :slight_smile:

@kgk2000

Thank you for contacting support.

I would like to request you to share a narrowed down sample application reproducing this issue. Please include the code which you are using to add a TextFragment and HtmlFragment and then calculating RowHeight for both of these rows so that we may investigate further to help you out. Please also elaborate the problem with negative margins with the help of screenshots and generated PDF file. Before sharing requested code snippet, please ensure using Aspose.PDF for .NET 18.2 in your environment.

Hello again! :slight_smile:

I am sending you a demo project.
There I am demonstrating the first two issues.
I didn’t manage to reproduce the 3rd one yet, but I will try a bit more.
But I have found some extra issues along the way.

To run it, first add your own license file (I have removed mine from the ZIP file and it is missing now):
TestAsposePDF_2.zip (11.2 KB)

Issue 2)
Once you run it, press “Test” to see what things look like normally (and notice the row heights of 441 logged on the window when the PDF is ready - this is the correct value of height).

Then check “use Html Fragments” and hit “Test” again. You will see that the font size used on the HtmlFragments is not the one specified as default on it. Also, the logged table row heights (values of 25 on the window) are way smaller then the ones from the previous run (not even the font size difference can account for such values).

Issue 3)
I have not managed to reproduce this one on the demo yet.

New issue)
Check the option “Keep With Next” and hit “Test”.
If you have “use Html Fragments” checked, the titles are not rendered.
If you have “use Html Fragments” unchecked, the whole text contents are not rendered.

Issue 1)
Stop the application, go to the source code and comment out this line:

var row0 = AddNewFragment(innerTable, GetFragment(false, “This is a title.”));

Then run it and hit test after you check “Use HTML Fragments”.
You will see that between page 1 and 2, the row with IsRowBroken = false breaks between pages.

I hope this helps, :slight_smile:
Kostas

@kgk2000

Thank you for elaborating the issues.

I have worked with the data shared by you and have been able to notice the problems reported by you. Following tickets have been logged in our issue management system for further investigation and resolution.

  • PDFNET-44307: Problem with RowHeight property (Issue 2)
  • PDFNET-44308: Problem with IsRowBroken property (Issue 1)
  • PDFNET-44309: Problem with IsKeptWithNext property (New issue)

The issue IDs have been linked with this thread so that you will receive notifications as soon as the issues are resolved.

We are sorry for the inconvenience.

Hello again! :slight_smile:
I have found a new bug and it would be nice if you could look into that a well.
In the previous demo project, add this extra method and call it form the UI:

    private void BreakBug_Click(object sender, RoutedEventArgs e)
    {
        // Create doc.
        var doc = new Document
        {
            EmbedStandardFonts = true
        };
        Page page = doc.Pages.Add();
        page.PageInfo.Margin.Top = 20;
        page.PageInfo.Margin.Bottom = 20;
        page.PageInfo.Margin.Left = 20;
        page.PageInfo.Margin.Right = 20;


        // Add content.
        var table = GetTable();

        for (int i = 0; i < 10; i++)
        {
            var innerTable = GetTable();
            var row = AddNewFragment(table, innerTable);
            row.IsRowBroken = AllowBreak.IsChecked == true;

            for (int j = 0; j < 2; j++)
            {
                // Title.
                var row0 = AddNewFragment(innerTable, GetFragment(false, "This is a title."));

                // Body #1.
                var fragment = (HtmlFragment)GetFragment(true, "<div><span></span><span></span><span></span><span><span></span><span>Bacon ipsum dolor amet ribeye biltong tenderloin burgdoggen cow boudin.<div><span><span><br></span></span></div>Short ribs t-bone spare ribs, venison fatback ribeye jowl tail pork leberkas pancetta capicola. Meatloaf rump ham hock filet mignon cupim pork salami ribeye. Prosciutto shoulder landjaeger, shank cow hamburger shsankle tenderloin boudin pancetta flank fatback short loin. Capicola porchetta shoulder kevin frankfurter pastrami shankle biltong spare ribs ham drumstick fatback meatball doner ribeye.</span><span></span></span><span></span> </div>");
                fragment.Margin = new MarginInfo(0, 0, 0, 0);
                fragment.TextState.LineSpacing = 2;
                var row2 = AddNewFragment(innerTable, fragment);
            }
            row.Border = new BorderInfo() { Bottom = new GraphInfo() { Color = Color.Brown, LineWidth = 1 } };
        }

        page.Paragraphs.Add(table);

        var tempPath = Path.Combine(Path.GetTempPath(), "_AsposeTest_" + Guid.NewGuid() + ".pdf");
        doc.Save(tempPath);
        Process.Start(tempPath);
    }

Notice the PDF content that is rendered.
Then, take the HTML form the code and add it to a browser page for comparison.
You will notice that this part of the HTML:

 <div><span><span><br></span></span></div>

…is being rendered as an empty line in browsers, while it is rendered as a zero height empty newline in Aspose PDF (so the gap between the paragraphs is missing and the “Short ribs t-bone” part is stuck to the previous “paragraph”).

P.S.:
I have also noticed that there are some differences regarding the size of vertical gaps produced by Aspose PDF, depending on the OS on some occasions. On Win7 it seems that it produces bigger gaps than on Win10, but I could not make a demo for this one.

@kgk2000

Thank you for gtting back to us.

We have worked with the data shared by you and have been able to reproduce the issue in our environment. A ticket with ID PDFNET-44371 has been logged in our issue management system for further investigation and resolution. The issue ID has been linked with this thread so that you will receive notification as soon as the issue is resolved.

Regarding this problem, please create a separate thread while sharing narrowed down sample application and generated PDF files, in both Windows environments so that we may compare and try to reproduce this issue to sort it out.

We are sorry for the inconvenience.