|
本帖最后由 xiao99hui 于 2023-2-25 11:14 编辑
Sub AddImageToPDF()
' 定义变量
Dim avDoc As New AcroAVDoc
Dim pdDoc As AcroPDDoc
Dim pageNum As Integer
Dim acroPage As AcroPDPage
Dim img As AcroPDXObject
Dim rect As AcroRect
Dim annot As AcroPDAnnot
' 打开PDF文件
If avDoc.Open("C:\example.pdf", "") Then
Set pdDoc = avDoc.GetPDDoc()
End If
' 获取PDF指定页码
pageNum = 1 ' 指定要添加图片的页码
Set acroPage = pdDoc.AcquirePage(pageNum)
' 加载图片
Set img = CreateObject("AcroExch.PDXObject")
img.CreateFromFile("C:\example.jpg")
' 在PDF中添加图片
Set rect = CreateObject("AcroExch.Rect")
rect.Top = 100
rect.Left = 100
rect.Bottom = 200
rect.Right = 200
Set annot = acroPage.Annots.Add("Stamp", rect)
annot.Icon = img
annot.Author = "John Doe"
' 保存和关闭PDF文件
pdDoc.Save 1, "C:\example_modified.pdf"
pdDoc.Close
' 释放对象
Set annot = Nothing
Set rect = Nothing
Set img = Nothing
Set acroPage = Nothing
Set pdDoc = Nothing
Set avDoc = Nothing
End Sub
是不是缺少什么插件?还是代码本事有问题?求解答
|
|