9 Replies Latest reply on Feb 22, 2013 1:25 PM by gkaiseril

    Using Bookmark Names to create Custom Stamps

    Bent2Bits®

      Hi all,

       

        I am a VB programmer that is struggling with a task in JS.  I am trying to do 1 of 2 things:  I would prefer #2.

       

      1.Create a custom stamp using the filename.

      or

      2.Create a custom stamp using the bookmark name (which in turn will be the filename)

       

      I have been foooling around for a number of hours trying to get this to work out, here's what I have done so far:

       

      I have created a stamp, the stamp has two text boxes that I need to fill from one string. The string is in the format of
      "08363-G-5109-DWG-R-00001_A.pdf" with a varying number of characters before the underscore, but always the same after the underscore. In the first text box I need
      08363-G-5109-DWG-R-00001 which I get with

      Code:
      event.value = event.source.source.documentFileName.slice(0,-6); this work great. The second box needs to contain the letter(s) that are between the "_" and the ".pdf" and everything I have tried doesn't produce a result.

       

      I focused most of my time trying to split the filename up, figuring the same logic would be applied to the bookmarks.

      The things I have tried:

       

      [CODE]

      var str = event.source.source.documentfilename;

      var strt = str.lastindexof("_");

      var end = str.lastindexof(".");

      event.value = str.substring(strt,end);

       

      and

           

      var arrStr = event.source.source.documentfilename.split("_");  ' **Harcoding = "08363-G-5109-DWG-R-00001_A.pdf" works**

      var arrstr2 = arrStr[1].split(".");                                             'But isn't very dynamic

      event.value = arrstr2[0];

       

      and

       

      var str = event.source.source.documentfilename;

      var arrStr = str.split("_");

      var arrstr2 = arrStr[1].split(".");

      event.value = arrstr2[0];

       

      [/CODE]

       

      Any assistance would be greatly appreciated!

      Bent

        • 1. Re: Using Bookmark Names to create Custom Stamps
          George_Johnson MVP & Adobe Community Professional

          Note that JavaScript is case sensitive, so "documentfilename" is wrong. You have it right in the first script you show.

          • 2. Re: Using Bookmark Names to create Custom Stamps
            Bent2Bits® Level 1

            Most helpful!  That little tidbit was tasty   You wouldn't happen to know how to assign the current bookmark name to a string would you?

             

            Bloody spectacular!

            Thanks mate,

            Bent

            • 3. Re: Using Bookmark Names to create Custom Stamps
              George_Johnson MVP & Adobe Community Professional

              I'm not sure what you mean by the current bookmark name, exactly. Can you elaborate?

              • 4. Re: Using Bookmark Names to create Custom Stamps
                Bent2Bits® Level 1

                Yes of course,

                 

                   In Adobe, if you have multiple sections in your document, you can add bookmarks to jump to certain segments of the document.  The would appear on the left hand side of the PDF, where you have three icons.

                 

                Pages - Go to specific pages using thumnails

                Bookmarks - Go to specific points of interest using bookmark links

                Search - See the results of your search

                 

                In my case, I would be combing multiple PDFs with the forementioned naming convention, and in the compiled version, the bookmarks are created automatically for each document name, so that you can jump to that document quickly.  So if I click on the second bookmark to jump to that particular document, I would like to capture that specific bookmark name in a string that I can use to fill in my stamp details.

                 

                I read some information about the bookmark object, and it looked like it might be something like var str = this.bookmark.name; but that doesn't work.

                 

                Thanks

                Bent

                • 5. Re: Using Bookmark Names to create Custom Stamps
                  George_Johnson MVP & Adobe Community Professional

                  OK. Is your code somehow triggering a particular bookmark that's present in the document and you then want to programmatically apply a stamp to the resulting page that's displayed? I don't think I have enough details yet of the workflow to best advise you. It may be easier to apply the stamps before you combine the documents.

                  • 6. Re: Using Bookmark Names to create Custom Stamps
                    gkaiseril MVP & Adobe Community Professional

                    The bookmark is an object and holds an array of "children" bookmarks. You need to access the various children to get the properties of an individual bookmark.

                     

                    Have looked at and tried to run the examples in the JS Reference?

                     

                    The following script displays the top most level book mark name:

                     

                    var bkm = this.bookmarkRoot.children[0];

                    console.println( "Top level bookmark name: " + bkm.name );

                     

                    You first need to get the 0 child level from the  book mark root.

                     

                    • 7. Re: Using Bookmark Names to create Custom Stamps
                      Bent2Bits® Level 1

                      GJ - The bookmark would be selected manually and the stamp would reflect the change.  The sole purpose of this is to combine and stamp hundreds of documents in the most efficient manner.

                      So for example:

                       

                      I combine 3 docs by selecting them in Windows and right clicking and selecting combine:

                      08363-G-5109-DWG-R-00002_A.pdf

                      08363-G-5109-DWG-R-00002_B.pdf

                      08363-G-5109-DWG-R-00002_C.pdf

                       

                      I would have 3 bookmarks automatically when the combination occurs:

                      08363-G-5109-DWG-R-00002_A

                      08363-G-5109-DWG-R-00002_B

                      08363-G-5109-DWG-R-00002_C

                       

                      So when I select the bookmark 08363-G-5109-DWG-R-00001_A then click stamps - dynamic stamps , my two text boxes have used this bookmark to get                 Text 1                          Text 2

                                                                                             08363-G-5109-DWG-R-00001     A

                       

                      Then I manually select the next bookmark and select stamp and it has used the next bookmark name to create a stamp  with two text boxes now              08363-G-5109-DWG-R-00002      B

                       

                       

                      If I had to stamp them first them combine, I would have to open one, stamp, save close rinse and repeat 100 times then combine.

                       

                      GK - I did have a poke around with bookmarkRoot.children, but the only result I ended up with was the word "Root" in the second box.  I couldn't seem to determine if JS automatically builds the children collection based on the number of bookmarks off the root, or if I had to programmatically build it with an array.

                      • 8. Re: Using Bookmark Names to create Custom Stamps
                        George_Johnson MVP & Adobe Community Professional

                        The problem is there is no concept of "current bookmark" that you can get. Even if there were a means to get the title of the last bookmark that was checked, the user could have changed the page between clicking the bookmark and applying the stamp.

                         

                        I still think this could be easier if you apply the stamps before you do the combine, assuming that you want to do it for every document that gets combined. You can do this with a batch process (aka Action) that automatically applies the stamp on the first page in a particular location, so there would be no need for the user to go through each combined document and manually apply the stamp. You can also flatten them if you don't want them to be altered or deleted after they're applied.

                        • 9. Re: Using Bookmark Names to create Custom Stamps
                          gkaiseril MVP & Adobe Community Professional

                          You do not build the array the array is returned by accessing  the children property of the bookmark root.

                           

                          You might find some help with Removing filename bookmarks created by Acrobat to see how to manipulate the array of bookmark root children.

                           

                          Unfortunately the bookmarks with the .PDF name do not link to anything.