「PDFのフィールドに値を入力した後、読み取り専用にするにはどうしたら良いか?」、という質問を頂きました。
フィールドを操作するマクロについては、何年か前に記事を書いています。
Acrobat JavaScriptのFieldオブジェクトには、そのものズバリの「readonly」プロパティが用意されているので、上記記事のコードのようにGetJSObjectメソッド経由で設定できます。
'Acrobat JavaScriptでフィールド操作
Public Sub Sample()
Dim app As Object
Dim avdoc As Object
Const PDSaveFull = &H1
Const PdfFilePath As String = "C:\Test\PDF\入力フォームサンプル.pdf" 'PDFファイルのパス
Set app = CreateObject("AcroExch.App")
Set avdoc = CreateObject("AcroExch.AVDoc")
If avdoc.Open(PdfFilePath, "") = True Then
app.Show 'Acrobat表示
With avdoc.GetPDDoc.GetJSObject
.getField("氏名").Value = "手巣都 花子"
With .getField("年齢")
.Value = "25"
.ReadOnly = True '「年齢」フィールドだけ読み取り専用に設定
End With
.getField("連絡先").Value = "XXX-XXXX-XXXX"
End With
avdoc.GetPDDoc.Save PDSaveFull, "C:\Test\PDF\(入力済み)入力フォームサンプル.pdf" '別名保存
avdoc.Close 1 '文書を保存せずに閉じる
app.Hide: app.Exit
End If
End Sub
あるいは下記のようにAFormAppオブジェクト経由で処理することもできます。
'AFormAppオブジェクトでフィールド操作
Public Sub Sample2()
Dim app As Object
Dim avdoc As Object
Const PDSaveFull = &H1
Const PdfFilePath As String = "C:\Test\PDF\入力フォームサンプル.pdf" 'PDFファイルのパス
Set app = CreateObject("AcroExch.App")
Set avdoc = CreateObject("AcroExch.AVDoc")
If avdoc.Open(PdfFilePath, "") = True Then
app.Show 'Acrobat表示
With CreateObject("AFormAut.App") 'AFORMAUTLib.AFormApp
With .Fields
.Item("氏名").Value = "手巣都 花子"
With .Item("年齢")
.Value = "25"
.IsReadOnly = True
End With
.Item("連絡先").Value = "XXX-XXXX-XXXX"
End With
End With
avdoc.GetPDDoc.Save PDSaveFull, "C:\Test\PDF\(入力済み)入力フォームサンプル.pdf" '別名保存
avdoc.Close 1 '文書を保存せずに閉じる
app.Hide: app.Exit
End If
End Sub



















この記事へのコメントはありません。