|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 bluesky_0 于 2024-4-10 12:39 编辑
原帖在这里
https://club.excelhome.net/thread-1561115-1-1.html
封装函数源代码如下:
- Public Function CroppedPDF_standard(nameFile As String, W_Left As Long, W_Right As Long, L_Top As Long, L_bottom As Long, outputPath As String) As String
- '根据特定数值裁剪PDF页面
- 'nameFile 文件地址和名称,
- 'W_Left,W_Right PDF宽度方向的裁剪
- 'L_Top,L_bottom PDF长度方向的裁剪
- 'outputPath 裁剪后的文件存放地址和文件名
- Dim acroRect, jso As Object
- Dim pdf1 As Acrobat.CAcroPDDoc
- Dim pagenum As Integer, I2 As Integer
- Set pdApp = CreateObject("AcroExch.App")
- Set acroRect = CreateObject("AcroExch.Rect")
- Set pdf1 = CreateObject("AcroExch.PDDoc")
- If pdf1.Open(nameFile) Then
- Set jso = pdf1.GetJSObject
- pagenum = pdf1.GetNumPages() '得到PDF页数
- For I2 = 1 To pagenum '每dpf文件多少页
- Set acroRect = CreateObject("AcroExch.Rect")
- '设置裁剪的PDF页面矩形设置
- acroRect.Left = W_Left '矩形以左边为准,向右偏移的数量
- acroRect.Right = W_Right '矩形的向右长度,以左边为准
- acroRect.Top = L_Top '矩形以顶边为准向下偏移的数量
- acroRect.bottom = L_bottom '矩形以底边为准向上偏移的数量
- CR = pdf1.CropPages(I2 - 1, I2 - 1, 0, acroRect) '裁剪页面
- Next
-
- exportCroppedPDF = outputPath '设定裁剪后的文件存放地址
- pdf1.Save 1, exportCroppedPDF '保存文件,覆盖不提示
- Set acroRect = Nothing
- CroppedPDF_standard = "文件裁剪OK"
- Else
- CroppedPDF_standard = "找不到文件" '
- End If
-
- pdf1.Close
- Set pdf1 = Nothing
- Set acroRect = Nothing
- Set jso = Nothing
- End Function
复制代码
|
评分
-
2
查看全部评分
-
|