我编写了一段代码,对pdf页面进行裁剪,然后使用AdobeAcrobat10.0类型库为Excel重新插入此页面到全局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")
我对这个库一点也不累加(代码来自我在互联网上找到的代码),所以我可能写错了一些行(但它一开始就起作用了)。非常感谢你的帮助!
发布于 2018-06-19 23:30:09
根据文档,CropPages
有4个参数,其中acroRect
应该是最后一个参数。
returnValue = Object.CropPages( nStartPage,nEndPage,nEvenOrOddPagesOnly,acroRect ) 参数:
nStartPage
:裁剪的第一页。PDDoc对象的第一个页面是页0。nEndPage
:裁剪的最后一页。nEvenOrOddPagesOnly
值,指示将裁剪范围中的哪些页。必须是下列之一:0
意味着裁剪范围内的所有页面1
意味着仅裁剪范围内的奇数页。2
意味着仅在范围内裁剪甚至页面。
acroRect
指定在用户空间中指定的裁剪矩形的AcroExch.Rect
。https://stackoverflow.com/questions/50942314
复制相似问题