Acrobat Form

[Form]読取専用になったフォームの読取専用フラグを解除する

AcrobatのPDFフォームが 意図せず読取専用になってしまった場合の対応用スクリプト


ダウンロード - getfield_readonly.zip




サンプルコード

サンプルソース(参考)
行番号ソース
001//フィールドの数を数えて
002var numCntField = this.numFields;
003//フィールドの数だけ繰り返し
004for (var itemNo = 0; itemNo < numCntField; itemNo++) {
005  //フィールドを順番に取得して
006  var strFieldName = this.getNthFieldName(itemNo);
007  //設定値を変更する
008  this.getField(strFieldName).readonly = false;
009  this.getField(strFieldName).display = visible;
010}
011
012
013//読取専用を解除する
014var numCntField = this.numFields; for (var itemNo = 0; itemNo < numCntField; itemNo++) { var strFieldName = this.getNthFieldName(itemNo); this.getField(strFieldName).readonly = false; this.getField(strFieldName).display.visible; }
015
016//読取専用にする
017var numCntField = this.numFields; for (var itemNo = 0; itemNo < numCntField; itemNo++) { var strFieldName = this.getNthFieldName(itemNo); this.getField(strFieldName).readonly = true; this.getField(strFieldName).display.visible; }
AppleScriptで生成しました

|

