set theDataFile to "ユーザーデータ.tab.txt" as text
set theTemplatesFile to "Templates.pdf" as text
set theFormNameA to "textA" as text
set theFormNameB to "textB" as text
set theFormNameC to "textC" as text
set theFormNameD to "textD" as text
tell application "Finder"
set theDefaultLocation to (container of (path to me)) as text
end tell
set theDefaultLocationDir to (POSIX path of theDefaultLocation) as text
set theTemFilePath to ("" & theDefaultLocationDir & theTemplatesFile & "") as text
tell application "Finder"
try
make new folder at theDefaultLocation with properties {name:("OutPut")}
end try
end tell
set theOutPutDir to ("\"" & theDefaultLocationDir & "OutPut\"") as text
set theDataFile to ("\"" & theDefaultLocationDir & "Data/" & theDataFile & "\"") as text
set theData to (do shell script "cat " & theDataFile) as «class utf8»
set AppleScript's text item delimiters to {"\n"}
set listData to (every text item of theData) as list
set numDataCnt to (count of listData) as integer
set AppleScript's text item delimiters to {""}
if numDataCnt is 1 then
set AppleScript's text item delimiters to {"\r"}
set listData to (every text item of theData) as list
set numDataCnt to (count of listData) as integer
set AppleScript's text item delimiters to {""}
end if
set numReadCnt to 2 as integer
repeat (numDataCnt - 1) times
set theLineData1 to ("") as text
set theLineData2 to ("") as text
set theLineData3 to ("") as text
set theLineData4 to ("") as text
set theReadListData to (item numReadCnt of listData) as text
set AppleScript's text item delimiters to {"\t"}
set listReadListData to (every text item of theReadListData) as list
set AppleScript's text item delimiters to {""}
set theData1 to (item 1 of listReadListData) as text
set theData2 to (item 2 of listReadListData) as text
set theData3 to (item 3 of listReadListData) as text
set theData4 to (item 4 of listReadListData) as text
log "theData1:" & theData1
log "theData2:" & theData2
log "theData3:" & theData3
log "theData4:" & theData4
set theData2 to doReplace(theData2, " ", "") as text
set theData2 to doReplace(theData2, " ", "") as text
set theSaveFileName to (theData2 & ".pdf")
set theOutPutFile to ("" & theDefaultLocationDir & "OutPut/" & theSaveFileName & "") as text
tell application "Adobe Acrobat"
do script "app.openDoc(\"" & theTemFilePath & "\");"
tell window 1
do script "var theAText = \"" & theData1 & "\";"
do script " this.getField(\"" & theFormNameA & "\").value = theAText;"
do script "var theTextA = this.getField(\"" & theFormNameA & "\").value;"
do script "console.println('theTextA: ' + theTextA);\n"
do script "var theBText = \"" & theData2 & "\";"
do script " this.getField(\"" & theFormNameB & "\").value = theBText;"
do script "var theTextB = this.getField(\"" & theFormNameB & "\").value;"
do script "console.println('theTextB: ' + theTextB);\n"
do script "var theCText = \"" & theData3 & "\";"
do script " this.getField(\"" & theFormNameC & "\").value = theCText;"
do script "var theTextC = this.getField(\"" & theFormNameC & "\").value;"
do script "console.println('theTextC: ' + theTextC);\n"
do script "var theDText = \"" & theData4 & "\";"
do script " this.getField(\"" & theFormNameD & "\").value = theDText;"
do script "var theTextD = this.getField(\"" & theFormNameD & "\").value;"
do script "console.println('theTextD: ' + theTextD);\n"
do script "this.flattenPages();"
do script "this.removeThumbnails();"
do script "this.saveAs(\"" & theOutPutFile & "\");"
delay 1
do script "closeDoc();"
end tell
end tell
set numReadCnt to (numReadCnt + 1) as integer
end repeat
to doReplace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end doReplace