|
楼主 |
发表于 2024-3-1 14:06
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
纯VBA代码 实现: PDF另存为图片文件
- Option Explicit '//强制声明变量
- Sub TEST()
- Dim PathPDF As String, PathJPEG As String
- PathPDF = ThisWorkbook.Path & "\TEST.pdf"
- PathJPEG = ThisWorkbook.Path & "\图片.JPEG"
- Call SetPDFtoJPG(PathPDF:=PathPDF, PathJPEG:=PathJPEG)
- End Sub
- Sub SetPDFtoJPG(ByVal PathPDF As String, Optional ByVal PathJPEG As String = "")
- Rem 将PDF文件另存为图片文件, 扩展名: jpeg
- Rem PathPDF PDF文件全路径
- Rem PathJPEG 图片文件全路径 可选, 默认="" 和 PathPDF 同名 类似: 图片_页面_1,图片_页面_2
-
- Dim oaapp As New Acrobat.AcroApp
- Dim oaavd As New Acrobat.AcroAVDoc
- Dim oapdd As Acrobat.AcroPDDoc
- Dim i As Long
- Dim jso As Object
- i = oaapp.Show
- i = oaavd.Open(PathPDF, "")
- Set oapdd = oaavd.GetPDDoc()
- Set jso = oapdd.GetJSObject
- If PathJPEG = "" Then PathJPEG = Mid(PathPDF, 1, Len(PathPDF) - 4) & ".jpeg"
- jso.SaveAs PathJPEG, "com.adobe.acrobat.jpeg"
- i = oaavd.Close(1)
- i = oaapp.Hide
- i = oaapp.Exit
- Set jso = Nothing
- Set oaavd = Nothing
- Set oaapp = Nothing
- End Sub
复制代码
|
|