打开 adobe pdf 并通过添加文本框来编辑页面
Open adode pdf and edit a page by adding a text box
我对使用 adobe 进行 vba 编码还很陌生,无法使用任何代码。我首先需要打开位于我的文档中的 pdf(使用 adobe acrobat),然后通过添加 textbox/or 多个文本框来编辑第 5 页。我想知道这是否可行,是否有代码可以做到这一点。我有 Adobe Acrobat XI Standard,它允许我手动编辑 pdf 并在需要的地方创建文本框。
任何帮助将不胜感激。
谢谢
vba/vbs 中有多种与 acrobat 通信的方法(参见 Acrobat SDK/IAC 部分)。但对我来说,最好的方法是使用 Acrobat Form API,它可以或多或少地直接使用 js 代码。
下面是一个 vbs/vba 示例,说明如何在第一页上添加文本(从零开始:第一页 = 0)。
请查找更多方法和属性,尤其是在 "Acrobat JavaScript API Reference" 处定义矩形(place/array 以设置方框)。
祝你好运,莱因哈特
Path = "D:\Test.pdf"
Set App = CreateObject("Acroexch.app")
app.show
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set AForm = CreateObject("AFormAut.App") 'from AFormAPI
If AVDoc.Open(Path,"") Then
'// write some js code on a vbs variable
js = "f = this.addField(""newField"", ""text"", 0, [250,650,20,600]);" &vblf _
& "f.value = ""any Text""; " &vblf _
& "f.flatten"
'//execute the js code
AForm.Fields.ExecuteThisJavaScript js
end if
Set AForm = Nothing
Set AVDoc = Nothing
Set APP = Nothing
在浏览了有关 OLE 自动化的 adobes 文档和 API 参考资料后,我发现您实际上可以使用 acrobat 在 VBA 中很好地编码。享受并适应您的需求。这是一个 link 到 adobe 的 API 参考:http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/iac_api_reference.pdf
Sub RMS_pdf()
Application.DisplayAlerts = False
Application.CutCopyMode = False
Set wb1 = Workbooks.Open(Filename:="\ldnfortunenet\fortunenetdocuments\William Hadman\Suitability\RMS\RMS Product Governance Reports\" & LongNewDate & "\RMS Product Governance Report.xlsm", UpdateLinks:=True)
Set ws1 = wb1.Sheets("Performance & Volatility")
Set ws2 = wb1.Sheets("Asset Allocation")
Set ws3 = wb1.Sheets("Detailed Contribution")
OpenPath = "\ldnfortunenet\fortunenetdocuments\William Hadman\Aushir Shah\RMS Product Governance Reports\RMS Product Governance Report - 2016-10-31 - CDF Direct Diversified Income.pdf"
SavePath = "\ldnfortunenet\fortunenetdocuments\William Hadman\Aushir Shah\RMS Product Governance Reports\RMS Product Governance Report - 2016-10-31 - CDF Direct Diversified Income v2.pdf"
'initialize the Acrobat interface
Set AcroApp = CreateObject("AcroExch.App")
Set gpdDoc = CreateObject("AcroExch.PDDoc")
'open the file
If gpdDoc.Open(OpenPath) Then
Set jso = gpdDoc.GetJSObject
End If
'get at the jso
If Not jso Is Nothing Then
If gpdDoc.Open(dest) Then
Set jso = gpdDoc.GetJSObject
End If
LastPage = gpdDoc.GetNumPages - 1
Set Box1 = jso.AddField("Performance Comment - " & StrategyName(4), "text", LastPage, Array(583.8, 706.32, 224.7, 583.2))
Box1.TextFont = "Helvetica"
Box1.TextSize = 8
Else
End If
If gpdDoc.Save(PDSaveFull, SavePath) = False Then
MsgBox "Unable to save image"
Else
End If
我对使用 adobe 进行 vba 编码还很陌生,无法使用任何代码。我首先需要打开位于我的文档中的 pdf(使用 adobe acrobat),然后通过添加 textbox/or 多个文本框来编辑第 5 页。我想知道这是否可行,是否有代码可以做到这一点。我有 Adobe Acrobat XI Standard,它允许我手动编辑 pdf 并在需要的地方创建文本框。 任何帮助将不胜感激。
谢谢
vba/vbs 中有多种与 acrobat 通信的方法(参见 Acrobat SDK/IAC 部分)。但对我来说,最好的方法是使用 Acrobat Form API,它可以或多或少地直接使用 js 代码。
下面是一个 vbs/vba 示例,说明如何在第一页上添加文本(从零开始:第一页 = 0)。
请查找更多方法和属性,尤其是在 "Acrobat JavaScript API Reference" 处定义矩形(place/array 以设置方框)。 祝你好运,莱因哈特
Path = "D:\Test.pdf"
Set App = CreateObject("Acroexch.app")
app.show
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set AForm = CreateObject("AFormAut.App") 'from AFormAPI
If AVDoc.Open(Path,"") Then
'// write some js code on a vbs variable
js = "f = this.addField(""newField"", ""text"", 0, [250,650,20,600]);" &vblf _
& "f.value = ""any Text""; " &vblf _
& "f.flatten"
'//execute the js code
AForm.Fields.ExecuteThisJavaScript js
end if
Set AForm = Nothing
Set AVDoc = Nothing
Set APP = Nothing
在浏览了有关 OLE 自动化的 adobes 文档和 API 参考资料后,我发现您实际上可以使用 acrobat 在 VBA 中很好地编码。享受并适应您的需求。这是一个 link 到 adobe 的 API 参考:http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/iac_api_reference.pdf
Sub RMS_pdf()
Application.DisplayAlerts = False
Application.CutCopyMode = False
Set wb1 = Workbooks.Open(Filename:="\ldnfortunenet\fortunenetdocuments\William Hadman\Suitability\RMS\RMS Product Governance Reports\" & LongNewDate & "\RMS Product Governance Report.xlsm", UpdateLinks:=True)
Set ws1 = wb1.Sheets("Performance & Volatility")
Set ws2 = wb1.Sheets("Asset Allocation")
Set ws3 = wb1.Sheets("Detailed Contribution")
OpenPath = "\ldnfortunenet\fortunenetdocuments\William Hadman\Aushir Shah\RMS Product Governance Reports\RMS Product Governance Report - 2016-10-31 - CDF Direct Diversified Income.pdf"
SavePath = "\ldnfortunenet\fortunenetdocuments\William Hadman\Aushir Shah\RMS Product Governance Reports\RMS Product Governance Report - 2016-10-31 - CDF Direct Diversified Income v2.pdf"
'initialize the Acrobat interface
Set AcroApp = CreateObject("AcroExch.App")
Set gpdDoc = CreateObject("AcroExch.PDDoc")
'open the file
If gpdDoc.Open(OpenPath) Then
Set jso = gpdDoc.GetJSObject
End If
'get at the jso
If Not jso Is Nothing Then
If gpdDoc.Open(dest) Then
Set jso = gpdDoc.GetJSObject
End If
LastPage = gpdDoc.GetNumPages - 1
Set Box1 = jso.AddField("Performance Comment - " & StrategyName(4), "text", LastPage, Array(583.8, 706.32, 224.7, 583.2))
Box1.TextFont = "Helvetica"
Box1.TextSize = 8
Else
End If
If gpdDoc.Save(PDSaveFull, SavePath) = False Then
MsgBox "Unable to save image"
Else
End If