|
本帖最后由 bluesky_0 于 2024-4-10 12:40 编辑
文档性质的PDF,可以导出很多格式,我导出使用的格式 是 图片,EXCEL,其他格式没有用过;
在Win10 Adobe9.0 pro, Adobe DC pro 运行OK
注意生成的EXCEL格式文件,需要Adobe PRO 10.0 以上版本
- Public Function SavePDFAsFormat(PDFPath_old As String, pdfName As String, PDFPath_new As String, FileExtension As String, Optional fileName As String = "") As String
- 'PDFPath_old As String, PDFname As String, 分别是PDF文件地址,文件名;分别举例:D:\OK,test.pdf
- 'PDFPath_new As String, FileExtension As String, Optional file_name As String = "" 分别是新地址,格式,可选项文件名,默认是原PDF文件名
- '重名不覆盖,自动重命名-001
- Dim objAcroApp As Acrobat.acroApp
- Dim objAcroAVDoc As Acrobat.acroAVDoc
- Dim objAcroPDDoc As Acrobat.acroPDDoc
- Dim objJSO As Object
- Dim boResult As Boolean
- Dim ExportFormat As String
- Dim NewFilePath As String
-
- 'Initialize Acrobat by creating App object.
- Set objAcroApp = CreateObject("AcroExch.App")
-
- 'Set AVDoc object.
- Set objAcroAVDoc = CreateObject("AcroExch.AVDoc")
-
- 'Open the PDF file.
- ' boResult = objAcroAVDoc.Open(PDFPath_old & "" & pdfName & ".pdf", "")
- boResult = objAcroAVDoc.Open(PDFPath_old & "" & pdfName, "")
-
- 'Set the PDDoc object.
- Set objAcroPDDoc = objAcroAVDoc.GetPDDoc
-
- 'Set the JS Object - JavaScript Object.
- Set objJSO = objAcroPDDoc.GetJSObject
-
- 'Check the type of conversion.
- Select Case LCase(FileExtension)
- Case "eps": ExportFormat = "com.adobe.acrobat.eps"
- Case "html", "htm": ExportFormat = "com.adobe.acrobat.html"
- Case "jpeg", "jpg", "jpe": ExportFormat = "com.adobe.acrobat.jpeg"
- Case "jpf", "jpx", "jp2", "j2k", "j2c", "jpc": ExportFormat = "com.adobe.acrobat.jp2k"
- Case "docx": ExportFormat = "com.adobe.acrobat.docx"
- Case "doc": ExportFormat = "com.adobe.acrobat.doc"
- Case "png": ExportFormat = "com.adobe.acrobat.png"
- Case "ps": ExportFormat = "com.adobe.acrobat.ps"
- Case "rft": ExportFormat = "com.adobe.acrobat.rft"
- Case "xlsx": ExportFormat = "com.adobe.acrobat.xlsx"
- Case "xls": ExportFormat = "com.adobe.acrobat.spreadsheet"
- Case "txt": ExportFormat = "com.adobe.acrobat.accesstext"
- Case "tiff", "tif": ExportFormat = "com.adobe.acrobat.tiff"
- Case "xml": ExportFormat = "com.adobe.acrobat.xml-1-00"
- Case Else: ExportFormat = "Wrong Input"
- End Select
-
- 'Check if the format is correct and there are no errors.
- If ExportFormat <> "Wrong Input" And Err.Number = 0 Then
-
- 'Format is correct and no errors.
-
- 'Set the path of the new file.
- If fileName = "" Then
- fileName = pdfName
- End If
-
- counter = 1
- Do While Dir(PDFPath_new & "" & fileName & "-" & Format(counter, "000") & "." & FileExtension) <> ""
- counter = counter + 1
- Loop
-
- If LCase(FileExtension) <> "xls" Then
- NewFilePath = PDFPath_new & "" & fileName & "-" & Format(counter, "000") & "." & FileExtension
- Else
- NewFilePath = PDFPath_new & "" & fileName & "-" & Format(counter, "000") & ".xml"
- End If
-
- 'Save PDF file to the new format.
- boResult = objJSO.SaveAs(NewFilePath, ExportFormat)
-
- 'Close the PDF file without saving the changes.
- boResult = objAcroAVDoc.Close(True)
-
- 'Close the Acrobat application.
- boResult = objAcroApp.Exit
-
- Else
-
- 'Something went wrong, so close the PDF file and the application.
-
- 'Close the PDF file without saving the changes.
- boResult = objAcroAVDoc.Close(True)
-
- 'Close the Acrobat application.
- boResult = objAcroApp.Exit
- End If
- SavePDFAsFormat = NewFilePath
- 'Release the objects.
- Set objAcroPDDoc = Nothing
- Set objAcroAVDoc = Nothing
- Set objAcroApp = Nothing
- End Function
复制代码
补充内容 (2024-7-11 08:30):
更正code里一个错误:
boResult = objAcroAVDoc.Open(PDFPath_old & "" & pdfName, "")改成
boResult = objAcroAVDoc.Open(PDFPath_old & "\" & pdfName, "") |
评分
-
3
查看全部评分
-
|