Aspose PDF Providing Rotated Forms Rectangle


We are using Aspose PDF .Net to extract all of the words from PDF documents using TextFragments. This has worked well for some time, so we are expanding to also extracting form fields from PDFs. During our testing, we pulled the rectangle from PDFs that were both portrait and landscape. The portrait PDF returned expected results: the rectangle provided for the form fields fit well with the rectangles for the rest of the words on the page. When we tried the landscape PDFs, however, we found that the form field rectangles appear to be rotated in comparison to the rest of the words on the page.

I have uploaded a sample of problem PDF. Here is a broad snippet of what we are trying to use for our testing:

        Dim pdfDocument As New Aspose.Pdf.Document(pdfFilepath)

        pageHeight = pdfDocument.PageInfo.Height
        pageWidth = pdfDocument.PageInfo.Width
        Dim formField As Aspose.Pdf.Forms.Field
        Dim fieldName As String
        Dim fieldValue As String
        Dim fieldLLX As Decimal
        Dim fieldLLY As Decimal
        Dim fieldURX As Decimal
        Dim fieldURY As Decimal
        For Each formField In pdfDocument.Form
            fieldName = formField.PartialName
            fieldValue = formField.Value
            fieldLLX = formField.Rect.LLX
            fieldLLY = formField.Rect.LLY
            fieldURX = formField.Rect.URX
            fieldURY = formField.Rect.URY
            If Trim(fieldValue) <> "" Then
                stoppoint = 100
            End If

When we test with this code, the coordinates provided by the rectangle are rotated on the page (as though the page was rotated 90 degrees clockwise). We also get height and width information that seems to be rotated as well (the height is larger than the width, even though in landscape mode the reverse should be true).

Can you provide any insight into how we can resolve this issue? Thank you.

PC1.pdf (1.9 MB)


We suggest you please use the latest version of Aspose.PDF for .NET 22.11 and let us know how it goes on your side. Hope this helps you.

If you still face problem, please share how are you checking the coordinates either they are rotated or not. Please also share the expected results. We will investigate the issue and provide you information on it.

This morning we upgraded to the latest version of Aspose PDF .Net (22.11). The issue persists with the updated version.

We are running a separate process that pulls the coordinates for every word on the page using TextFragments. When we compare the TextFragment coordinates for a portrait PDF example with the form field coordinates, they line up with each other. The portrait PDF also has correct width and height measurements (height is bigger than the width).

When we apply the same logic to landscape files (like the one provided above PC1.pdf), we get correct coordinates for the TextFragments, but coordinates that are rotated to incorrect positions for the form field rectangles. They are rotated from each other 90 degrees. The height and width of these files is also reported incorrectly (with height being larger than width, even though the reverse should be true for landscape).

I have attached two images from a spreadsheet to this post which lay out the values we are seeing between two different sample PDFs (the landscape file I have already given and the portrait file we are testing against). I am also attaching the portrait file.

Please let me know what further information I can provide to resolve the issue. Thank you.

Landscape PDF (PC1.pdf) - incorrect values.png (53.5 KB)
PF1.pdf (83.3 KB)
Portrait PDF (PF1.pdf) - correct values.png (17.0 KB)


Please try to use the below code snippet to get true rectangle of the form fields and see if you receive correct coordinates:

// C#
var pdf = new Aspose.Pdf.Document(dataDir + "PC1.pdf");
var fields = pdf.Form.Fields; // cache Form.Fields property in local variable

for (int i = 0; i < fields.Length; i++) // 7 seconds to exit loop
 var f = fields[i];
 var rec = f.GetRectangle(true);

Thank you, that did resolve our initial issue with the specific form coordinates. However, we still have one outstanding problem. The height and width reported by Aspose for the PDF are reversed from what they should be when we send a landscape file through. We use the height and width in our later calculations, so all of our later work on files like this is incorrect. We are seeing this issue on numerous landscape files, not just those with form fields.

Is there a way to fix them so that they reflect the true height and width of the page? Or a way to detect that the page is landscape so that we can reverse them before using them?

Edited to add: We have tried using the .IsLandscape property to determine this. These landscape PDFs return a “False” incorrectly.

Thank you.


You are getting False value because the page is not actually landscape but rotated. Therefore, please use Page.GetPageRect(true).Height and Page.GetPageRect(true).Width properties to get actual height and width of the page in an existing PDF. Page.PageInfo.Height and Page.PageInfo.Width properties are only for PDF generation and should be used while creating new PDF file from scratch.