|
楼主 |
发表于 2024-7-11 21:00
来自手机
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 lss001 于 2024-7-12 05:20 编辑
Sub InsertImages() '添加图片
Dim pdfFile$, PDFoutputFile$, imageFile$
Dim jso As Object, pageRect As Variant
Dim pageField As Object, page As Long
Dim fieldRect(0 To 3) As Double
Set AcroApp = CreateObject("AcroExch.App")
Set AcroAVDoc = CreateObject("AcroExch.AVDoc")
Set AcroPDDoc = CreateObject("AcroExch.PDDoc")
pdfFile = ThisWorkbook.Path & "\num.pdf"
imageFile = ThisWorkbook.Path & "\123.gif"
PDFoutputFile = Replace(pdfFile, ".pdf", "newnum.pdf")
If AcroAVDoc.Open(pdfFile, "") Then
Set AcroPDDoc = AcroAVDoc.GetPDDoc()
Set jso = AcroPDDoc.GetJSObject
For page = 0 To AcroPDDoc.GetNumPages() - 1
pageRect = jso.getPageBox("Crop", page)
fieldRect(0) = 0
fieldRect(1) = 135
fieldRect(2) = 240
fieldRect(3) = 0
Set pageField = jso.addField( _
"button" & page + 1, "button", page, fieldRect)
pageField.buttonImportIcon imageFile
pageField.buttonPosition = jso.Position.iconOnly
pageField.ReadOnly = True
Next
AcroPDDoc.Save 1, PDFoutputFile
AcroAVDoc.Close True
End If
Set AcroPDDoc = Nothing
Set AcroAVDoc = Nothing
Set AcrobatApp = Nothing
End Sub |
|