Public Sub Insert_Images_In_PDF()
Dim PDFinputFile As String
Dim PDFoutputFile As String
Dim imageFile As String
Dim i As Integer
Dim AcrobatApp As Acrobat.AcroApp
Dim AcroAVDocInput As Acrobat.AcroAVDoc
Dim AcroPDDocInput As Acrobat.AcroPDDoc
Dim jso As Object
Dim pageRect As Variant
Dim pageField As Object
Dim fieldRect(0 To 3) As Double
Dim page As Long
Set targetWorkbook = ThisWorkbook
Set rh = targetWorkbook.Sheets("RCT")
Set sh = targetWorkbook.Sheets("Stamper")
lastrowA = rh.Cells(sh.Rows.Count, "A").End(xlUp).Row
lastrowI = rh.Cells(sh.Rows.Count, "I").End(xlUp).Row
For i = lastrowA - (lastrowA - lastrowI - 1) To rh.Range("A" & Application.Rows.Count).End(xlUp).Row
PDFinputFile = "S:\01 PV\02 Proffesion\02 Engineering & QC\Rev_1 - Acrobat PRO - Multi\01 Drawings - Projects\" & rh.Range("F" & i).Value & ".pdf"
imageFile = "S:\01 PV\02 Proffesion\02 Engineering & QC\Rev_1 - Acrobat PRO - Multi\02 Signatures\" & rh.Range("F" & i).Value & " " & "x" & " " & rh.Range("D" & i).Value & ".png"
PDFoutputFile = "S:\01 PV\02 Proffesion\02 Engineering & QC\Rev_1 - Acrobat PRO - Multi\03 Signed Drawings\" & rh.Range("F" & i).Value & " " & "x" & " " & rh.Range("D" & i).Value & ".pdf"
Set AcrobatApp = New Acrobat.AcroApp
Set AcroAVDocInput = New Acrobat.AcroAVDoc
If AcroAVDocInput.Open(PDFinputFile, "") Then
Set AcroPDDocInput = AcroAVDocInput.GetPDDoc()
Set jso = AcroPDDocInput.GetJSObject
For page = 0 To AcroPDDocInput.GetNumPages() - 1
pageRect = jso.getPageBox("Crop", page)
fieldRect(0) = 30
fieldRect(1) = 120
fieldRect(2) = 150
fieldRect(3) = 10
Set pageField = jso.addField("button" & page + 1, "button", page, fieldRect)
On Error Resume Next
pageField.buttonImportIcon imageFile
On Error GoTo 0
pageField.buttonPosition = jso.Position.iconOnly
pageField.ReadOnly = True
Next
AcroPDDocInput.Save 1, PDFoutputFile
AcroAVDocInput.Close True
Else
MsgBox "Unable to open PDF input file" & vbCrLf & PDFinputFile
End If
rh.Range("I" & i).Value = 1
Next i
Set AcroPDDocInput = Nothing
Set AcroAVDocInput = Nothing
Set AcrobatApp = Nothing
End Sub
Public Sub Insert_Images_In_PDF2()
Dim PDFFolder As String
Dim PDFiFile As String
Dim PDFoFile As String
Dim ImageFile As String
Dim i As Integer
Dim AcrobatApp As Acrobat.AcroApp
Dim AcroAVDocInput As Acrobat.AcroAVDoc
Dim AcroPDDocInput As Acrobat.AcroPDDoc
Dim jso As Object
Dim pageRect As Variant
Dim pageField As Object
Dim fieldRect(0 To 3) As Double
Dim page As Long
Set targetWorkbook = ThisWorkbook
Set rh = targetWorkbook.Sheets("RCT")
Set sh = targetWorkbook.Sheets("Stamper")
lastrowA = rh.Cells(sh.Rows.Count, "A").End(xlUp).Row
lastrowI = rh.Cells(sh.Rows.Count, "I").End(xlUp).Row
For i = lastrowA - (lastrowA - lastrowI - 1) To rh.Range("A" & Application.Rows.Count).End(xlUp).Row
PDFFolder = "S:\01 PV\02 Proffesion\02 Engineering & QC\Rev_2 - Acrobat PRO - Multi\01 Drawings\" & rh.Range("F" & i).Value & "\"
PDFiFile = Dir(PDFFolder & "*.pdf")
ImageFile = "S:\01 PV\02 Proffesion\02 Engineering & QC\Rev_2 - Acrobat PRO - Multi\02 Signatures\" & rh.Range("D" & i).Value & ".png"
PDFoFile = "S:\01 PV\02 Proffesion\02 Engineering & QC\Rev_2 - Acrobat PRO - Multi\03 Signed Drawings\" & rh.Range("D" & i).Value & "\"
Set AcrobatApp = New Acrobat.AcroApp
Set AcroAVDocInput = New Acrobat.AcroAVDoc
If AcroAVDocInput.Open(PDFiFile, "") Then
Set AcroPDDocInput = AcroAVDocInput.GetPDDoc()
Set jso = AcroPDDocInput.GetJSObject
For page = 0 To AcroPDDocInput.GetNumPages() - 1
pageRect = jso.getPageBox("Crop", page)
fieldRect(0) = 20
fieldRect(1) = 120
fieldRect(2) = 100
fieldRect(3) = 10
Set pageField = jso.addField("button" & page + 1, "button", page, fieldRect)
On Error Resume Next
pageField.buttonImportIcon ImageFile
On Error GoTo 0
pageField.buttonPosition = jso.Position.iconOnly
pageField.ReadOnly = True
Next
AcroPDDocInput.Save 1, PDFoFile
AcroAVDocInput.Close True
Else
MsgBox "Unable to open PDF input file" & vbCrLf & PDFiFile
End If
rh.Range("I" & i).Value = 1
Next i
Set AcroPDDocInput = Nothing
Set AcroAVDocInput = Nothing
Set AcrobatApp = Nothing
End Sub