11 Replies Latest reply on Mar 25, 2013 4:33 PM by trentnielson

    Certain FreeText attributes don't seem to work in this.addAnnot

    DHeadrick Level 1

      Hi,

       

      I'm executing this JavaScript code:

       

      MyRect = this.addAnnot

                 ( { page: 0,

                      type: "FreeText",

                      width: 1,

                      strokeColor: color.black,

                      textSize: 14,

                      contents: "ABC",

                      alignment: "center",

                      rect: [ LLX, LLY, URX, URY] })

       

      The textSize, contents and alignment parameters are basically ignored.

       

      If I put the text size outside of this.addAnnot as follows, it works fine:

       

          MyRect.textSize = 14;

       

      The contents somewhat works within the this.addAnnot except the text color is wrong (it's red).  If I do the contents as follows outside of this.addAnnot, it works fine:

       

         MyRect.contents = "ABC";   // this produces black text, as it should

       

      I've never been able to get alignment to work in any case, either within this.addAnnot or outside of it. 

       

      Can someone tell me if textSize and contents truly have to be outside of this.addAnnot in order to work correctly?  Also, can someone tell me if alignment has ever worked in Acrobat with JavaScript?  BTW, I've tried both "center" and the value 1 for alignment, but it's always left aligned.

       

      Thanks.  I'm on Acrobat 9.

       

      Dave

        • 1. Re: Certain FreeText attributes don't seem to work in this.addAnnot
          gkaiseril MVP & Adobe Community Professional

          What is the size and location of your annotation?

          What are the values for LLX, LLY, URX, and URY?

          What is the size of the PDF page?

          Is the PDF page rotated?

           

          Have you tried making the annotation and then modifying it?

          • 2. Re: Certain FreeText attributes don't seem to work in this.addAnnot
            DHeadrick Level 1

            Hi,

             

            Thanks for your reply.

             

            The issue I'm observing is independent of the size and location of the annotation.  Stated another way, it's independent of the values of LLX, LLY, URX, and URY.  I would be glad to generate some values for these parameters if you'd like.

             

            Your other questions are more interesting.  The page *is* rotated and it's a size B (aka tabloid, aka 11"x17") page.  So, it's in landscape mode, with the 17" dimension running horizontally.  This means, as I understand it, the origin for specifying the text box dimension is in the upper left corner, with Y running down (vertically) and X running right (horizontally).  Using this coordinate system, I never have any trouble creating a text box anywhere I want on the page, of any size. It's what's in the text box that's the problem.

             

            You ask "Have you tried making the annotation and then modifying it?"   Maybe I'm misunderstanding your question, but that's what I'm doing.  I create the annotation with this.addAnnot and then modify it (in particular, the textSize and contents) after I create the annotation.  If I create textSize or contents within the this.addAnnot, they either have no affect or they do unexpected things, like generating red text.  If i create textSize or contents outside of the this.addAnnot, it always works fine.

             

            If I do both (create textSize and contents within this.addAnnot, which doesn't work), and then modify it subsquently, that also works fine.  In this case, whatever textSize and contents are specified within this.addAnnot becomes a "don't care" since I specify (override) these values afterwards.  So, it's cleaner to just specify textSize and contents in one spot, namely outside of and after the this.addAnnot.

             

            Thanks for any further insights you have on why (it appears) I can't specify textSize and contents within this.addAnnot.  Also, any insights on why it appears that "alignment" is completely non-functional would be appreciated as well.

             

            Dave

            • 3. Re: Certain FreeText attributes don't seem to work in this.addAnnot
              gkaiseril MVP & Adobe Community Professional

              A check of the documentation for the add annotation action shows the centered property does not have a value option of the character string "centered", it has values of 0, 1, and 2.

               

              alignment

              • 4. Re: Certain FreeText attributes don't seem to work in this.addAnnot
                DHeadrick Level 1

                In my original posting, I stated: "BTW, I've tried both "center" and the value 1 for alignment, but it's always left aligned."

                 

                Do you have any ideas why none of this (seems to) work?  Specifically, why I can't specify textSize and contents with the this.addAnnot and why alignment doesn't work at all?

                 

                Thanks again.


                Dave

                • 5. Re: Certain FreeText attributes don't seem to work in this.addAnnot
                  gkaiseril MVP & Adobe Community Professional

                  The user interface is now different than it was in Acrobat version 5 and the example from the version 5 JavaScript documentation does not work as illustrated.

                  • 6. Re: Certain FreeText attributes don't seem to work in this.addAnnot
                    DHeadrick Level 1

                    I never mentioned Acrobat version 5.  I did mention that I'm using Acrobat 9.  What "example from the version 5 JavaScript" are you referring to??  And how would this be relevant to my question regarding Acrobat 9?

                     

                    Basically, I'm still no closer to understanding why I'm experiencing these problems on Acrobat 9.  Do you have any ideas on this?

                    • 7. Re: Certain FreeText attributes don't seem to work in this.addAnnot
                      gkaiseril MVP & Adobe Community Professional

                      You have provided incomplete code and code with an obvious error, but maybe not a script ending error.

                       

                      The 'alignment' property has been depreciated since it was introduced.

                       

                      Here is the page from the version 5 JS refer

                       

                      FreeTextAnnot.jpg

                       

                      With only partial code and an obvious coding value error, it is possible you have code elsewhere that could have corrupted the code you are trying to use.

                       

                      Yes one can redefine a property or method in JavaScript.

                      • 8. Re: Certain FreeText attributes don't seem to work in this.addAnnot
                        gkaiseril MVP & Adobe Community Professional

                        You could write your script in the following manner:

                         

                        var LLX = 25; LLY = 25; URX = 100; URY = 100;
                        var MyRect = this.addAnnot ( { page: 0,
                                        type: "FreeText",
                                        width: 1,
                                        rect: [ LLX, LLY, URX, URY] })
                        MyRect.textSize = 25;
                        MyRect.contents = "ABC";


                        So you are setting the content after the comment object has been established.

                         

                        If you think this is an error, then you should file a bug report with Adobe.

                        1 person found this helpful
                        • 9. Re: Certain FreeText attributes don't seem to work in this.addAnnot
                          DHeadrick Level 1

                          I couldn't find any evidence that the 'alignment' property has been deprecated, at least in Acrobat 9.  It was introduced in Acrobat 5 and still seems to be supported.  I think it's fair to conclude that this property just doesn't work.

                           

                          Your example script is exactly what I've been doing, namely putting 'textSize' and 'contents' outside of the this.addAnnot.  My original question from my first posting was:

                           

                              "Can someone tell me if textSize and contents truly have to be outside of this.addAnnot in
                               order to work correctly?"

                           

                          I'll take your answer as confirmation that this is, in fact, what I need to do.  I presume this is a bug but perhaps Adobe would claim "This is just how it works".

                           

                          Thanks for your help.

                           

                          Dave

                          • 10. Re: Certain FreeText attributes don't seem to work in this.addAnnot
                            gkaiseril MVP & Adobe Community Professional

                            The not working is the depreciation, but it does not throw an error and stop the script.

                             

                            Some times one needs to have an object created and established before modifying certain propertites or using certain methods.

                            • 11. Re: Certain FreeText attributes don't seem to work in this.addAnnot
                              trentnielson

                              Did you ever figure out how to get alignment to work? I'm struggling with this right now.