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 14, 2018

Do you access the correct text field?


Hi try67,

Thank you for the code example, that will allow me to see if and how my code differs.  The first and most obvious difference is that my code is a document-level JavaScript, beginning with this header:

//-------------------------------------------------------------

//-----------------Do not edit the XML tags--------------------

//-------------------------------------------------------------

//<Document-Level>

I'll have to confess that I don't actually know what a document-level JavaScript is.  I created my first PDF containing JavaScript about 7 years ago and I evidently (and unknowingly) created it as a document-level JavaScript, whatever that is.  I've been re-using this code ever since as a template for all subsequent projects.

If I haven't exhausted your patience, can someone explain the difference between a document-level JavaScript and one that contains the AcroForm tag? 

As I recall (again, it's been 7 years), I created my first program by clicking the "Document JavaScript" link, or it's predecessor in Acrobat X. If I shouldn't be using this link, how should I begin when I create a new program?

As you can tell, I'm somewhat jumping to the conclusion that my document-level program is the culprit behind rotation not working.  If I want to convert my document-level JavaScript to the structure that has the AcroForm tag, any suggestions of how I would go about doing this?  I can do a copy & paste of all of my code once I know how to create a skeleton program with the AcroForm tags.

Thanks again for everyone's help!  I'm guessing my rotation will work once I'm no longer a document-level program.

BTW, in case it matters, my PDF is a one-page diagram, i.e. it's not a lengthy document.

Dave