Author Topic: Acrobat Applescript do Javascript  (Read 4248 times)

0 Members and 1 Guest are viewing this topic.

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Acrobat Applescript do Javascript
« on: April 05, 2007, 05:16:58 AM »
Posting here on the off chance someone with javascript knowledge can help me out! I've posted elsewhere with no response. Am I going the right way to get the "printParams" I want my script to override the users current choice of settings in advanced print set up. Here is what I have so far:

001   -- Flag integer values
002   property applyOverPrint : 131072
003   property applySoftProofSettings : 2097152
004   property applyWorkingColorSpaces : 262144
005   property emitCJKTTasT2 : 134217728
006   property emitFlatness : 67108864
007   property emitFormsAsPSForms : 4194304
008   property emitHalftones : 1
009   property emitPostScriptXObjects : 524288
010   property maxJP2KRes : 8388608
011   property setPageSize : 1024
012   property suppressBG : 16
013   property suppressCJKFontSubst : 64
014   property suppressCenter : 256
015   property suppressCropClip : 4
016   property suppressRotate : 128
017   property suppressTransfer : 8
018   property suppressUCR : 32
019   property usePrintersMarks : 33554432
020   property useTrapAnnots : 16777216
021   -- Raster flag integer values
022   property textToOutline : 1
023   property strokesToOutlines : 2
024   property allowComplexClip : 4
025   property preserveOverprint : 8
026   
027   -- binaryOK: (boolean)
028   -- bitmapDPI: (integer)
029   -- colorOverride: {Auto = 0, Grey = 1, mono = 2} (integer)
030   -- colorProfile: (integer)
031   -- downloadFarEastFonts: (boolean)
032   -- flags: bit field (integer) Needs to be created from the above propertys…?
033   -- fontPolicy: {everyPage = 2, jobStart = 0, pageRange 1} (integer)
034   -- gradientDPI: (integer)
035   -- pageHandling: {fit = 2, nUp = 6, none = 1, shrink = 3, tileAll = 5, tileLarge = 4} (integer)
036   -- pageSubset: {all = -3, even = -5, odd = -4} (integer)
037   -- printAsImage: (boolean) PS Level 1
038   -- printContent: {doc = 0, docAndComments = 1, formFieldsOnly = 2} (integer)
039   -- psLevel: {2, 3} (integer)
040   -- rasterFlagValues: bit field (integer) Needs to be created from the above propertys…?
041   -- reversePages: (boolean)
042   -- transparencyLevel:  (integer)
043   -- useT1Conversion: (boolean)
044   
045   -- Record the current printer and set printer choice
046   tell application "Printer Setup Utility"
047        set DefaultPrinter to the current printer
048        set current printer to printer "DC_3535_DC3535_Print"
049   end tell
050   -- Get list of PDF's
051   set Q1 to "Do you want to include all the subfolders" & return & "within your folder selection?"
052   set theDialog to display dialog Q1 buttons {"No", "Yes"} default button 1 with icon note
053   if button returned of theDialog is "Yes" then
054        set inputFolder to choose folder with prompt "Where is the top level folder of PFD's?" without invisibles
055        tell application "Finder"
056             try
057                  set filesList to (files of entire contents of inputFolder whose name extension is "pdf") as alias list
058             on error -- only one file
059                  set filesList to (files of entire contents of inputFolder whose name extension is "pdf") as alias as list
060             end try
061        end tell
062   else
063        tell application "Finder"
064             set inputFolder to choose folder with prompt "Where is the folder of PFD's?" without invisibles
065             try
066                  set filesList to (files of inputFolder whose name extension is "pdf") as alias list
067             on error -- only one file
068                  set filesList to (files of inputFolder whose name extension is "pdf") as alias as list
069             end try
070        end tell
071   end if
072   set countA to count of filesList
073   if countA = 0 then
074        display dialog "This folder contains no PDF files to print!" giving up after 2
075   end if

Posted on: April 03, 2007, 04:08:17 AM
The rest:

