I wrote a piece of code that crops a pdf page and then re-insert this page in the global pdf using the Adobe Acrobat 10.0 Type Library for Excel VBA. The code works fine on my computer but crops too much on the one of my co-worker. I think it might come from the resolution (1440x900 for mine, 1600x900 for my co-worker) but I just don't see where the resolution might interfer in the code.
Dim acroRect, jso, page As Object
Dim pdf1 As Acrobat.CAcroPDDoc
Dim nameFile, s, exportCroppedPDF As String
Set acroRect = CreateObject("AcroExch.Rect")
Set pdf1 = CreateObject("AcroExch.PDDoc")
nameFile = "namefile.pdf"
If pdf1.Open(nameFile) Then
Set jso = pdf1.GetJSObject
Set page = pdf1.AcquirePage(pdf1.GetNumPages() - 1)
'These values were found from some tests I did, there is no logic behind them
acroRect.bottom = 22
acroRect.Left = 35
acroRect.Right = 785
acroRect.Top = 589
page.CropPage (acroRect)
exportCroppedPDF = "pathAndNamefile.pdf"
s = jso.extractPages(0, pdf1.GetNumPages() - 1, exportCroppedPDF)
Else
Debug.Print ("Can't open the file!")
End If
pdf1.Close
Set pdf1 = Nothing
Set acroRect = Nothing
Set jso = Nothing
Set page = Nothing
Debug.Print ("Crop successful")
I am not cumfortable at all with this library (the code comes from pieces of code I found on the Internet) so I might have wrote some wrong lines (but it initialy works). Thanks a lot for your help!