我写了一段代码,裁剪了pdf页面,然后使用Adobe Acrobat 10.0 Excel VBA类型库将页面重新插入到全局pdf中。 该代码在我的计算机上可以正常工作,但是在我的一位同事身上收获过多。我认为它可能来自分辨率(我的分辨率为1440x900,我的同事为1600x900),但我只是看不到分辨率可能会干扰代码的位置。
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")
对于这个库,我一点都不放心(代码来自我在Internet上找到的代码段),所以我可能写错了一些代码(但起初是可以的)。 非常感谢您的帮助!
答案 0 :(得分:0)
根据文档CropPages
有4个参数,其中acroRect
应该是最后一个。
returnValue = Object.CropPages( nStartPage, nEndPage, nEvenOrOddPagesOnly, acroRect )
参数:
nStartPage
:裁剪的第一页。 PDDoc对象的第一页是 第0页。nEndPage
:裁剪的最后一页。nEvenOrOddPagesOnly
表示该范围中哪些页面被裁剪的值。一定是 以下之一:
0
表示裁剪范围内的所有页面1
表示仅裁剪该范围内的奇数页2
意味着仅裁剪该范围内的偶数页面acroRect
一个AcroExch.Rect
,指定裁剪矩形,即 在用户空间中指定。