Skip to main content
Participant
February 12, 2016
Question

Get page numbers that contain rotated text

  • February 12, 2016
  • 2 replies
  • 1427 views

Hello,

I searched through the documentation for JavaScript for Adobe, however I did not have success in finding information about getting the rotation of text.

Practically, I would need a code for the JavaScript console in Adobe Pro, that would find pages that have rotated text. Rotated by 90 or 270 degrees. Basically, I would need to get the page numbers of landscape pages, that are shown as portrait. I tried using getPageRotation command, however the PDFs were converted with the pages in portrait, and show no rotation. This is why I would need a function that would recognize rotated text.

Is this possible? Thanks!

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
February 12, 2016

Maybe instead of looking at the coordinates of the text just look at the size of the pages. That's much easier to do.

You can use the getPageBox method for that.

Participant
February 12, 2016

The pages are in portrait mode. I already tried this. While in portrait mode, even if text is rotated 90/270 degress, the page size is as the ones they are in portrait mode.

try67
Community Expert
Community Expert
February 12, 2016

In that case looking at the text quads is probably the only option, but it should be sufficient to look at a single word in each page.

Bernd Alheit
Community Expert
Community Expert
February 12, 2016

You can use the method getPageNthWordQuads of the doc object.

Participant
February 12, 2016

I am not sure how to use this. Could you please provide more details on how should I proceed? If I loop through a really big document, Adobe would crash if I would search all words

Karl Heinz  Kremer
Community Expert
Community Expert
February 12, 2016

Assuming that all the text on a page is oriented the same way, there is no need to loop over all the text in the document. The "quads" are the four points that mark the corners of the bounding box around the word. Create a document with four pages, with every page using a different text orientation. Then run the following code in your JavaScript console:

var q = this.getPageNthWordQuads(0, 1);

console.println(q.toSource());

q = this.getPageNthWordQuads(1, 1);

console.println(q.toSource());

q = this.getPageNthWordQuads(2, 1);

console.println(q.toSource());

q = this.getPageNthWordQuads(3, 1);

console.println(q.toSource());

This will print the quads for the first word on all four pages. When you now analyze the four points in each quad, you will find that they are arranged in a certain way (this assumes that you use a word with a width that is greater than it's height). Let's assume you get this output (simplified to integers):

[[85, 744, 115, 744, 85, 728, 115, 728]]

This means that P1 has an x component of 85, and a y component of 744, P2 is 115 and 744, and so on. You can see that the y components of P1 and P2 are the same, and P1.x is less than P2.x. You do this for all four pages, and you will have rules to find the text orientation on each page. To make sure that you don't accidentally pick a first word like "I", I would not just use one word, but maybe the first 3 and use a 2 out of 3 rule to determine the text orientation.