1

Hi folks i have a few use cases i need to cover while rotating the page in the PDF .

  1. I need to check each page rotation value and rotate it to 0 degree.

  2. when i check few docs in Adobe it shows me 90 degree but it will be in 0 degree.

I need to cover both the use cases, I have written a code using java PDFBox which will get the degree of rotation is showing wrong, If any one have idea How to find And what are the Aspects that decide the degree please help me through it . with code or Wiki to refer , I am working on a spring boot project.

 PDDocument document;


 public void getPdfFile(String pdfPath) throws IOException {

    File file = new File(pdfPath);

    document = PDDocument.load(file);

   int pageCount = document.getNumberOfPages();

   for(int i = 0; i < pageCount; i++) {
       PDPage page =  document.getPage(i);

      System.out.println( page.getRotation());
      if(page.getRotation() != 0) {
          page.setRotation(0);
      }

   }
     document.save("/Users/tejasreddy/Desktop/CE/StorePDF/rotated1_rotated.pdf");

     document.close();
}

enter image description here

CropBox And Media Box Details

Thanks Tejas.

3: PDF Details

  • 3
    *"which will get the degree of rotation is showing wrong"* - what do you mean by *showing wrong*? PDFBox shows the value of the rotation attribute of the page alright, so I assume you simply mean something different by *page rotation* than the value of that attribute. – mkl May 12 '22 at 04:48
  • Thanks for the reply , In the image Which i have shared above you can see the "Rorate : 90" but the rotation value should be "0" , when i try to get the rotate value using the code , i am getting the same value as shown in the screenshot as 90 but it should be 0 , so i am thinking the "getRoatation" method is giving the wrong values. and i wanted to find the correct value , since i am new to PDFBox i am excepting roadMap to solve this problem , please let me know is there a way to find the solution for this problem. Thanks tejas. – tejas Reddy p May 13 '22 at 06:03
  • 1
    Why should it be 0? First of all the page rotation attribute is not firmly related to the looks of the page at all. And secondly, even if it was, different parts of your page have text rotated differently, some text looks upright, some is rotated by 90°. So a rotation value of 90 even by the looks of your page doesn't seem unlikely. – mkl May 13 '22 at 20:50

1 Answers1

1

There appears to be a misunderstanding in respect to the meaning of the PDF page rotation property, so I'll explain that here.

The visible page area has the dimensions and coordinate ranges given by the CropBox entry of the page. The x coordinates in this area increase going right, the y coordinate increase going up. In this area the instructions of the page content streams can draw text and other contents in any direction or orientation.

The Rotate entry of the page (i.e. the "page rotation") instructs a viewer program to display the page area defined by the crop box rotated clockwise by the value of that entry in degree (must be a multiple of 90°).

That's it.

Thus, the page rotation value does not necessarily coincide with the orientation of any content on the page. (Of, course, when creating a PDF one usually chooses the crop box and the rotation value to make both adding content and reading it in a viewer as easy as possible. But this is not technically enforced.)

mkl
  • 90,588
  • 15
  • 125
  • 265
  • Hi Thanks for the reply , I looked into the details of the crop box and the media box which are same , my understanding is that the media box values and the "CropBox" values must be different because , crop box gives the user visualisation , can you explain me on this so that i can understand bit more , " the reason i am trying to rotate the image is that the use case is to create an image in such a way that it is accessible by every one including the blind ppl ", i have shared the picture of "cropBox " and the "media box " details in picture and the pdf link. Thanks – tejas Reddy p May 16 '22 at 12:22
  • 1
    *"my understanding is that the media box values and the "CropBox" values must be different"* - No. Actually crop box defaults to the media box. – mkl May 16 '22 at 13:15
  • Thanks , Yes got the point , Now my question is how can we rotate the orientation of contents stream ...! – tejas Reddy p May 17 '22 at 11:25
  • The content stream has no orientation other than being executed from start to end. You said before *"the reason i am trying to rotate the image is that the use case is to create an image in such a way that it is accessible by every one including the blind ppl"* - maybe you should explain what exactly you technically need to change to allow for accessibility. Usually accessibility requires proper tagging of the contents, your file is completely un-tagged. – mkl May 17 '22 at 15:51
  • Thanks for the reply again , i have created the new question so that we can have good clarity of what exactly i am finding for , https://stackoverflow.com/questions/72283591/how-to-know-the-page-starting-points-in-the-pdf-page. is the new question i have raised for better understanding – tejas Reddy p May 18 '22 at 05:26