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

Free Support Forum - aspose.com

Detect page rotations in PDF

Hi there,

I’m using Aspose.Pdf for .NET version 10.4. I have the next scenario. There are two stages.
At first stage I’m opening a PDF document, rotate some pages to specific angle (90, 180 or 270 degrees), and save this document as PDF.
At second stage I’m opening the previously saved PDF with rotated pages and want to detect, which pages were rotated at 1st stage, and on what angle. And the problem is - I cannot detect this, Aspose.Pdf detects all page rotations as 0.

My source code is below, it represents previously described 2 stages. This issue can be reproduced on different PDFs, so I decided not to attach them.

//1st stage - rotationg
String full_path = SharedData.FilesFolder + DocumentName;
FileStream fs = File.OpenRead(full_path);
using (Aspose.Pdf.Document document = new Document(fs))
{
using (PdfPageEditor pdfPageEditor = new PdfPageEditor())

{

pdfPageEditor.BindPdf(document);

pdfPageEditor.PageRotations[1] = 180;

pdfPageEditor.PageRotations[2] = 90;

pdfPageEditor.Save(SharedData.FilesOutputFolder + DocumentName + “_output.pdf”);

}
}

//2nd stage - checking existing rotations
using (Aspose.Pdf.Document document2 = new Document(SharedData.FilesOutputFolder + DocumentName + “_output.pdf”))
{

using (PdfPageEditor pdfPageEditor2 = new PdfPageEditor())

{

pdfPageEditor2.BindPdf(document2);

Console.WriteLine("Rotations. 1st page: " + pdfPageEditor2.GetPageRotation(1).ToString() +
"; 2nd page: " + pdfPageEditor2.GetPageRotation(2).ToString());

}
}

From this code it can be seen, that I’m using “PdfPageEditor” for rotating and for detecting rotations, as it is described here: Working with Page Rotation .

Maybe, there is another way of adding and/or obtaining rotation angle, and this way can give me what I want - in that case please tell me what I need to do.


Thanks a lot.
With best wishes,
Denis Gvardionov

Hi Denis,


Thanks for your inquiry. We have noticed that page rotation set by PdfPageEditor is not being identified by API. So we have logged a ticket PDFNEWNET-38767 in our issue tracking system for further investigation and resolution.

However as a workaround, you may use Rotate() method of Page class as following. Hopefully it will help you to accomplish the task.

//1st stage - rotationg<o:p></o:p>

String full_path = myDir + "TableDOM.pdf";

Aspose.Pdf.Document doc = new Aspose.Pdf.Document(full_path);

doc.Pages[1].Rotate = Rotation.on180;

doc.Pages[2].Rotate = Rotation.on90;

doc.Save(myDir + "TableDOM_output.pdf");

using (Aspose.Pdf.Document document2 = new Document(myDir + "TableDOM_output.pdf"))

{

using (PdfPageEditor pdfPageEditor2 = new PdfPageEditor())

{

pdfPageEditor2.BindPdf(document2);

Console.WriteLine("Rotations. 1st page: " + pdfPageEditor2.GetPageRotation(1).ToString() +

"; 2nd page: " + pdfPageEditor2.GetPageRotation(2).ToString());

}

}


We are sorry for the inconvenience caused.

Best Regards,

Hello Tilal,

Your answer was very helpful. It works even better than I thought. When rotating pages by using your way, Aspose.Pdf not only rotates pages, but firstly reads already performed rotation, takes it into account, and performs rotation while “keeping in mind” previous orientation of the page.

I suggest you to add this to the documentation, this info is very useful.


Thanks a lot.
Denis Gvardionov

Hi Denis,



Thanks for your feedback. It is good to know you have managed to accomplish your requirement.

Moreover, we have added the Rotate() method details on following documentation page.


Best Regards,

Hi Denis,


Thanks for your patience. We have further investigation the issue PDFNEWNET-38767 and would like to update you that Please note that PdfPageEditor does not change Rotation property of the page; It creates Form X-Object and shows this form rotated (using matrix operator). So please rotate and detect page rotation as suggested above.

Please feel free to contact us for any futher assistance.

Best Regards,