001   -- Loop through the list of files
002   repeat with aFile in filesList
003        set fileIndex to 0
004        tell application "Finder"
005             set theFile to aFile as alias
006        end tell
007        tell application "Adobe Acrobat 7.0 Pr#2CB915"
008             activate
009             open theFile
010             tell active doc
011                  -- Set the window size and document view
012                  set bounds to {146, 42, 1198, 1200}
013                  set view mode to just pages
014                  set zoom type of PDF Window 1 to fit page
015                  delay 1
016                  set MB_Size to media box of page 1 as list
017                  -- Points to millimeters Conversion
018                  set MB_Height to ((item 2 of MB_Size) / 2.834645) as integer
019                  set MB_Width to ((item 3 of MB_Size) / 2.834645) as integer
020                  -- Determine long & short edges
021                  if MB_Height is greater than or equal to MB_Width then
022                       set LE to MB_Height
023                       set SE to MB_Width
024                  else
025                       set LE to MB_Width
026                       set SE to MB_Height
027                  end if
028                  -- JavaScript indexing is zero based so minus 1
029                  set PageCount to (count of pages) - 1
030                  -- Set flag values
031                  set fv to applyOverPrint + applySoftProofSettings + applyWorkingColorSpaces + usePrintersMarks + suppressUCR + emitHalftones + suppressTransfer
032                  -- Set raster flag values
033                  set rfv to allowComplexClip + preserveOverprint + strokesToOutlines
034                  -- Set the print peramiters
035                  set PP1 to "{binaryOK: true, bitmapDPI: 300, colorProfile: 2, colorOverride: 0, downloadFarEastFonts: true, firstPage: 0, flags: " & fv & ", fontPolicy: 0, gradientDPI: 150, interactive: 2, lastPage: " & PageCount & ", pageHandling: 3, pageSubset: -3, printAsImage: false, printContent: 0, psLevel: 3, rasterFlagValues: " & rfv & ", reversePages: false, transparencyLevel: 75, useT1Conversion: true}"
036                  -- Determine ecconomic paper size
037                  set thisFit to false
038                  -- Fits on A5 paper (less printer margins)
039                  if LE < 200 and SE < 138.5 then
040                       set thisFit to true
041                       do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a5"
042                       delay 1
043                       -- Print document via JavaScript using PP1 inc fv & rfv
044                       do script "this.print({bUI: false, printParams: " & PP1 & "});"
045                       display dialog "This PDF Fits on A5" giving up after 2
046                  end if
047                  -- Fits on A4 paper (less printer margins)
048                  if LE < 287 and SE is less than or equal to 200 and thisFit is false then
049                       set thisFit to true
050                       do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a4"
051                       delay 1
052                       do script "this.print({bUI: false, printParams: " & PP1 & "});"
053                       display dialog "This PDF Fits on A4" giving up after 2
054                  end if
055                  -- Fits on A3 paper (less printer margins)
056                  if LE < 410 and SE is less than or equal to 287 and thisFit is false then
057                       do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a3"
058                       delay 1
059                       do script "this.print({bUI: false, printParams: " & PP1 & "});"
060                       display dialog "This PDF Fits on A3" giving up after 2
061                  end if
062                  -- Scale output to fit on A3 paper (less printer margins)
063                  if LE is greater than or equal to 410 or SE > 287 then
064                       do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a3"
065                       delay 1
066                       set PP2 to "{binaryOK: true, bitmapDPI: 300, colorProfile: 2, colorOverride: 0, downloadFarEastFonts: true, firstPage: 0, flags: " & fv & ", fontPolicy: 0, gradientDPI: 150, interactive: 2, lastPage: " & PageCount & ", pageSubset: -3, printAsImage: false, printContent: 0, psLevel: 3, rasterFlagValues: " & rfv & ", reversePages: false, transparencyLevel: 75, useT1Conversion: true}"
067                       -- Print document via JavaScript using PP2 inc fv & rfv
068                       do script "this.print({bUI: false, bShrinkToFit: true, printParams: " & PP2 & "});"
069                       display dialog "This PDF is larger than A3 & requires scaling" giving up after 2
070                  end if
071             end tell
072             close active doc saving no
073        end tell
074   end repeat
075   -- Set the printer choice back
076   tell application "Printer Setup Utility"
077        set current printer to DefaultPrinter
078   end tell

Posted on: April 03, 2007, 04:10:19 AM
BTW should have added that Im not getting any errors thrown out in Acrobat's Java console. The intention of the above script is to be generic and replace the finder choose folder part with a list created by any of my Quark print to Postscript scripts. When working I would like to have the end of all my Quark scripts call this script. Im not sure on how to do that yet but need to cross this bridge first. TIA
Posted on: April 03, 2007, 06:15:16 AM
Michel, this topic can now be moved to the newly created Acrobat area. Thanks.
« Last Edit: April 05, 2007, 06:08:31 AM by Publi-Script »