Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue May 26, 2020 6:03 pm

Hi,
I have a lot of scanned pdf files that are portrait-oriented but nonetheless PdfPageBase.Rotation results in a non-zero angle to rotate.

Sample code:

Code: Select all
PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(filePath);
           
            foreach (PdfPageBase page in doc.Pages)
            {
                int rotation = (int)page.Rotation;
                if (page.Rotation == PdfPageRotateAngle.RotateAngle90)
                {
                    rotation += (int)PdfPageRotateAngle.RotateAngle270;
                    page.Rotation = (PdfPageRotateAngle)rotation;
                    isRotateSave = true;
                }
                if (page.Rotation == PdfPageRotateAngle.RotateAngle180)
                {
                    rotation += (int)PdfPageRotateAngle.RotateAngle180;
                    page.Rotation = (PdfPageRotateAngle)rotation;
                    isRotateSave = true;
                }
                if (page.Rotation == PdfPageRotateAngle.RotateAngle270)
                {
                    rotation += (int)PdfPageRotateAngle.RotateAngle90;
                    page.Rotation = (PdfPageRotateAngle)rotation;
                    isRotateSave = true;
                }
            }


Thanks in advance'
Assaf

assafperl
 
Posts: 2
Joined: Tue Mar 03, 2020 12:45 pm

Wed May 27, 2020 3:18 am

Hi Assaf,

Thanks for your inquiry.
I simulated a PDF file and tested your code with the latest Spire.PDF Pack(Hot Fix) Version:6.5.9, but it could return the correct rotation angle. Attached is my test PDF file.
If you are using an older version, I suggest your try again with the latest version. If the issue still happens after trying, please provide a sample PDF file for our further investigation. You could send it to us([email protected]) via email.

Sincerely,
Rachel
E-iceblue support team

Sample.zip
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Sun May 31, 2020 5:33 am

Hi,

Thanks for the quick reply.
My scenario is different.
The pdf file that I'm processing is portrait-oriented and does not need to be rotated, nonethelesswhen running the following code:

Code: Select all
PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(filePath);
           
            foreach (PdfPageBase page in doc.Pages)
            {
                int rotation = (int)page.Rotation;
                if (page.Rotation == PdfPageRotateAngle.RotateAngle90)
                {
                    rotation += (int)PdfPageRotateAngle.RotateAngle270;
                    page.Rotation = (PdfPageRotateAngle)rotation;
                    isRotateSave = true;
                }
                if (page.Rotation == PdfPageRotateAngle.RotateAngle180)
                {
                    rotation += (int)PdfPageRotateAngle.RotateAngle180;
                    page.Rotation = (PdfPageRotateAngle)rotation;
                    isRotateSave = true;
                }
                if (page.Rotation == PdfPageRotateAngle.RotateAngle270)
                {
                    rotation += (int)PdfPageRotateAngle.RotateAngle90;
                    page.Rotation = (PdfPageRotateAngle)rotation;
                    isRotateSave = true;
                }
            }

I get that the page needs to be rotated by a 270 angle.

assafperl
 
Posts: 2
Joined: Tue Mar 03, 2020 12:45 pm

Mon Jun 01, 2020 2:02 am

Hello,

Thanks for your feedback.
To help us investigate your issue more accurately, please provide us with your input file. You could send it to us([email protected]) via email. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF