【发布时间】:2018-06-20 07:12:34
【问题描述】:
我编写了一段代码,用于裁剪 pdf 页面,然后使用 Adobe Acrobat 10.0 Type Library for 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")
我对这个库一点也不满意(代码来自我在互联网上找到的代码片段)所以我可能写了一些错误的行(但它最初有效)。 非常感谢您的帮助!
【问题讨论】:
-
请注意,
Dim nameFile, s, exportCroppedPDF As String只会将最后一个变量定义为String,而前 2 个变量仍为Variant类型。您必须为 每个 变量声明一个类型:Dim nameFile As String, s As String, exportCroppedPDF As String. -
@Peh 哦,我不知道,谢谢提供信息