打开adode pdf并通过添加文本框来编辑页面

时间:2016-11-04 12:21:11

标签: vba excel-vba adobe acrobat excel

我对adobe的vba编码很新,无法获得任何代码。我首先需要打开我文档中的pdf(使用adobe acrobat),然后通过添加文本框/或多个文本框来编辑第5页。我想知道这是否可行,是否有代码可以做到这一点。我有Adobe Acrobat XI Standard,它允许我手动编辑pdf并在需要时创建文本框。 任何帮助将不胜感激。

由于

2 个答案:

答案 0 :(得分:3)

有几种方法可以从vba / vbs与acrobat进行通信(请参阅Acrobat SDK / IAC部分)。但对我来说,最好是使用Acrobat Form API,它允许使用js-code更直接地工作。

下面你将找到一个vbs / vba示例,如何在第一页上添加文本(基于零:第一页= 0)。

请查看更多方法和属性,尤其是在“Acrobat JavaScript API Reference”中定义rect(放置框的位置/数组)。 祝你好运,莱因哈德

con.Open()
cmd.CommandText = "select * from stud where studentno = 'mnb'"
cmd.Connection = con
dr = cmd.ExecuteReader()

While dr.Read()

    studnum.Text = dr.Item("studentno")
    fname.Text = dr.Item("fname")
    mname.Text = dr.Item("mname")
    lname.Text = dr.Item("lname")
    gender.Text = dr.Item("gender")
    section.Text = dr.Item("seccode")
    bday.Text = dr.Item("bday")
    phone.Text = dr.Item("phoneno")
    address.Text = dr.Item("maddress")

    Dim imageData As Byte() = DirectCast(dr("pic"), Byte())
    If Not imageData Is Nothing Then
        Using ms As New MemoryStream(imageData, 0, imageData.Length)
            ms.Write(imageData, 0, imageData.Length)
            PictureBox1.BackgroundImage = Image.FromStream(ms, True)
        End Using
    End If

End While

答案 1 :(得分:2)

在浏览了有关OLE自动化和API引用的adobes文档后,我发现您可以使用acrobat在VBA中实际编写得非常好。享受并适应您的需求。以下是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