6 Replies Latest reply on Nov 17, 2016 12:45 AM by Sudha K

    Crop PDF

    Sudha K Level 1

      HI,

       

           Sorry i don't know  the place to write this so writing here...

       

           I am croping pdf to trim size using applescript.

       

           1.  Crop Pages -> Get the Trim box values

           2.  Place the values (T, L, B, R) to the Crop box.

           3.  Select All radio button

           4.  Click Ok.

       

           Following these steps in apple script but after cropping the pdf (ie., after completing script) no changes in pdf.  Actually values are asigned to crop process but no changes.  I could not get the issue.  Can anyone help me?

       

       

      Code:

       

      ------------- Process --------

       

      set pdfFile to choose file

      my mainProcess(pdfFile)

      display dialog "Process Completed!!!"

       

      -------------- Functions ---------

       

      on mainProcess(pdfFile)

         

          local trimboxFlg, cropboxFlg

          set cropboxFlg to 0

          set trim_box to ""

         

          tell application "Adobe Acrobat Pro"

              activate

              open pdfFile

              delay 1

             

              set trimVals to my getTrimValues()

              --display dialog "trimVals " & trimVals

              --set trimVals to {0.545, 0.545, 0.545, 0.545}

              delay 1

              my cropProcess(trimVals)

             

          end tell

         

      end mainProcess

       

       

      on cropProcess(trimVals)

         

          local cropboxFlg, boxTypeValue2

          set boxTypeValue2 to "CropBox"

          set cropboxFlg to 0

         

          tell application "System Events"

              tell process "Acrobat"

                 

                  click menu item "Crop Pages..." of menu 1 of menu bar item "Document" of menu bar 1

                 

                  if exists window "Crop Pages" then

                      tell window "Crop Pages"

                          tell pop up button 1 of group "Crop Margins"

                             

                              set boxType to value of item 1 as string

                              if boxType is not equal to boxTypeValue2 then

                                  click

                                  click menu item boxTypeValue2 of menu 1 --    click TrimBox

                                  set cropboxFlg to 1

                              else

                                  set cropboxFlg to 1

                              end if

                             

                          end tell

                         

                          --click button "Revert To Selection" of group "Margin Controls" of group "Crop Margins"

                         

                          if cropboxFlg is equal to 1 then --     Get trim box values

                              set value of text field 1 of group "Margin Controls" of group "Crop Margins" to (item 1 of trimVals) as string

                              set value of text field 2 of group "Margin Controls" of group "Crop Margins" to (item 2 of trimVals) as string

                              set value of text field 3 of group "Margin Controls" of group "Crop Margins" to (item 3 of trimVals) as string

                              set value of text field 4 of group "Margin Controls" of group "Crop Margins" to (item 4 of trimVals) as string

                             

                          end if

                          click radio button "All" of group "Page Range"

                          click button "OK"

                      end tell

                     

                     

                  else

                      display dialog "ELSE..."

                  end if

                 

              end tell

          end tell

      end cropProcess

       

      on getTrimValues()

         

          local trimTop, trimBottom, trimLeft, trimRight

          local trim_box, trimboxFlg

          set boxTypeValue1 to "TrimBox"

          set trimboxFlg to 0

          set trimTop to 0

          set trimBottom to 0

          set trimLeft to 0

          set trimRight to 0

         

         

          tell application "System Events"

              tell process "Acrobat"

                 

                  click menu item "Crop Pages..." of menu 1 of menu bar item "Document" of menu bar 1

                 

                  if exists window "Crop Pages" then

                      tell window "Crop Pages"

                          tell pop up button 1 of group "Crop Margins"

                             

                              set boxType to value of item 1 as string

                              if boxType is not equal to boxTypeValue1 then

                                  click

                                  click menu item boxTypeValue1 of menu 1 --    click TrimBox

                                  set trimboxFlg to 1

                              else

                                  set trimboxFlg to 1

                              end if                       

                          end tell

                         

                          if trimboxFlg is equal to 1 then                       

                              set trimTop to the value of text field 1 of group "Margin Controls" of group "Crop Margins" as string

                              set trimBottom to the value of text field 2 of group "Margin Controls" of group "Crop Margins" as string

                              set trimLeft to the value of text field 3 of group "Margin Controls" of group "Crop Margins" as string

                              set trimRight to the value of text field 4 of group "Margin Controls" of group "Crop Margins" as string

                           end if

                    end tell

       

                  end if

                 

              end tell

          end tell

          return {trimTop, trimBottom, trimLeft, trimRight}

      end getTrimValues

       

       

       

      - Sudha K

        • 1. Re: Crop PDF
          Test Screen Name Most Valuable Participant

          There is a JavaScript method for setting the CropBox.

          • 2. Re: Crop PDF
            Sudha K Level 1

            Hi,

             

                 I am not familiar in acrobat scripting. I want to do this for batch and also need to write error report if there is any issue occur.

             

                 I feel its easy in applescript also i can call applescript  through java.  So using applescript.

            • 3. Re: Crop PDF
              Test Screen Name Most Valuable Participant

              Adobe have thousands of pages of documentation on their supported interfaces in the Acrobat SDK. They don't support this sort of UI automation, so there won't be any information to help you do that.

               

              For batch why not just use Acrobat actions?

              • 4. Re: Crop PDF
                Sudha K Level 1

                Can we write report file like csv using scripting or actions?

                 

                Actually i completed all process by applescript. When i run the code its fully completed but the process of crop is not happen.

                • 5. Re: Crop PDF
                  Test Screen Name Most Valuable Participant

                  Acrobat JavaScript is not good for writing reports, and actions could only use JavaScript. So you could keep the AppleScript for this and use the AppleScript interface to JavaScript to set the cropping.

                   

                  Did you check that if you complete the SAME sequence of steps manually in the UI that the crop happens as you expect? This is the only tip I can give, we have no way to help you fix problems in UI automation, Adobe have no interest in that. I know there is enthusiasm for such unsupported methods though, maybe you'll find an AppleScript forum.

                  • 6. Re: Crop PDF
                    Sudha K Level 1

                    Hi,

                     

                         yes i have checked manually its working fine. I will check it as you suggested.

                     

                         Thank you so much...