16 Replies Latest reply: Apr 11, 2012 10:20 AM by lrosenth RSS

    Get location of an annotation

    tyerlv123 Community Member

      I am looking at getting the location/coordinates of an annotation and printing them.

       

      I can get the annotation and appear to even get the coordinates but can't print them.

       

      This is what i am trying:

       

      ASFixedRect box;

      PDAnnotGetRect(annot, &box);

       

      ptr = (char *) &box.left;

      sprintf(buf, "The annotation's location is %s", ptr);

      AVAlertNote(buf);

       

      Thanks,

       

      Tyler

        • 1. Re: Get location of an annotation
          lrosenth Adobe Employee

          You can’t print them because you are trying to treat an ASFixed value as a char*.  Clearly that’s wrong.

          You should convert them from ASFixed to something standard like a float (ASFixedToFloat is your friend!) and then use the %f for sprintf.

          • 2. Re: Get location of an annotation
            tyerlv123 Community Member

            As a follow up question:

             

            I am trying to use this method as well:

             

            ASBool PDRedactionGetProps(PDAnnot redactionAnnot, PDRedactParams redactionProps)

             

            I can get it to return true therefore to the best of my knowledge redactionProps is filled out.

             

            How do I pull the data out of redactionProps ie in oder to get the value of the overlayText? or the pageNum? it also looks like this method will also get me the location of the annotation...by geting the redactQuads.

            • 3. Re: Get location of an annotation
              lrosenth Adobe Employee

              It’s a structure, so just reference the members.  (props.size, etc)

              • 4. Re: Get location of an annotation
                tyerlv123 Community Member

                I believe that is what I am trying:

                 

                PDRedactParams redactionProps;

                PDRedactionGetProps(annot, redactionProps);

                 

                ASText overlay;

                overlay = redactionProps.overlayText

                 

                But it doesn't like redactionProps.overlayText...isn't that how you would reference the members?

                • 5. Re: Get location of an annotation
                  lrosenth Adobe Employee

                  Sounds like you are having C/C++ development issues, not related to our SDK.

                  • 6. Re: Get location of an annotation
                    tyerlv123 Community Member

                    The error that comes tells me

                    Error: expression must have class type

                     

                     

                    I can do this although what gets returned is null.

                     

                    PDRedactParamsRec redactionProps;

                    PDRedactionGetProps(annot, &redactionProps);

                     

                    but then when i get my redactionProps.overlayText the returned result is null? when I do have overlay text.

                    • 7. Re: Get location of an annotation
                      lrosenth Adobe Employee

                      And the annotation you have is indeed of Subtype Redaction??

                      • 8. Re: Get location of an annotation
                        tyerlv123 Community Member

                        Yup the sub type is redact.

                        Because I do this to test:

                         

                        if(PDAnnotGetSubtype(annot) == ASAtomFromString("Redact") and it goes into the if statment

                         

                        And when I do this atom = PDAnnotGetSubtype(annot);

                        ptr = (char *) ASAtomGetString(atom);

                        sprintf(buf, "The subtype is %s", ptr);

                        AVAlertNot(buf);

                         

                        returns the ptr as Redact.

                        • 9. Re: Get location of an annotation
                          tyerlv123 Community Member

                          An Update:

                           

                          As above the PDAnnotGetSubtype returns the subtype as Redact so it should indeed be a Redaction annotation.

                           

                          My PDRedactionGetProps(annot, redactionProps); ;returns false

                          My PDRedactionGetProps(annot, &redactionProps); also returns false

                           

                          My question is why doesn't this work.  Is it something wrong with my PDF.  I just create a blank PDF.  Then I go to Advanced -> Redaction- > Mark for redaction and draw my box somewhere on the page and give it an overlay text and then save the PDF.


                          I then run my plugin against this PDF and the about returns false. 

                           

                          Is my variable annot wrong?  I get it by going:

                           

                          PDAnnot annot;

                          annot = PDGetAnnot(page, i2++)

                           

                           

                          Full code is this:

                           

                          #include "PDExpT.h"

                          #include "PIHeaders.h"

                          #include "redax.h"

                          #include <functional>

                          #include <iostream>

                           

                           

                          void RedaxReports( TCHAR * path ) {

                               PDDoc myPDDoc = getDocument(path);

                               PDPage page;

                               ASInt32 i,i2;

                               PDAnnot annot;

                               char* ptr;

                               char buf[200];

                               ASAtom atom;

                           

                               //Iterate through the PDF document page by page

                               for (i = 0; i < PDDocGetNumPages(myPDDoc); i ++)

                               {

                                    //Get each page within the document

                                    page = PDDocAcquirePage(myPDDoc, i);

                           

                                    //Get each annotation on the page

                                    for (i2 = 0; i2 < PDPageGetNumAnnots(page); i2++)

                                    {

                                         //Get a specific annotation

                                         annot = PDPageGetAnnot(page,i2);

                                         if (PDAnnotIsValid(annot))

                                         {

                                              //Display subtype information about the annotation

                               

                                              if(PDAnnotGetSubtype(annot) == ASAtomFromString("Redact")){

                                                   atom = PDAnnotGetSubtype(annot);

                                

                                                   //Cast the ASAtom object to a character pointer

                                                   ptr = (char*) ASAtomGetString(atom);

                                                   sprintf(buf, "The annotation’s subtype is %s", ptr);

                                                   AVAlertNote (buf);

                           

                                                   try{

                                                        PDRedactParamsRec  redactionProps;                     //Have also tried PDRedactParams redactionProps

                           

                                                        if(PDRedactionGetProps(annot, &redactionProps)){     //Then put PDRedactionGetProps(annot, redactionProps) still returns false

                                                             sprintf(buf, "Returns True");

                                                             AVAlertNote (buf);

                                                        }

                                                        else

                                                        {

                                                             sprintf(buf, "Returns False");

                                                             AVAlertNote (buf);

                                                        }

                           

                                                   }

                                                   catch (std::exception &cException){

                                                        AVAlertNote("ERROR");

                                                        AVAlertNote (cException.what());

                                                   }

                                              }

                                         }

                                     }

                               }

                          }//RedaxReports

                          • 10. Re: Get location of an annotation
                            lrosenth Adobe Employee

                            You have to fill in the redactionProps.size member to the sizeof(PDRedactParams)

                            • 11. Re: Get location of an annotation
                              tyerlv123 Community Member

                              Sorry thought the rest would be simple but alas another question relating to the initial question about the location of the box.

                               

                              How do I use the redactQuads? and numQuads members?

                               

                              More specially get the data out of the redactQuads.

                               

                              ASFixedQuad *rect;

                              rect = redactionProps.redactQuads;

                              • 12. Re: Get location of an annotation
                                lrosenth Adobe Employee

                                You have the data right there – now use them as coordinate sets on the page.  Not sure what you are missing?

                                • 13. Re: Get location of an annotation
                                  tyerlv123 Community Member

                                  Im trying to print the coordinate sets.

                                  • 14. Re: Get location of an annotation
                                    lrosenth Adobe Employee

                                    Remember to convert Fixed to something that you can print (like a float).

                                    • 15. Re: Get location of an annotation
                                      tyerlv123 Community Member

                                      But I can't access the members of rect? ie rect.bl

                                      • 16. Re: Get location of an annotation
                                        lrosenth Adobe Employee

                                        Top, left, bottom, right.