We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PDF Table has null properties after inserting '$P' Text, Displays as '1' in document

I have discovered a peculiar bug. If I have a cell within a table that contains the 2-character sequence ‘$P’, then I get a NullReferenceException when I try calling either table.GetWidth() or table.GetHeight(). I tried some other character sequence of this pattern, like ‘$R’, ‘$S’, etc. and did not find this issue. Additionally, if I do not call table.GetWidth() or table.getHeight(), I am still able to generate a PDF when I insert ‘$P’ into a cell, but the text shows as ‘1’. You can verify this by removing the call to .GetWidth() in the code below. Otherwise, the line that has table.GetWidth() throws a NullReferenceException. dollar-p-bug.JPG (49.1 KB)

        Document doc = new Document();
        Page page = doc.Pages.Add();
        page.PageInfo.Width = PageSize.PageLetter.Width;
        page.PageInfo.Height = PageSize.PageLetter.Height;
        page.PageInfo.Margin = new MarginInfo(27, 27, 27, 27);

        var table = new Table()
            ColumnAdjustment = ColumnAdjustment.AutoFitToWindow,

        var row = table.Rows.Add();
        var cell = row.Cells.Add("$P");

        var width = table.GetWidth();



Thank you for contacting support.

Please call ProcessParagraphs() method before calculating Width or Height of the table, to avoid NullReferenceException.

var width = table.GetWidth();

Moreover, we have been able to notice the text as ‘1’ when ‘$P’ is added to the table. A ticket with ID PDFNET-45997 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

I’m not sure that calling ProcessParagraphs() before calling table.GetWidth() is the proper solution. If that is the case, then why do we not encounter the NullReferenceException for all text within the table, and not just when we have ‘$P’? It seems to me that if calling table.GetWidth() without previously calling ProcessParagraphs() would always throw a NullReferenceException, then your solution would make sense, but that’s not the case – it only happens with ‘$P’ in the cell.

In our particular case, we are also still changing the content of the table based on it’s width (for example, truncating the content), so we don’t want to prematurely call ProcessParagraphs() since the table’s content has not been finalized yet.

Can you suggest an alternate solution?


Thank you for elaborating it further.

We have logged your concerns and will update you once the ticket is investigated. Please be patient and spare us some time.