Skip to main content
Inspiring
February 12, 2018
Answered

How do I rotate the text inside of a text field with JavaScript ?

  • February 12, 2018
  • 1 reply
  • 4832 views

Hi,

I'm using Acrobat Pro DC 2015 Release.  I created a text field (using this.addField) then I attempted to rotate the text using the rotation property.  I've tried rotations of 90,  180, and 270, but the text never rotates.  If I bring up the properties dialog for the text field, which has a "Orientation" pulldown menu under the General tab, I can easily rotate the text by 90, 180, and 270 degrees.

I know that the text box doesn't rotate, I only want to rotate the text inside of the text box.  I've tried this with two different text boxes in my program but I can never get the text to rotate.  When I look at the text box properties dialog, specifically the "Orientation" pulldown, it never reflects what my program is attempting to do -- it always stays at 0 degrees.

With any text field and as you know, there are numerous text properties one can set -- textFont, textColor, textSize, readonly, value, etc.  Is there some requirement whereby the rotation property has to be set AFTER all of the other properties have been set?  I've tried moving the rotation property around in my program relative to the other text properties, but I still can't get my text to rotate.

BTW, my page is in landscape mode.  I haven't done anything in my program to reflect this orientation -- do I need to do something to tell Acrobat my page is in landscape mode?

Thanks for any suggestions anyone has.

Dave

This topic has been closed for replies.
Correct answer try67

The page size is irrelevant. My guess is there's something wrong with your code. Can you share the code you used to do it, as well as the file? You can upload the file to a website like Dropbox, Google Drive, Adobe Cloud, etc., and then post the link to it here.


I created a file that demonstrates how to rotate a field, and how to read the field's current rotation: Field rotation test.pdf - Google Drive

1 reply

Bernd Alheit
Community Expert
February 12, 2018

What do you use to rotate the field?

DHeadrickAuthor
Inspiring
February 12, 2018

Hi Bernd,

As mentioned in my post, I'm using the rotation property.  For example, MyTextFieldVariable.rotation = 90

Is this correct?

Thanks.


Dave

DHeadrickAuthor
Inspiring
February 15, 2018

What you posted above doesn't show any actual code, it's just a blank tag... Also, you should NOT be editing doc-level scripts using the "Edit All JavaScripts" command. Only use the "Document JavaScripts" button.

Without seeing the actual file I can't help you further, I'm afraid.


My code is 9,000 lines long and much of it is proprietary to the company I'm working for, so I can't share it.  However, that part of the code which does rotation is as I've described.

Thank you so much for providing your sample PDF, it allowed me to figure out what's going on.  Your PDF worked perfectly while my code continued to malfunction, so I worked to figure out what the difference is. In my Googling, I found the method getPageRotation().  When I added this to your code, I got 0 degrees.  When I added this to my code, I got 90 degrees!!

Somehow (likely many years ago) my page rotation got set to 90 degrees, meaning all of my programmed rotations are always off by 90 degrees. So, when I program 0, I get a 90 degree rotation on the screen.  This also causes a difference between what I program and what the Orientation dialog in the properties menu reports -- they always differ by 90 degrees.

One can't visibly see any sign of rotation.  My 17" x 11" page is displayed fine in landscape mode.  In my further Googling, there is no way to reset the rotation.  I believe I would need to start with a blank 17" x 11" PDF with rotation = 0 and copy all of the fields and JavaScript into it.  It will be MUCH easier to just live with the 90 degree page rotation and adapt to it in my programming of rotation.

Since you provide the example which ultimately led me to figure this out, I'll mark your reply above as the correct answer.

Thanks again for everyone's help!!