(* qxp_searchreplace_01.applescript *) tell application "QuarkXPress Passport" tell document 1 set text of every text of every story where it is "OLD" to "NEW" end tell end tell
(* qxp_searchreplace_01.applescript *) tell application "QuarkXPress Passport" tell document 1 set text of every text of every story where it is "OLD" to "NEW" end tell end tell
(* qxp_textbox_01.applescript Creates a new text box Properties are for example. *) tell application "QuarkXPress Passport" tell document 1 make new text box at end with properties {class:text box, content:text content, box type:text box type, box shape:rectangular, first baseline minimum:ascent baseline, first baseline offset:"0 mm", runaround all sides:false, storage:"", text outset:{"0 pt", "0 pt", "0 pt", "0 pt"}, vertical justification:top justified, columns:1, gutter:"4,233 mm", name:"LOG_TEST_MODUL", shade:"20%", runaround:none runaround, color:color spec "Gelb", blend:{style:solid blend}, frame:{style:dotted line, inside trap:default, outside trap:default, gap color:null, gap opacity:"0%", gap shade:"0%", width:"6 pt", color:color spec "Magenta"}, bounds:{"0 mm", "0,269 mm", "183,132 mm", "47,269 mm"}} set text of last generic box to "Das ist ein kleiner Test" set style sheet of paragraph 1 of story 1 of last generic box to object reference of style spec "Normal" set character style of every text of last generic box whose it is "Das ist ein kleiner Test" to object reference of character spec "Normal" end tell end tell
(* qxp_picturebox_01.applescript Creates a new picture box Properties are for example. It seems that not all properties are set properly when a new picture box is generated. Setting of image 1 of an picture box is some times a little bit buggy? *) tell application "QuarkXPress Passport" tell document 1 make new picture box at end with properties {class:picture box, name:"m_bilder_TEST", content:picture content, box type:picture box type, box shape:rounded corner, bounds:{"0 mm", "48 mm", "112,818 mm", "188 mm"}, storage:"", blend:{style:solid blend}, frame:{style:sparsely dashed line, inside trap:default, outside trap:default, gap color:null, gap opacity:"0%", gap shade:"0%", width:"3 pt", color:color spec "Schwarz"}, text outset:{"0 pt", "0 pt", "6 pt", "0 pt"}, corner radius:"10 mm", shade:"20%", runaround:item runaround, color:color spec "Schwarz"} -- Fixing some stuff set properties of last generic box to {corner radius:"10 mm", bounds:{"0 mm", "48 mm", "112,818 mm", "188 mm"}} -- Image file path & Image Properties try set image 1 of last generic box to file ("BootHD:Users:csg:Desktop:export_preissuchmaschine.png") -- another way to set image 1 --set image 1 of last generic box to ("BootHD:Users:csg:Desktop:export_preissuchmaschine.png" as alias) set properties of image 1 of last generic box to {actual bounds:{"-51,279 mm", "-38,459 mm", "268,111 mm", "274,461 mm"}, screen function:dot spot, offset:{"-38,459 mm", "-51,279 mm"}, scale:{"100%", "100%"}, invert runaround:false, show half tone:false, color:color spec "Schwarz"} end try end tell end tell
(* qxp_stylespec_01.applescript Creates a new text box Properties are for example. rule above and rule below (position and indent) are not correct scriptable. *) tell application "QuarkXPress Passport" tell document 1 if not (exists style spec "10_Hotelname") then make new style spec at beginning with properties {class:style spec, base style:null, character attributes:{language:3, font:"TheSans B7 Bold", shade:"60%", size:"12 pt", color:color spec "Schwarz"}, character style:null, key character:"", name:"10_Hotelname", next style:style spec "10_Hotelname", paragraph attributes:{rule above:{rule on:false}, rule below:{rule on:true, text length:Indents, position:"34%", style:solid line, width:"0,5 pt", color:color spec "0/60/100/0"}, left indent:"7 mm", grid lock:false, leading:"16 pt", justification:left justified, relative leading:false}} end if end tell end tell
(* qxp_characterspec_01.applescript Creates a new text box Properties are for example. *) tell application "QuarkXPress Passport" tell document 1 if not (exists character spec "10_Hotelname") then make new character spec at beginning with properties {class:character spec, base style:null, key character:"", language:3, font:"TheSans B7 Bold", name:"10_Hotelname", shade:"60%", size:"12 pt", color:color spec "Schwarz"} end if end tell end tell
(* qxp_colorspec_01.applescript Creates a new colorspec Properties are for example. For more details see the dictionary. *) tell application "QuarkXPress Passport" tell document 1 if not (exists color spec "0/60/100/0") then make new color spec at beginning with properties {class:color spec, color type:CMYK type, angle:"45", CMYK color value:{0, 39321, 65535, 0}, name:"0/60/100/0", separation:true} end if end tell end tell
(* qxp_document_02.applescript Creates a new document with two pages with different master spread an some rulers *) tell application "QuarkXPress Passport" --set default document set properties of default document 1 to {class:document, auto leading:"20%", automatic trap amount:"0,144 pt", auto constrain:false, auto picture import:auto import off, automatic text box:false, auto kern:true, kern above:"4 pt", baseline grid increment:"8,9 pt", baseline grid start:"11 mm", baseline grid showing:false, ciceros per centimeter:"2,197", facing pages:false, flex space width:"50%", fractional character widths:true, frame inside:true, guides in front:true, horizontal measure:millimeters, hyphenation method:expanded hyphenation, ignore white:true, item spread coords:false, keep master page items:true, knockout limit:"0", ligatures on:standard ligatures, lock guides:false, maintain leading:true, maximum ligature track:"1", overprint limit:"0", page height:"297 mm", points per inch:"72", process trap:true, page width:"210 mm", subscript horizontal scale:"100%", subscript offset:"33%", subscript vertical scale:"100%", single layout mode:false, trapping method:absolute trap, auto page insertion location:end of story, indeterminate trap amount:"0,144 pt", typesetting leading mode:true, vertical measure:millimeters, bottom margin:"8 mm", column count:1, greek below:"7 pt", greek pictures:false, guides showing:true, gutter width:"4,233 mm", inside margin:"8 mm", invisibles showing:true, left margin:"8 mm", outside margin:"8 mm", right margin:"8 mm", rulers showing:true, top margin:"8 mm", view scale increment:"25%", minimum view scale:"10%", maximum view scale:"800%", view scale:"110,3%"} -- neues document set thedoc to make new document at beginning -- reference zu master document set theMaster to object reference of master document 1 -- neue Musterseiten anlegen make new spread at end of master document 1 with properties {name:"left"} make new spread at end of master document 1 with properties {name:"right"} -- reference zu den musterseiten set theLeft to a reference to spread "left" of theMaster set theRight to a reference to spread "right" of theMaster -- set margin rulers und columns der musterseiten set properties of page 1 of theLeft to {column count:1, gutter width:"4,233 mm", top margin:"8 mm", left margin:"8 mm", bottom margin:"8 mm", right margin:"8 mm"} set properties of page 1 of theRight to {column count:6, gutter width:"2 mm", top margin:"5 mm", left margin:"5 mm", bottom margin:"5 mm", right margin:"5 mm"} -- draw rulers to masterpages make new horizontal guide at end of page 1 of theLeft with properties {class:horizontal guide, position:"34 mm", scale:"10%"} make new horizontal guide at end of page 1 of theLeft with properties {class:horizontal guide, position:"68,626 mm", scale:"10%"} make new horizontal guide at end of page 1 of theLeft with properties {class:horizontal guide, position:"49,509 mm", scale:"10%"} make new horizontal guide at end of page 1 of theLeft with properties {class:horizontal guide, position:"78 mm", scale:"10%"} make new vertical guide at end of page 1 of theLeft with properties {class:vertical guide, position:"29,566 mm", scale:"10%"} make new vertical guide at end of page 1 of theLeft with properties {class:vertical guide, position:"68,957 mm", scale:"10%"} make new vertical guide at end of page 1 of theLeft with properties {class:vertical guide, position:"89,232 mm", scale:"10%"} make new vertical guide at end of page 1 of theLeft with properties {class:vertical guide, position:"48,683 mm", scale:"10%"} make new horizontal guide at end of page 1 of theRight with properties {class:horizontal guide, position:"2,626 mm", scale:"10%"} make new horizontal guide at end of page 1 of theRight with properties {class:horizontal guide, position:"36 mm", scale:"10%"} make new vertical guide at end of page 1 of theRight with properties {class:vertical guide, position:"13,327 mm", scale:"10%"} make new vertical guide at end of page 1 of theRight with properties {class:vertical guide, position:"84 mm", scale:"10%"} make new vertical guide at end of page 1 of theRight with properties {class:vertical guide, position:"126 mm", scale:"10%"} make new vertical guide at end of page 1 of theRight with properties {class:vertical guide, position:"184,228 mm", scale:"10%"} make new vertical guide at end of page 1 of theRight with properties {class:vertical guide, position:"186,737 mm", scale:"10%"} make new vertical guide at end of page 1 of theRight with properties {class:vertical guide, position:"189,559 mm", scale:"10%"} -- musterseiten zuweisen tell thedoc set master spread of page 1 to theLeft make new page at end of spread 1 with properties {master spread:theRight} end tell end tell
(* qxp_document_01.applescript Creates a new document All properties below are NOT needed to create a new document. It is possible to use only specific properties, the other properties will be set to default values. *) tell application "QuarkXPress Passport" set properties of default document 1 to {class:document, auto leading:"20%", automatic trap amount:"0,144 pt", auto constrain:false, auto picture import:auto import off, automatic text box:false, auto kern:true, kern above:"4 pt", baseline grid increment:"11 pt", baseline grid start:"4 mm", baseline grid showing:false, ciceros per centimeter:"2,197", facing pages:false, flex space width:"50%", fractional character widths:true, frame inside:true, guides in front:true, horizontal measure:millimeters, hyphenation method:expanded hyphenation, ignore white:true, item spread coords:false, keep master page items:true, knockout limit:"0", ligatures on:standard ligatures, lock guides:false, maintain leading:true, maximum ligature track:"1", overprint limit:"0", page height:"297 mm", points per inch:"72", process trap:true, page width:"420 mm", subscript horizontal scale:"100%", subscript offset:"33%", subscript vertical scale:"100%", single layout mode:false, trapping method:absolute trap, auto page insertion location:end of story, indeterminate trap amount:"0,144 pt", typesetting leading mode:true, vertical measure:millimeters, bottom margin:"8 mm", column count:1, greek below:"7 pt", greek pictures:false, guides showing:true, gutter width:"4,233 mm", inside margin:"8 mm", invisibles showing:true, left margin:"8 mm", outside margin:"8 mm", right margin:"8 mm", rulers showing:true, top margin:"8 mm", view scale increment:"25%", minimum view scale:"10%", maximum view scale:"800%", view scale:"86,3%"} make new document at beginning end tell
Folgendes kleines AppleScript wurde inspiriert durch ein PHP Script.
Ein mit Formularfeldern pröpariertes PDF wird als Vorlage benutzt. Die Formularfelder die als Wert bzw. Standardtext einen Platzhalter enthalten werden durch suchen/ersetzen mit Werten befüllt.
Dieses PDF kann einfach mit den Formularfunktionen von OpenOffice erstellt werden. Hier ist die OO Beispieldatei zu finden.
Einfach und genial. Ein Ansatz mit Potenzial ;-)
(* pdf_form_fill.applescript This applescript was inspired by the php script pdf_form_fill from @author Lars Wegmann info@wegmann-it.de The script replaces the values of the form textfield in a pdf file. For example: Make a new OpenOffice Writer document, insert some form textfields. The value of the fields represents the placeholders that would be replaced later with applescript. Notice: The placeholder it self must have the lenght of the maxlength of the form textfield. If the textfield has 40 characters the placeholder must have also 40 characters. The replace string can't be longer than the search string (the placeholder). *) --search/replace array set arr to {{"###FELD1###", "X1"}, {"###FELD2###", "X2"}} --open pdf file set pdfdata to readFile("/Applications/MAMP/htdocs/test/PDF/pdf-test.pdf") --process search/replace array set pdfdata to processArray(pdfdata, arr) --write pdf file writeFile("/Applications/MAMP/htdocs/test/PDF/pdf-test-replaced.pdf", pdfdata) on readFile(unixPath) set foo to (open for access (POSIX file unixPath)) set txt to (read foo for (get eof foo)) close access foo return txt end readFile on writeFile(unixPath, theData) set f to open for access unixPath with write permission write theData to f as string close access f end writeFile -- process array of search|replace values on processArray(theData, arr) repeat with sr in arr --search replace ascii if item 1 of sr is in theData then set theData to str_replace(item 1 of sr, str_pad(item 1 of sr, item 2 of sr), theData) end if --search replace hex if string2hex(item 1 of sr) is in theData then set theData to str_replace(string2hex(item 1 of sr), str_pad(string2hex(item 1 of sr), string2hex(item 2 of sr)), theData) end if end repeat return theData end processArray -- convert string to hex value on string2hex(this_String) set hex to "" repeat with i from 1 to count of this_String set hex to hex & char2hex(character i of this_String) end repeat return hex as string end string2hex -- convert character to hex value on char2hex(this_char) set the ASCII_num to (the ASCII number this_char) set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"} set x to item ((ASCII_num div 16) + 1) of the hex_list set y to item ((ASCII_num mod 16) + 1) of the hex_list return ("00" & x & y) as string end char2hex on str_pad(str1, str2) set c1 to count of str1 set c2 to count of str2 set pad to "" if c2 is less than c1 then repeat with i from 1 to c1 - c2 set pad to pad & " " end repeat end if return str2 & pad end str_pad -- find : Text (or list of text) to be found -- replace : Text (or list of text) to replace with -- subject : Text (or list of text) to be searched on str_replace(find, replace, subject) set prevTIDs to text item delimiters of AppleScript set returnList to true -- This wouldn't make sense (you could have it raise an error instead) if class of find is not list and class of replace is list then return subject if class of find is not list then set find to {find} if class of subject is not list then ¬ set {subject, returnList} to {{subject}, false} set findCount to count find set usingReplaceList to class of replace is list try repeat with i from 1 to (count subject) set thisSubject to item i of subject repeat with n from 1 to findCount set text item delimiters of AppleScript to item n of find set thisSubject to text items of thisSubject if usingReplaceList then try item n of replace on error "" -- `replace` ran out of items end try else replace end if set text item delimiters of AppleScript to result set thisSubject to "" & thisSubject end repeat set item i of subject to thisSubject end repeat end try set text item delimiters of AppleScript to prevTIDs if not returnList then return beginning of subject return subject end str_replace
(* Loop optimizing Example 1 *) set MyList to {} repeat 10000 times set the end of MyList to " hello from the loop" end repeat return MyList as text -- 5.63s set MyString to "" repeat 10000 times set MyString to MyString & " hello from the loop" end repeat -- 3.71s
(* Loop optimizing Example 2 for complete overview. * For speed testing you have to split this example in two separate files *) (* * slow version *) --create a list to work with set MyList to {} --put 5000 elements in the list for us to walk through for testing repeat with i from 0 to 5000 set the end of MyList to i end repeat --now walk the list again and add up all the number set MyTotal to 0 repeat with ThisValue in MyList set MyTotal to MyTotal + ThisValue end repeat --return MyTotal --2.87s (* * fast version *) --create a global scope list to work with property MyGlobalList : {} --make sure it's empty as these are persistent between runs set MyGlobalList to {} --now work with a reference to that global list set MyList2 to a reference to MyGlobalList --put 5000 elements in the list for us to walk through for testing repeat with i from 0 to 5000 set the end of MyList2 to i end repeat --now walk the list again and add up all the number set MyTotal2 to 0 repeat with ThisValue in MyList2 set MyTotal2 to MyTotal2 + ThisValue end repeat --return MyTotal2 --0.09s !!!