PDFフォームの入力データ集計


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# 前提条件:フォームの名称が同じPDFのデータ集計用
005# 
006#  com.cocolog-nifty.quicktimer.icefloe
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
008use AppleScript version "2.8"
009use framework "Foundation"
010use framework "AppKit"
011use framework "PDFKit"
012use scripting additions
013
014property refMe : a reference to current application
015set appFileManager to refMe's NSFileManager's defaultManager()
016
017
018################################
019#ダイアログ PDF選択
020set strName to (name of current application) as text
021if strName is "osascript" then
022  tell application "Finder" to activate
023else
024  tell current application to activate
025end if
026set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
027set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
028set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
029set listUTI to {"com.adobe.pdf"}
030set strMes to ("ファイルを選んでください") as text
031set strPrompt to ("ファイルを選んでください") as text
032try
033  set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDefaultLocation of type listUTI with invisibles, multiple selections allowed and showing package contents) as list
034on error
035  log "エラーしました"
036  return "エラーしました"
037end try
038if listAliasFilePath is {} then
039  return "選んでください"
040end if
041
042################################
043#出力用のテキスト
044set ocidOutPutString to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
045#選択したファイルの数
046set numCntFile to (count of listAliasFilePath) as integer
047#出力用のテキストに入れる
048ocidOutPutString's appendString:(" \t収集ファイル合計: " & numCntFile & " 件\n")
049
050################################
051#選択したファイルの数だけ繰り返し
052repeat with itemNo from 1 to (numCntFile) by 1
053  #項番出力用のテキストに入れる
054  (ocidOutPutString's appendString:(itemNo as text))
055  (ocidOutPutString's appendString:("\t"))
056  #順番に取り出し
057  set itemAliasFilePath to (item itemNo of listAliasFilePath)
058  #パス
059  set aliasItemFilePath to itemAliasFilePath as alias
060  set strFilePath to (POSIX path of aliasItemFilePath) as text
061  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
062  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
063  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
064  #ファイル名
065  set strFileName to (ocidFilePathURL's lastPathComponent()) as text
066  #出力用のテキストに入れる
067  (ocidOutPutString's appendString:(strFileName))
068  (ocidOutPutString's appendString:("\t"))
069  #############
070  # NSData
071  set ocidOption to (refMe's NSDataReadingMappedIfSafe)
072  set listResponse to (refMe's NSData's dataWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference))
073  if (item 2 of listResponse) = (missing value) then
074    log "正常処理"
075    set ocidReadData to (item 1 of listResponse)
076  else if (item 2 of listResponse) ≠ (missing value) then
077    set strErrorNO to (item 2 of listDone)'s code() as text
078    set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
079    refMe's NSLog("■:" & strErrorNO & strErrorMes)
080    return "エラーしました" & strErrorNO & strErrorMes
081  end if
082  
083  #############
084  #PDFDocument
085  set ocidActivDoc to (refMe's PDFDocument's alloc()'s initWithData:(ocidReadData))
086  #PDFPAGE 1ページ目
087  set ocidActivPage to (ocidActivDoc's pageAtIndex:(0))
088  #############
089  #出力に使うDICT
090  set ocidFormDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
091  #############
092  #PDFAnnotation
093  set ocidAnnotationArray to ocidActivPage's annotations()
094  #アノテーションの数だけ繰り返し
095  repeat with itemAnnotation in ocidAnnotationArray
096    #備考用の値の初期化
097    set strAnoNoteValue to ("") as text
098    #注釈の種類を調べて
099    set strAnnoType to itemAnnotation's type() as text
100    if strAnnoType is "Widget" then
101      #Formの名称
102      set strAnoName to (itemAnnotation's fieldName()) as text
103      if strAnoName = (missing value) then
104        set strAnoName to (itemAnnotation's valueForAnnotationKey:("/T")) as text
105      end if
106      #Formの値
107      set strAnoValue to (itemAnnotation's widgetStringValue()) as text
108      if strAnoValue = (missing value) then
109        set strAnoValue to (itemAnnotation's valueForAnnotationKey:("/V")) as text
110      end if
111      (ocidFormDict's setValue:(strAnoValue) forKey:(strAnoName))
112    else
113      #フォーム以外の注釈があった場合は備考欄(最後)に入れる
114      set strNotes to (itemAnnotation's |contents|()) as text
115      if strNotes = (missing value) then
116        set strAnoNoteValue to (itemAnnotation's valueForAnnotationKey:("/Contents")) as text
117      else
118        set strAnoNoteValue to "" as text
119      end if
120    end if
121  end repeat
122  #############
123  #収集したデータを並び替えて出力テキストに入れていく
124  #キー=フォーム名をソートする
125  set ocidAllKeysArray to ocidFormDict's allKeys()
126  set ocidSortedAllKeysArray to (ocidAllKeysArray's sortedArrayUsingSelector:("localizedStandardCompare:"))
127  #キー順に値を取り出して
128  repeat with itemKey in ocidSortedAllKeysArray
129    set ocidValue to (ocidFormDict's valueForKey:(itemKey))
130    (ocidOutPutString's appendString:(ocidValue))
131    (ocidOutPutString's appendString:("\t"))
132  end repeat
133  #最後に備考を入れて改行
134  (ocidOutPutString's appendString:(strAnoNoteValue))
135  (ocidOutPutString's appendString:("\n"))
136  set strAnoNoteValue to ("") as text
137end repeat
138
139
140
141################################
142#最後に処理したPDFの階層に作成
143#コンテナ
144set ocidContainerPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
145#保存先
146set ocidSaveDirPathURL to ocidContainerPathURL's URLByAppendingPathComponent:("収集済データ") isDirectory:(false)
147#フォルダを作っておく
148set appFileManager to refMe's NSFileManager's defaultManager()
149set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
150ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
151ocidAttrDict's setValue:(1) forKey:(refMe's NSURLLabelNumberKey)
152set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
153if (item 1 of listDone) is true then
154  # log "正常処理"
155else if (item 2 of listDone) ≠ (missing value) then
156  set strErrorNO to (item 2 of listDone)'s code() as text
157  set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
158  refMe's NSLog("■:" & strErrorNO & strErrorMes)
159  return "エラーしました" & strErrorNO & strErrorMes
160end if
161
162
163################################
164#TSV関連
165#日付生成 ファイル名に
166set strDateText to doGetDateNo("yyyyMMdd")
167#保存先パス
168set ocidSaveBaseFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strDateText) isDirectory:(false)
169set ocidSaveFilePathURL to ocidSaveBaseFilePathURL's URLByAppendingPathExtension:("tsv")
170#保存
171set listDone to ocidOutPutString's writeToURL:(ocidSaveFilePathURL) atomically:(false) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
172if (item 1 of listDone) is true then
173  log "正常処理"
174else if (item 2 of listDone) ≠ (missing value) then
175  set strErrorNO to (item 2 of listDone)'s code() as text
176  set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
177  refMe's NSLog("■:" & strErrorNO & strErrorMes)
178  return "エラーしました" & strErrorNO & strErrorMes
179end if
180################################
181#開く
182set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
183set boolDone to appSharedWorkspace's openURL:(ocidSaveFilePathURL)
184
185
186
187return
188
189
190##############################
191### 今の日付日間 テキスト
192##############################
193to doGetDateNo(argDateFormat)
194  ####日付情報の取得
195  set ocidDate to current application's NSDate's |date|()
196  ###日付のフォーマットを定義
197  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
198  ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
199  set ocidTimeZone to refMe's NSTimeZone's alloc()'s initWithName:"Asia/Tokyo"
200  ocidNSDateFormatter's setTimeZone:(ocidTimeZone)
201  ocidNSDateFormatter's setDateFormat:(argDateFormat)
202  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
203  set strDateAndTime to ocidDateAndTime as text
204  return strDateAndTime
205end doGetDateNo
AppleScriptで生成しました

|

PDFドキュメントのフォームフィールドの情報の収集


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

###################################
#####設定項目
###################################
##収集したデータの保存ファイル名
set strDefaultFileName to "PDFフォーム.tsv" as text
set strTargetExtension to "tsv"
###################################
#####入力
###################################
###デスクトップ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDesktopDirPath to (ocidDesktopDirPathURL's absoluteURL()) as alias
##################
#ダイアログを全面に
set strName to (name of current application) as text
#スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  #スクリプトエディタで実行
  tell current application to activate
end if
set listUTI to {"com.adobe.pdf"} as list
###ダイアログテキスト
set strPromptText to "PDFを選んでください"
try
  set aliasFilePath to (choose file strPromptText with prompt strPromptText default location aliasDesktopDirPath of type listUTI without multiple selections allowed, invisibles and showing package contents) as alias
on error
log "エラーしました"
return
end try
###パス
set strFilePath to POSIX path of aliasFilePath as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false

##################################################
#####保存先
##################################################
#ダイアログを全面に
set strName to (name of current application) as text
#スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  #スクリプトエディタで実行
  tell current application to activate
end if
set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ファイル名 ダイアログ
set aliasSaveFilePath to (choose file name strMesText default location aliasDesktopDirPath default name strDefaultFileName with prompt strPromptText) as «class furl»
###パス
set strSaveFilePath to POSIX path of aliasSaveFilePath as text
set ocidSaveFilePathStr to refMe's NSString's stringWithString:(strSaveFilePath)
set ocidSaveFilePath to ocidSaveFilePathStr's stringByStandardizingPath
set ocidSaveFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveFilePath) isDirectory:false


###########################
####acrobat起動
tell application id "com.adobe.Acrobat.Pro"
activate
end tell
###########################
####起動チェック
tell application id "com.adobe.Acrobat.Pro"
  ####起動確認最大5秒
  repeat 5 times
activate
    set boolFrontmost to frontmost as boolean
    if boolFrontmost is true then
      exit repeat
    end if
delay 1
  end repeat
end tell
#####################
#####本処理
####出力用テキストの初期化
set ocidSaveString to refMe's NSMutableString's alloc()'s initWithCapacity:(0)

####ファイルを開く
tell application id "com.adobe.Acrobat.Pro"
  try
do script "app.openDoc(\"" & strFilePath & "\");"
  on error
open file (POSIX file strFilePath as alias)
  end try
end tell

#####################
#オープン待ち
tell application id "com.adobe.Acrobat.Pro"
  ####起動確認最大5秒
  repeat 10 times
activate
    set numCntOpenDoc to (count of every document) as integer
    if numCntOpenDoc = 0 then
delay 0.5
    else
      exit repeat
    end if
  end repeat
end tell

###########################
####開いたファイルのフォーム情報を取得する
tell application id "com.adobe.Acrobat.Pro"
  ###フォームの数を数える
do script "var numCntFild = this.numFields"
  set numCntFild to (do script " this.numFields") as text
log "フィールド数:" & numCntFild
end tell
set numCntChkFild to 0 as integer
repeat numCntFild times
  tell application id "com.adobe.Acrobat.Pro"
    ######順番にフォーム名を取得
    # do script "var strFildTitle = this.getNthFieldName(" & numCntChkFild & ").value;"
    set strFiledTitle to (do script "this.getNthFieldName(" & numCntChkFild & ")") as text
log "フィールド名:" & strFiledTitle
    if strFiledTitle is ("undefined") then
      set strFiledTitle to "" as text
    end if
ocidSaveString's appendString:(strFiledTitle)
ocidSaveString's appendString:("\t")
    ######フォームの内容を取得
    # do script "var strGetFormValue = this.getField(\"" & strFiledTitle & "\").value;"
    set strFormValeText to (do script "this.getField(\"" & strFiledTitle & "\").value;") as text
    if strFormValeText is ("undefined") then
      set strFormValeText to "" as text
    end if
log "フォームの値:" & strFormValeText
ocidSaveString's appendString:(strFormValeText)
ocidSaveString's appendString:("\n")
  end tell
  set numCntChkFild to numCntChkFild + 1 as integer
end repeat

set listDone to ocidSaveString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
if (item 1 of listDone) = true then
log "TSVファイルに保存しました"
else
log "失敗しました"
end if




|

【フォームデータ収集】XMLなFDF (XML形式とXDFDの違い)

フォームデータの収集です。
注釈データではありませんので留意ください
サンプルデータ

ダウンロード - このままデスクトップへ.zip


XML形式はフラットなリスト構造

【スクリプトエディタで開く】|

<?xml version="1.0" encoding="UTF-8"?>
<fields xmlns:xfdf="http://ns.adobe.com/xfdf-transition/">
<SOME_FORM_A>AAAAAAAAAAAAAAAAAA</SOME_FORM_A>
<SOME_FORM_B>BBBBBBBBBBBBBBBB</SOME_FORM_B>
</fields>


XFDFはリスト構造がやや複雑

【スクリプトエディタで開く】|

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<f href="FILE_NAME.pdf"/>
<fields>
<field name="SOME_FORM_A">
<value>AAAAAAAAAAAAAAAAAA</value>
</field>
<field name="SOME_FORM_B">
<value>BBBBBBBBBBBBBBBB</value>
</field>
</fields>
</xfdf>

XMLなFDFの取得

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application


#######【1】URL

set strFilePath to "~/Desktop/XMLなFDF.xml" as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)


#######【2】NSXMLDocument
set ocidOption to (refMe's NSXMLDocumentTidyXML)
set listReadXMLDoc to refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference)
set ocidReadXMLDoc to (item 1 of listReadXMLDoc)
###ROOT
set ocidRootElement to ocidReadXMLDoc's rootElement()
set numChild to (count of ocidRootElement's children) as integer
###第一階層だけの子要素
repeat with numCntChild from 0 to (numChild - 1)
  log (ocidRootElement's childAtIndex:numCntChild)'s |name| as text
  log (ocidRootElement's childAtIndex:numCntChild)'s stringValue as text
end repeat

-->出力
(*SOME_FORM_A*)
(*AAAAAAAAAAAAAAAAAA*)
(*SOME_FORM_B*)
(*BBBBBBBBBBBBBBBB*)

XFDFはattribute有り

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application


#######【1】URL

set strFilePath to "~/Desktop/XMLなFDF.xfdf" as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)


#######【2】NSXMLDocument
set ocidOption to (refMe's NSXMLDocumentTidyXML)
set listReadXMLDoc to refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference)
set ocidReadXMLDoc to (item 1 of listReadXMLDoc)
###ROOT
set ocidRootElement to ocidReadXMLDoc's rootElement()
###ファイル名部
set ocidChilds to ocidRootElement's elementsForName:"f"
set ocidFileName to (ocidChilds's objectAtIndex:0)
set ocidAttribute to (ocidFileName's attributeForName:"href")
log ocidAttribute's stringValue as text

###fields
set ocidChilds to ocidRootElement's elementsForName:"fields"
set ocidElementFields to (ocidChilds's objectAtIndex:0)
###子要素 構造的にはArray
set ocidChilds to ocidElementFields's elementsForName:"field"
set numChild to (count of ocidChilds's children) as integer

###第一階層だけの子要素
repeat with numCntChild from 0 to (numChild - 1)
  set ocidElementField to (ocidChilds's objectAtIndex:(numCntChild))
  set ocidAttribute to (ocidElementField's attributeForName:"name")
  log ocidAttribute's stringValue as text
  set ocidValue to (ocidElementField's elementsForName:("value"))
  log ocidValue's stringValue as text
end repeat
-->出力
(*FILE_NAME.pdf*)
(*SOME_FORM_A*)
(*AAAAAAAAAAAAAAAAAA*)
(*SOME_FORM_B*)
(*BBBBBBBBBBBBBBBB*)

|

[FORM]メール文書を作成中にエラーが発生したので、Adobe Acrobat は要求を完了することができませんでした。

エラーメッセージが
『メール文書を作成中にエラーが発生したので、Adobe Acrobat は要求を完了することができませんでした。次の手順に進む方法がわからない場合は、フォームを保存し、インターネット電子メールサービスを使用してそのフォームを手動で返信することができます。』
なら

システム設定>>プライバシーとセキュリティ>>オートメーション

Acrobatがメールを許可しているかです

Screencapture-20230526-201635

↑これを
↓こうね
Screencapture-20230526-211607

|

フォームベーシック(数値)

ダウンロード - acr6842168065282355621.tmp.pdf


Screencapture_20230515_11_08_09
Screencapture_20230515_11_00_31
Screencapture_20230515_11_00_45
Screencapture_20230515_11_20_50
Screencapture_20230515_11_01_01

【スクリプトエディタで開く】|

//フォームの値を取得
var numGetNumber = event.value;
//数値に確定
numTypeofNumber = parseInt(numGetNumber);
//デフォルト値のままだったら
if (numGetNumber == 999) {
  this.getField("numNumber3Digits").fillColor = color.red;
  this.getField("numNumber3Digits").strokeColor = color.red;
//数値以外なら
}else if (!(typeof numTypeofNumber === "number")){
  this.getField("numNumber3Digits").fillColor = color.red;
  this.getField("numNumber3Digits").strokeColor = color.red;
//文字数が3桁あれば
} else if (/^\d{3}$/.test(numGetNumber.toString())) {
  this.getField("numNumber3Digits").fillColor = color.transparent;
  this.getField("numNumber3Digits").strokeColor = color.black;
//それ以外なら
} else {
  this.getField("numNumber3Digits").fillColor = color.red;
  this.getField("numNumber3Digits").strokeColor = color.red;
}

|

[開発用]フォームの名前をフォームの値に入れる

これを
Screencapture-20230423-122023
こうします
Screencapture-20230423-122011

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

tell application id "com.adobe.Reader"
  tell active doc
    ###フィールドの数を数えて
    do script "var numFieldCnt = this.numFields;"
    set numFieldCnt to (do script "this.numFields;") as integer
    set numFieldCntJS to numFieldCnt
    ####フィールドの数だけ繰り返し
    repeat numFieldCnt times
      set numFieldCntJS to numFieldCntJS - 1 as integer
      ####名前を取得して
      do script "var strFieldName = this.getNthFieldName(" & numFieldCntJS & ");"
      set strFieldName to (do script "this.getNthFieldName(" & numFieldCntJS & ");") as text
      ####リードオンリーを解除して
      do script "this.getField(\"" & strFieldName & "\").readonly = false;"
      ###値を入れる
      do script " this.getField(strFieldName).value = strFieldName;"
    end repeat
  end tell
end tell


|

[Form]フォームの内容を読取専用にする

読取専用へ

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use scripting additions


property refMe : a reference to current application

set listFormName to {} as list


##################################
#### 文書を開いているか?
##################################
tell application id "com.adobe.Reader"
  ###PROで利用したい場合はこちら
  ##tell application id "com.adobe.Acrobat.Pro"
  activate
  tell active doc
    ###javascript無効になっているとここでエラーになる
    set numAllPage to do script ("this.numPages;")
    set numNowPage to do script ("this.pageNum;")
    try
      if numAllPage is "undefined" then
        error number -1708
      end if
    on error
      display alert "エラー:文書が選択されていません" buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 10
      return "エラー:文書が選択されていません"
    end try
  end tell
end tell
##################################
#### フォームの名称を取得してリストに
##################################
tell application id "com.adobe.Reader"
  ###PROで利用したい場合はこちら
  ##tell application id "com.adobe.Acrobat.Pro"
  tell active doc
    ###フィールドの数を数えて
    do script "var numFieldCnt = this.numFields;"
    set numFieldCnt to (do script "this.numFields;") as integer
    set numFieldCntJS to numFieldCnt
    ####フィールドの数だけ繰り返し
    repeat numFieldCnt times
      set numFieldCntJS to numFieldCntJS - 1 as integer
      ####名前を取得して
      do script "var strFildTitle = this.getNthFieldName(" & numFieldCntJS & ");"
      set strFieldName to (do script "this.getNthFieldName(" & numFieldCntJS & ");") as text
      ######フォームの内容をAppleScriptに渡す
      set strFormValue to (do script "this.getField(strFildTitle).value;") as text
      ####タブ区切りに値を整形して
      set listFormNameAndValue to ("" & strFieldName & "\t" & strFormValue & "") as text
      ###リストに追加する
      copy listFormNameAndValue to end of listFormName
    end repeat
  end tell
end tell

##################################
#### ダイアログ
##################################
###ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
  end tell
else
  tell current application
    activate
  end tell
end if

try
  tell current application
    activate
    set listResponse to (choose from list listFormName with title "選んでください" with prompt "選択した入力欄を読取専用に変更します" default items (item 1 of listFormName) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed) as list
  end tell
on error
  log "エラーしました"
  return "エラーしました"
  error "エラーしました" number -200
end try

if (item 1 of listResponse) is false then
  return "キャンセルしました"
  error "キャンセルしました" number -200
end if
##################################
#### 本処理
##################################

repeat with itemResponse in listResponse
  ###受け取った戻り値はタブ区切りなので
  set strFormNameAndValue to itemResponse as text
  set AppleScript's text item delimiters to "\t"
  set listFormNameAndValue to every text item of strFormNameAndValue
  set AppleScript's text item delimiters to ""
  set strFormName to item 1 of listFormNameAndValue
  
  tell application id "com.adobe.Reader"
    ###PROで利用したい場合はこちら
    ##tell application id "com.adobe.Acrobat.Pro"
    tell active doc
      ####リードオンリーにする
      do script "this.getField(\"" & strFormName & "\").readonly = true;"
    end tell
  end tell
end repeat




解除

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use scripting additions


property refMe : a reference to current application

set listFormName to {} as list


##################################
#### 文書を開いているか?
##################################
tell application id "com.adobe.Reader"
  ###PROで利用したい場合はこちら
  ##tell application id "com.adobe.Acrobat.Pro"
  activate
  tell active doc
    ###javascript無効になっているとここでエラーになる
    set numAllPage to do script ("this.numPages;")
    set numNowPage to do script ("this.pageNum;")
    try
      if numAllPage is "undefined" then
        error number -1708
      end if
    on error
      display alert "エラー:文書が選択されていません" buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 10
      return "エラー:文書が選択されていません"
    end try
  end tell
end tell
##################################
#### フォームの名称を取得してリストに
##################################
tell application id "com.adobe.Reader"
  ###PROで利用したい場合はこちら
  ##tell application id "com.adobe.Acrobat.Pro"
  tell active doc
    ###フィールドの数を数えて
    do script "var numFieldCnt = this.numFields;"
    set numFieldCnt to (do script "this.numFields;") as integer
    set numFieldCntJS to numFieldCnt
    ####フィールドの数だけ繰り返し
    repeat numFieldCnt times
      set numFieldCntJS to numFieldCntJS - 1 as integer
      ####名前を取得して
      do script "var strFildTitle = this.getNthFieldName(" & numFieldCntJS & ");"
      set strFieldName to (do script "this.getNthFieldName(" & numFieldCntJS & ");") as text
      ######フォームの内容をAppleScriptに渡す
      set strFormValue to (do script "this.getField(strFildTitle).value;") as text
      ####タブ区切りに値を整形して
      set listFormNameAndValue to ("" & strFieldName & "\t" & strFormValue & "") as text
      ###リストに追加する
      copy listFormNameAndValue to end of listFormName
    end repeat
  end tell
end tell

##################################
#### ダイアログ
##################################
###ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
  end tell
else
  tell current application
    activate
  end tell
end if

try
  tell current application
    activate
    set listResponse to (choose from list listFormName with title "選んでください" with prompt "選択した入力欄を読取専用に変更します" default items (item 1 of listFormName) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed) as list
  end tell
on error
  log "エラーしました"
  return "エラーしました"
  error "エラーしました" number -200
end try

if (item 1 of listResponse) is false then
  return "キャンセルしました"
  error "キャンセルしました" number -200
end if
##################################
#### 本処理
##################################

repeat with itemResponse in listResponse
  ###受け取った戻り値はタブ区切りなので
  set strFormNameAndValue to itemResponse as text
  set AppleScript's text item delimiters to "\t"
  set listFormNameAndValue to every text item of strFormNameAndValue
  set AppleScript's text item delimiters to ""
  set strFormName to item 1 of listFormNameAndValue
  
  tell application id "com.adobe.Reader"
    ###PROで利用したい場合はこちら
    ##tell application id "com.adobe.Acrobat.Pro"
    tell active doc
      ####リードオンリーを解除
      do script "this.getField(\"" & strFormName & "\").readonly = false;"
    end tell
  end tell
end repeat

|

[Form]リストの内容でPDFを作成して、回収後にデータ収集するまで

ダウンロード - 配布用PDF作成回収.zip

|

[Form]回収したPDFからフォームの内容を集計する

過去に作成したものの修正版
https://force4u.cocolog-nifty.com/skywalker/2021/09/post-1db92c.html

ダウンロード -回収PDFデータ収集.zip


【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#メニューバーの ▶︎ の右三角をクリックして実行してください↑
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

###################################
#####設定項目
###################################
##収集したデータの保存ファイル名
set strFileName to "PDFフォーム集計データ.txt" as text


###################################
#####入力フォルダ
###################################
###ダイアログのデフォルト
tell application "Finder"
  set aliasPathToMe to path to me as alias
  set aliasContainerPath to container of aliasPathToMe as alias
  #####回収したPDFフォームを集めてあるフォルダ名
  set aliasDefaultLocation to (folder "回収PDFサンプル" of folder aliasContainerPath) as alias
end tell
#####空のテキストファイルを作っておく
tell application "Finder"
  try
    make new file at aliasContainerPath with properties {name:(strFileName)}
  end try
end tell

##################################################
#####回収PDFのパス関連
##################################################

###ダイアログテキスト
set strPromptText to "回収したPDFフォルダを選んでください"
try
  set listResponse to (choose folder strPromptText with prompt strPromptText default location aliasDefaultLocation without multiple selections allowed, invisibles and showing package contents) as list
on error
  log "エラーしました"
  return
end try
###フォルダーのパス関連
set aliasDirPath to (item 1 of listResponse) as alias
set strDirPath to POSIX path of aliasDirPath as text
set ocidDirPathStr to refMe's NSString's stringWithString:strDirPath
set ocidDirPath to ocidDirPathStr's stringByStandardizingPath
set ocidDirPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidDirPath isDirectory:true

###フォルダに内包されているコンテンツ
set listArray to {(refMe's NSURLIsDirectoryKey), (refMe's NSURLIsRegularFileKey), (refMe's NSURLPathKey)}
set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
set listFilePathArray to appFileManager's contentsOfDirectoryAtURL:ocidDirPathURL includingPropertiesForKeys:listArray options:ocidOption |error|:(reference)
set ocidFilePathArray to item 1 of listFilePathArray

###パス格納用のリスト
set ocidPathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
###URLリストをパスリストにして(ディレクトリ等を除く処理)
repeat with itemFilePath in ocidFilePathArray
  set boolIsRegFile to (item 2 of (itemFilePath's getResourceValue:(reference) forKey:(refMe's NSURLIsRegularFileKey) |error|:(reference))) as boolean
  set boolIsDir to (item 2 of (itemFilePath's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference))) as boolean
  if boolIsDir is false then
    if boolIsRegFile is true then
      set ocidFilePath to item 2 of (itemFilePath's getResourceValue:(reference) forKey:(refMe's NSURLPathKey) |error|:(reference))
      (ocidPathArray's addObject:ocidFilePath)
    end if
  end if
end repeat
#####(同じフォルダ内だから)ファイル名順にソート
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:"self" ascending:true selector:"localizedStandardCompare:"
set ocidSortedPathList to (ocidPathArray's sortedArrayUsingDescriptors:{ocidDescriptor})
##################################################
#####準備
##################################################
###########################
####acrobat起動
tell application id "com.adobe.Acrobat.Pro"
  launch
end tell
###########################
####起動チェック
tell application id "com.adobe.Acrobat.Pro"
  ####起動確認最大5秒
  repeat 5 times
    activate
    set boolFrontmost to frontmost as boolean
    if boolFrontmost is true then
      exit repeat
    end if
    delay 1
  end repeat
end tell

##################################################
#####本処理
##################################################
####出力用テキストの初期化
set strOutPutTextTab to "" as text

###ファイルの数だけ繰り返し
repeat with itemSortedPath in ocidSortedPathList
  set strFilePath to itemSortedPath as text
  ####ファイルを開く
  tell application id "com.adobe.Acrobat.Pro"
    try
      do script "app.openDoc(\"" & strFilePath & "\");"
    on error
      open file (POSIX file strFilePath as alias)
    end try
  end tell
  ####開いたファイルのフォーム情報を取得する
  tell application id "com.adobe.Acrobat.Pro"
    ###フォームの数を数える
    do script "var numCntFild = this.numFields"
    ###AppleScript用にテキストにして戻す
    set numCntFild to (do script "numCntFild") as text
  end tell
  set numCntChkFild to 0 as integer
  repeat numCntFild times
    tell application id "com.adobe.Acrobat.Pro"
      ######順番にフォーム名を取得
      do script "var strFildTitle = this.getNthFieldName(" & numCntChkFild & ")"
      ######フォームの内容を取得
      do script "var strFormValeText = this.getField(strFildTitle).value;"
      ######フォームの内容をAppleScriptに渡す
      set strFormValue to (do script "this.getField(strFildTitle).value;") as text
    end tell
    ###改行除去
    set strFormValue to doReplace(strFormValue, "\r", "")
    set strFormValue to doReplace(strFormValue, "\n", "")
    ######フォーム毎にタブ区切りテキストにする
    set strOutPutTextTab to strOutPutTextTab & strFormValue & "\t" as text
    set numCntChkFild to numCntChkFild + 1 as integer
  end repeat
  ####1ファイル毎に改行を入れる
  set strOutPutTextTab to strOutPutTextTab & "\n" as text
  
  ####開いたファイルを閉じる
  tell application id "com.adobe.Acrobat.Pro"
    do script "closeDoc(false);"
  end tell
end repeat

log strOutPutTextTab

####結果テキスト
tell application "Finder"
  set aliasFilePath to (file strFileName of folder aliasContainerPath) as alias
end tell
tell application "TextEdit"
  activate
  set objAvtivDoc to open file aliasFilePath
  tell objAvtivDoc
    activate
    set its text to strOutPutTextTab
    save in aliasFilePath
  end tell
end tell

####文字の置き換え
to doReplace(argOrignalText, argSearchText, argReplaceText)
  set strDelim to AppleScript's text item delimiters
  set AppleScript's text item delimiters to argSearchText
  set listDelim to every text item of argOrignalText
  set AppleScript's text item delimiters to argReplaceText
  set strReturn to listDelim as text
  set AppleScript's text item delimiters to strDelim
  return strReturn
end doReplace

|

より以前の記事一覧

その他のカテゴリー

Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager Apple AppleScript AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Audio AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Diff AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript Droplet AppleScript eMail AppleScript Encode % AppleScript Encode Decode AppleScript Encode UTF8 AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript Guide AppleScript HTML AppleScript HTML Entity AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim AppleScript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript Leading Zero AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript Mail AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Messages AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSArray Sort AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFileManager enumeratorAtURL AppleScript NSFont AppleScript NSFontManager AppleScript NSGraphicsContext AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSpoint AppleScript NSPredicate AppleScript NSPrintOperation AppleScript NSRange AppleScript NSRect AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSURLSession AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotation AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFImageRep AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photoshop AppleScript Pictures AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript Swift AppleScript System Events AppleScript System Events Plist AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text MD AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML savedSearch AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript XMP AppleScript YouTube Applications CityCode github iPhone List lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom Windows zoom