• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Fwd: Cannot get Java script to work with Acrobat DC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: Cannot get Java script to work with Acrobat DC


  • Subject: Fwd: Cannot get Java script to work with Acrobat DC
  • From: Brian Christmas <email@hidden>
  • Date: Sun, 28 Feb 2016 11:10:11 +1100



G’day

I’ve made a slight bit of progress on my Acrobat Barcode Code 128 problem.

Using the script below (with cTextFont instead of cFont), I can at least get a text box (or whatever it’s called) to display the text instead of rectangles, but it’s always in ‘Ariel’ font,instead of Code 128. I still cannot get the ‘this.addAnnot’ to work.

If I hilite the inserted text, I can manually reset it to Code 128.

I’m trying to see if the ‘Use of Arbitrary Fonts’ will make a difference, but cannot work out how to address the text box, to get any different Font value or name. I suspect from the Dictionary that no command is available, and don’t have the foggiest how to get the box and it’s font name from _javascript_.

I’m sorry to be a nuisance, but this version of Acrobat is driving me mad!  Hellllllllp, please!

Regards

Santa

tell application "Adobe Acrobat"
activate
set p to 1
tell document 1
tell page 1
set cbox to {}
if cbox = {} then set cbox to crop box
if cbox = {} then set cbox to bounds
if cbox = {} then set cbox to media box
if cbox = {} then set cbox to art box
if cbox = {} then set cbox to trim box
if cbox = {} then set cbox to bleed box
set p to 4
set pageTop to (item 2 of cbox) + 36
set p to 5
set item 2 of cbox to pageTop
set p to 6
set pageBottom to (item 4 of cbox)
set p to 7
set item 4 of cbox to pageBottom
set p to 8
set bounds to cbox
set p to 9
set media box to cbox
set p to 10
set crop box to cbox
set p to 11
set trim box to cbox
set p to 12
set bleed box to cbox
set p to 13
set art box to cbox
set p to 14
set theNewString to ((character id 209) & "this is a test" & (character id 211) as text)
#
# values are Text, Font, Font Size, Start Page, End Page, Text type?, Horizontal Alignment, Vertical Offset, Horizontal Offset, Vertical Height, Rotation, Current Page
set p to 15
set theResult1 to my Add_WaterMarkText(theNewString, "Code 128", 48, 1, 1, 1, 0, 3, 10, 0, 0, 1)
do script theResult1
set theResult1 to my Add_WaterMarkText(theNewString, "Code128", 48, 1, 1, 1, 0, 3, 10, 0, 0, 1)
set temp2 to "Text1"
#
# What do I refer the new box as???
set the name of watermark to "Text1"
set temp to do script "this.getField(temp2).textFont"
  end tell
display dialog temp


end tell
(*tell application "System Events" to tell process "Adobe Acrobat"
keystroke return
keystroke "a" using command down


set the font of the selection to "Code 128"


end tell*)
end tell
# This handler uses _javascript_
#
on Add_WaterMarkText(cText, cFont, nFontSize, nS, nE, nTA, nHorizontalAlignment, nVerticalAlignment, nHorizontalValue, nVerticalValue, nR, currentPage)
(*set theType to "FreeText" as text
set Params to "cPage:" & currentPage - 1 & ", " & return
set Params to Params & "cType:" & theType & ", " & return
set Params to Params & "cContents:" & cText & ", " & return
set Params to Params & "cTextFont:" & cFont & ", " & return
set Params to Params & "cTextSize:40, " & return
set Params to Params & "cRect:[1, 1, 300, 100], " & return
set Params to Params & "cWidth:0, " & return
set Params to Params & "cAlignment:0, " & return
set _javascript_ to "this.addAnnot({" & Params & "});"*)
set Params to "cTextFont: '" & cFont & "'," & return
set Params to Params & "cText: '" & cText & "'," & return
set Params to Params & "nFontSize: '" & nFontSize & "'," & return
if class of nS is integer then set Params to Params & "nStart: " & (currentPage - 1) & "," & return
if class of nE is integer then set Params to Params & "nEnd: " & (currentPage - 1) & "," & return
-- 0 = left, 1 = centre, 2 = right
if class of nHorizontalAlignment is integer then set Params to Params & "nHorizAlign: " & nHorizontalAlignment & "," & return
-- 3 = top, 4 = bottom
if class of nVerticalAlignment is integer then set Params to Params & "nVertAlign: " & nVerticalAlignment & "," & return
-- offset in points
if class of nHorizontalValue is integer then set Params to Params & "nHorizValue: " & nHorizontalValue & "," & return
-- offset in points
if class of nVerticalValue is integer then set Params to Params & "nVertValue: " & nVerticalValue & "," & return
if class of nR is integer then set Params to Params & "nRotation: " & nR & "," & return
set Params to Params & "bOnScreen: true" & "," & return
set Params to Params & "bOnPrint: true" & "," & return
set Params to Params & "bOnTop: true" & "," & return
set Params to Params & "nOpacity: 1.0" & "," & return
set _javascript_ to "this.addWatermarkFromText({" & Params & "});"
return _javascript_
end Add_WaterMarkText

Use of arbitrary fonts

