注釈でテキストボックスと長方形を追加 (AddNewAnnot)
- PDFを開いたウィンドウを表示させた状態でマクロを実行してください
- 参照設定が必要です
Option Explicit
Public Sub Main()
Dim avApp As Acrobat.AcroApp
Dim avDoc As Acrobat.AcroAVDoc
Dim pdDoc As Acrobat.AcroPDDoc
Dim pdPage As Acrobat.AcroPDPage
Dim pdAnnot As Acrobat.AcroPDAnnot
Dim rect As Acrobat.AcroRect
Dim pageNum As Long
On Error GoTo ErrorHandler
Set avApp = VBA.Interaction.CreateObject(Class:="AcroExch.App")
Set avDoc = avApp.GetActiveDoc()
Set pdDoc = avDoc.GetPDDoc()
pageNum = avDoc.GetAVPageView().GetPageNum()
Set pdPage = pdDoc.AcquirePage(nPage:=pageNum)
Set rect = New Acrobat.AcroRect
rect.Left = 10 * 72 / 25.4
rect.bottom = 20 * 72 / 25.4
rect.Right = 100 * 72 / 25.4
rect.Top = 50 * 72 / 25.4
Set pdAnnot = pdPage.AddNewAnnot(-1, "FreeText", rect)
pdAnnot.SetColor &H80C0FF
pdAnnot.SetTitle "プロパティ 一般タブ 作成者 FreeText"
pdAnnot.SetContents "テキストボックス注釈"
rect.Left = 10 * 72 / 25.4
rect.bottom = 70 * 72 / 25.4
rect.Right = 150 * 72 / 25.4
rect.Top = 100 * 72 / 25.4
Set pdAnnot = pdPage.AddNewAnnot(-1, "Square", rect)
pdAnnot.SetColor &HFFC080
pdAnnot.SetTitle "プロパティ 一般タブ 作成者 Square"
pdAnnot.SetContents ""
ErrorHandler:
Set rect = Nothing
Set pdAnnot = Nothing
Set pdPage = Nothing
Set pdDoc = Nothing
Set avDoc = Nothing
Set avApp = Nothing
Debug.Print VBA.Conversion.Error(VBA.Information.Err.Number)
End Sub
フラット化 (flattenPages)
- PDFを開いたウィンドウを表示させた状態でマクロを実行してください
Option Explicit
Public Sub PdfFlattenPage()
#Const DEBUG_ = False
#If DEBUG_ Then
Dim avApp As Acrobat.AcroApp
Dim avDoc As Acrobat.AcroAVDoc
#Else
Dim avApp As Object
Dim avDoc As Object
#End If
Dim jso As Object
Dim pageNum As Long
On Error GoTo ErrorHandler
Set avApp = VBA.Interaction.CreateObject(Class:="AcroExch.App")
Set avDoc = avApp.GetActiveDoc()
Set jso = avDoc.GetPDDoc().GetJSObject()
pageNum = avDoc.GetAVPageView().GetPageNum()
jso.syncAnnotScan
jso.flattenPages pageNum
ErrorHandler:
Set jso = Nothing
Set avDoc = Nothing
Set avApp = Nothing
Debug.Print VBA.Conversion.Error(VBA.Information.Err.Number)
End Sub