• 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
Cannot get Java script to work with Acrobat DC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cannot get Java script to work with Acrobat DC


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

G’day

This relates my Code 128 font problem.

In Acrobat DC, using my old version of _javascript_, the Code 128 font only drew as rectangles in new text boxes. I could manually draw a new text box in the document, and set its contents to Code 128 OK, so I thought my _javascript_ needed updating.

Trouble is, I get a ‘can’t understand script’ message when running it.

An abbreviated version of the code is below. Would anyone with knowledge of Java mind telling me what I’m doing wrong, please?

Acrobat DC Java Documentation.

Of note, Using my old _javascript_ version, I can select the new text boxes, but cannot select and change the font of the displayed rectangles. If I hit Command-A while a text box is selected, then hit delete, the rectangles disappear, then I can type in new text, and it displays as the bar code 128 font. Darned if I know what’s wrong!

I also assume THIS below might have a bearing on my problem, but can’t get access to the Java Editor in El Capitan Acrobat DC.

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, 
});"

 _______________________________________________
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

  • Follow-Ups:
    • Fwd: Cannot get Java script to work with Acrobat DC
      • From: Brian Christmas <email@hidden>
  • Prev by Date: Re: Still after help with Barcode font issue, Please!
  • Next by Date: Re: How to Paste into Outlook 2011 using keystorkes/System Events
  • Previous by thread: Re: Still after help with Barcode font issue, Please!
  • Next by thread: Fwd: Cannot get Java script to work with Acrobat DC
  • Index(es):
    • Date
    • Thread