G’day
I recently had a perplexing issue arise with Acrobat 9 pro. Adding a barcode as Header & Footer seemed to sometimes overlap an image.
Turned out that if images are rotated, all the various boxes surrounding the image get rotated as well.
As this is not mentioned in the Acrobat Dictionary, and info is not available on the web regarding scripting Acrobat, i thought this would be a suitable forum for posting the answer.
This uses a free non-commercial-use bar-code font, “IDAutomationHC39M”.
http://www.idautomation.com/fonts/free/
Regards
Santa
global pdfHeader
global tempattachmentname
global PreserveFileName
set pdfHeader to true
set tempattachmentname to "(2011121212101010Z)"
set PreserveFileName to "this is a test"
tell application "Adobe Acrobat Pro"
activate
try
close all docs saving no
end try
open ((path to desktop) & "Test 180.pdf") as text
tell document 1 to tell page 1
say rotation as text
set B to media box
set c to bounds
set d to crop box
set e to art box
set f to trim box
set g to bleed box
my ADDHeaderFooter("", "")
tell application "System Events" to tell process "Acrobat"
try
if (enabled of menu item "Crop Pages..." of menu 1 of menu bar item "Document" of menu bar 1) then
keystroke "t" using {command down, shift down}
set x to 0
repeat until window "Crop Pages" exists
set x to x + 1
if x = 50 then exit repeat
delay 0.1
end repeat
click checkbox "Remove White Margins" of group 1 of group 1 of window "Crop Pages"
key code 36
end if
end try
end tell
set bb to media box
set cc to bounds
set dd to crop box
set ee to art box
set ff to trim box
set gg to bleed box
set tempBox to bounds as list
if rotation as number = 0 then
set tempwidth to (item 3 of tempBox) - (item 1 of tempBox)
if tempwidth < 250 then set item 3 of tempBox to (item 3 of tempBox) + (250 - tempwidth)
if pdfHeader then
set item 4 of tempBox to (item 4 of tempBox) - 50 -- bottom
else
set item 4 of tempBox to (item 4 of tempBox) - 20
end if
set item 1 of tempBox to (item 1 of tempBox) - 20 -- left
set item 2 of tempBox to (item 2 of tempBox) + 50 -- top
set item 3 of tempBox to (item 3 of tempBox) + 20 -- right
end if
if rotation as number = 90 then
set tempwidth to (item 2 of tempBox) - (item 4 of tempBox)
if tempwidth < 250 then set item 2 of tempBox to (item 2 of tempBox) + (250 - tempwidth)
if pdfHeader then
set item 3 of tempBox to (item 3 of tempBox) + 50 -- bottom
else
set item 3 of tempBox to (item 3 of tempBox) + 20
end if
set item 4 of tempBox to (item 4 of tempBox) - 20 -- left
set item 1 of tempBox to (item 1 of tempBox) - 50 -- top
set item 2 of tempBox to (item 2 of tempBox) + 20 -- right
end if
if rotation as number = 180 then
set tempwidth to (item 3 of tempBox) - (item 1 of tempBox)
if tempwidth < 250 then set item 1 of tempBox to (item 1 of tempBox) - (250 - tempwidth)
if pdfHeader then
set item 2 of tempBox to (item 2 of tempBox) + 50 -- bottom
else
set item 2 of tempBox to (item 2 of tempBox) + 20
end if
set item 3 of tempBox to (item 3 of tempBox) + 20 -- left
set item 4 of tempBox to (item 4 of tempBox) - 50 -- top
set item 1 of tempBox to (item 1 of tempBox) - 20 -- right
end if
if rotation as number = 270 then
set tempwidth to (item 2 of tempBox) - (item 4 of tempBox)
if tempwidth < 250 then set item 4 of tempBox to (item 4 of tempBox) - (250 - tempwidth)
if pdfHeader then
set item 1 of tempBox to (item 1 of tempBox) - 50 -- bottom
else
set item 1 of tempBox to (item 1 of tempBox) - 20
end if
set item 2 of tempBox to (item 2 of tempBox) + 20 -- left
set item 3 of tempBox to (item 3 of tempBox) + 50 -- top
set item 4 of tempBox to (item 4 of tempBox) - 20 -- right
end if
set crop box to tempBox --
set media box to tempBox --
set art box to tempBox --
set trim box to tempBox --
set bleed box to tempBox --
set bounds to tempBox --
set hh to crop box
my ADDHeaderFooter(tempattachmentname, PreserveFileName)
end tell
end tell
on ADDHeaderFooter(tempattachmentname2, PreserveFileName2)
tell application "System Events" to tell process "Acrobat"
click menu item "Add..." of menu 1 of menu item "Header & Footer" of menu 1 of menu bar item "Document" of menu bar 1
delay 1
repeat while exists button "Replace Existing" of window 1
click button "Replace Existing" of window 1
delay 0.1
end repeat
--delay 1
set x to 0
repeat until exists window "Add Header and Footer"
try
click button "Replace Existing" of window 1
end try
set x to x + 1
if x = 300 then exit repeat
delay 0.1
end repeat
--if RunForOz then delay 4
set value of text field 2 of group 2 of window "Add Header and Footer" to "0.1"
set value of text field 3 of group 2 of window "Add Header and Footer" to "0.6"
set value of combo box 1 of group 1 of window "Add Header and Footer" to "10"
delay 0.2
--set temp to value of text field 3 of group 2 of window "Add Header and Footer"
--if temp < 1.0 then set value of text field 3 of group 2 of window "Add Header and Footer" to "1.0"
if pdfHeader then
if PreserveFileName2 = "" then
set value of text area 1 of scroll area 5 of window "Add Header and Footer" to ""
else
set value of text area 1 of scroll area 5 of window "Add Header and Footer" to "(" & PreserveFileName2 & ")"
end if
end if
set value of text area 1 of scroll area 2 of window "Add Header and Footer" to tempattachmentname2
delay 0.1
click pop up button 1 of group 1 of window "Add Header and Footer"
click menu item "IDAutomationHC39M" of menu 1 of pop up button 1 of group 1 of window "Add Header and Footer"
set x to 0
repeat until exists button "OK" of window "Add Header and Footer"
delay 0.1
set x to x + 1
if x = 50 then exit repeat
end repeat
set x to 0
repeat while exists window "Add Header and Footer"
delay 0.1
keystroke return
set x to x + 1
if x = 50 then exit repeat
end repeat
end tell
end ADDHeaderFooter
B & return & c & return & d & return & e & return & f & return & g & return & return & bb & return & cc & return & dd & return & ee & return & ff & return & gg & return & return & hh & return & return & tempBox