Beginning with Acrobat 5.0, an arbitrary font can be used when laying out a text field, combo box, list box or button by setting the value of textFont to the PDSysFont font name, as returned by PDSysFontGetName. (See the Acrobat and PDF Library API Reference.)

To find the PDSysFont font name of a font:

1.Create a text field in a PDF document. Using the UI, set the text font for this field to the desired font.

2.Open the _javascript_ Debugger Console and execute the script 

      this.getField("Text1").textFont

The above code assumes the name of the field is Text1.

3.The string returned to the console is the font name needed to programmatically set the text font.



Regards

Santa


tell application "Adobe Acrobat"
activate
set p to 1
tell document 1
tell page 1
set cbox to {}
if cbox = {} then set cbox to crop box
if cbox = {} then set cbox to bounds
if cbox = {} then set cbox to media box
if cbox = {} then set cbox to art box
if cbox = {} then set cbox to trim box
if cbox = {} then set cbox to bleed box
set p to 4
set pageTop to (item 2 of cbox) + 36
set p to 5
set item 2 of cbox to pageTop
set p to 6
set pageBottom to (item 4 of cbox)
set p to 7
set item 4 of cbox to pageBottom
set p to 8
set bounds to cbox
set p to 9
set media box to cbox
set p to 10
set crop box to cbox
set p to 11
set trim box to cbox
set p to 12
set bleed box to cbox
set p to 13
set art box to cbox
set p to 14
set theNewString to ((character id 209) & "this is a test" & (character id 211) as text)
#
# values are Text, Font, Font Size, Start Page, End Page, Text type?, Horizontal Alignment, Vertical Offset, Horizontal Offset, Vertical Height, Rotation, Current Page
set p to 15
end tell
set theResult1 to my Add_WaterMarkText(theNewString, "Code 128", 48, 1, 1, 1, 0, 3, 10, 0, 0, 1)
# Generates a ‘doesn’t understand the “do script” message, see below.
do script theResult1
end tell
end tell

# This handler uses _javascript_
#
on Add_WaterMarkText(cText, cFont, nFontSize, nS, nE, nTA, nHorizontalAlignment, nVerticalAlignment, nHorizontalValue, nVerticalValue, nR, currentPage)
set theType to "FreeText" as text
set Params to "page:" & currentPage - 1 & ", " & return
set Params to Params & "type:" & theType & ", " & return
set Params to Params & "contents:" & cText & ", " & return
set Params to Params & "textFont:" & cFont & ", " & return
set Params to Params & "textSize:40, " & return
set Params to Params & "rect:[0, 0, 300, 100], " & return
set Params to Params & "width:0, " & return
set Params to Params & "alignment:0, " & return
set _javascript_ to "this.addAnnot({" & Params & "});"
return _javascript_

# OLD Script
(*set Params to "cText: '" & cText & "'," & return
set Params to Params & "cFont: '" & cFont & "'," & return
set Params to Params & "nFontSize: '" & nFontSize & "'," & return
if class of nS is integer then set Params to Params & "nStart: " & (currentPage - 1) & "," & return
if class of nE is integer then set Params to Params & "nEnd: " & (currentPage - 1) & "," & return
-- 0 = left, 1 = centre, 2 = right
if class of nHorizontalAlignment is integer then set Params to Params & "nHorizAlign: " & nHorizontalAlignment & "," & return
-- 3 = top, 4 = bottom
if class of nVerticalAlignment is integer then set Params to Params & "nVertAlign: " & nVerticalAlignment & "," & return
-- offset in points
if class of nHorizontalValue is integer then set Params to Params & "nHorizValue: " & nHorizontalValue & "," & return
-- offset in points
if class of nVerticalValue is integer then set Params to Params & "nVertValue: " & nVerticalValue & "," & return
if class of nR is integer then set Params to Params & "nRotation: " & nR & "," & return
set Params to Params & "bOnScreen: true" & "," & return
set Params to Params & "bOnPrint: true" & "," & return
set Params to Params & "bOnTop: true" & "," & return
set Params to Params & "nOpacity: 1.0" & "," & return*)
# set _javascript_ to "this.addWatermarkFromText({" & Params & "});"
end Add_WaterMarkText


error "Adobe Acrobat got an error: \"this.addAnnot({page:0, 
type:FreeText, 
contents:Ñthis is a testÓ, 
textFont:Code 128, 
textSize:40, 
rect:[0, 0, 300, 100], 
width:0, 
alignment:0, 
});\" doesn’t understand the “do script” message." number -1708 from "this.addAnnot({page:0, 
type:FreeText, 
contents:Ñthis is a testÓ, 
textFont:Code 128, 
textSize:40, 
rect:[0, 0, 300, 100], 
width:0, 
alignment:0, 
});"


And what, you ask, was the beginning of it all?
And it is this......
Existence that multiplied itself
For sheer delight of being
And plunged with numberless trillions of forms
So that it might
find
itself
innumerably

Sri Aurobindo



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Cannot get Java script to work with Acrobat DC (From: Brian Christmas <email@hidden>)

  • Prev by Date: Re: Adding a person to a group in Contacts
  • Next by Date: Re: Adding a person to a group in Contacts
  • Previous by thread: Cannot get Java script to work with Acrobat DC
  • Next by thread: Adding a person to a group in Contacts
  • Index(es):
    • Date
    • Thread