Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Feb 11, 2018 Feb 11, 2018

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

TOPICS
Acrobat SDK and JavaScript , Windows
4.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 13, 2018 Feb 13, 2018

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

Translate
Community Expert ,
Feb 11, 2018 Feb 11, 2018

What do you use to rotate the field?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 12, 2018 Feb 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2018 Feb 12, 2018

The text can't be rotated independently of the field. What you see in the Properties dialog as Orientation is the same as the rotation property you can edit with a script. You will see that this property exists also for non-text fields, indicating it has nothing to do with the text itself.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2018 Feb 12, 2018

This is correct.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 12, 2018 Feb 12, 2018

.I'm confused.  What does the rotation property affect if it doesn't affect the text itself?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2018 Feb 12, 2018

It affects the entire appearance of the field, including the text.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2018 Feb 12, 2018

Your example is correct. It changes the text orientation in the field.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 12, 2018 Feb 12, 2018

I'm still confused.  Let me ask a specific question.  What can I do programmatically to change the data displayed by the Orientation pulldown in the properties dialog?  Let's say I want the Orientation dialog to display 90 degrees.  I know how to set it to 90 degrees manually using the GUI.  What do I do in JavaScript so that the Orientation dialog will display 90 degrees?

The inverse should apply.  If I set the Orientation dialog to say 90 degrees using the GUI, how do I read this value in JavaScript?  What Javascript property reflects the value of Orientation that I set with the GUI?

So far, I haven't found a way programmatically to set or read the value displayed by the Orientation pulldown.  The Orientation GUI display and the value of the rotation property seem completely independent.  I can program rotation to any value I want and the Orientation dialog value never changes.  Is there any way programmatically that I can change what the Orientation pulldown displays?

Thanks again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2018 Feb 12, 2018

Setting the value:

f.rotation = 90;

Reading the value:

f.rotation;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2018 Feb 12, 2018

this.getField("Text1").rotation=90;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 13, 2018 Feb 13, 2018

Thanks for your replies.  In my original post, I indicated I was setting rotation to 90, 180, and 270, but the text never changes orientation.  I just added a console.println statement to print out the rotation properties in each case, and it printed out 90, 180 and 270 as I changed the rotation property from 90, 180, to 270, respectively.

So, rotation is getting set correctly.  What never changes is the actual rotation of the text.  As I mentioned in my original post, the Orientation pulldown in the Text Field Properties menu never changes, it's ALWAYS zero regardless of what I set rotation to.  My understanding is that the Orientation pulldown should reflect what I set rotation to.  If I set the rotation property to 90 and I look at the Orientation pulldown for that text field, it should also be 90.

As I also mentioned in my original post, my page is set to landscape mode.  The paper size is 17" wide by 11" high.  I'm not aware of a need in my JavaScript to communicate the fact that my page is landscape mode -- do I need to somehow do this?  I believe Acrobat considers landscape mode to be "rotated user space" -- is this somehow causing my rotation property to be ignored?

I hate to ask this but if anyone has the time to experiment with a 17" x 11" document, and see if setting the rotation property for a text field affects the Orientation value, that would be greatly appreciated. 

BTW, I do have a workaround -- I just change the Orientation pulldown manually to 90 degrees.  I would just like to know why setting the rotation property seems to have no effect on the Orientation value nor on the rotation of my text.

Thanks again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2018 Feb 13, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2018 Feb 13, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2018 Feb 13, 2018

Do you access the correct text field?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 14, 2018 Feb 14, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2018 Feb 14, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 15, 2018 Feb 15, 2018

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!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 15, 2018 Feb 15, 2018

Some pages just are rotated. Best to write robust code that deals with this just as it deals with cropped pages. So robust code checks getPageRotation before adding anything. Yes, everything gets more complicated...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 15, 2018 Feb 15, 2018

Yes, page rotation will affect how the field rotation is displayed on the screen (since the field exists within the page and is therefore affected by it). However, it's certainly possible to test the page rotation, exactly how you described, using the getPageRotation method.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 15, 2018 Feb 15, 2018

Yes, this was a great (if somewhat painful) learning experience.  Now I know about getPageRoation().  I agree, robust code should check for the native rotation of the page, if any, and responding accordingly when doing other rotations.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 15, 2018 Feb 15, 2018
LATEST
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines