【发布时间】:2018-01-28 09:22:59
【问题描述】:
我需要使用 Excel VBA 检索 PDF 文件中的 页数(具有安全性)。
以下代码在 PDF 文件中没有启用安全性时有效:
Sub PDFandNumPages()
Dim Folder As Object
Dim file As Object
Dim fso As Object
Dim iExtLen As Integer, iRow As Integer
Dim sFolder As String, sExt As String
Dim sPDFName As String
sExt = "pdf"
iExtLen = Len(sExt)
iRow = 1
' Must have a '\' at the end of path
sFolder = "C:\test\"
Set fso = CreateObject("Scripting.FileSystemObject")
If sFolder <> "" Then
Set Folder = fso.GetFolder(sFolder)
For Each file In Folder.Files
If Right(file, iExtLen) = sExt Then
Cells(iRow, 1).Value = file.Name
Cells(iRow, 2).Value = pageCount(sFolder & file.Name)
iRow = iRow + 1
End If
Next file
End If
End Sub
但是,如果启用了任何类型的安全性,则代码无法提取页码并返回零页。
注意:打开这些 PDF 文件没有密码保护,它仅启用了一些安全功能以防止 修改 PDF。
启用安全的示例 PDF 可在以下 Google Drive 链接上找到:Google Drive PDF with security
我的要求是调整代码,以便显示 PDF 文件中的页码,无论是否有任何安全性。
对于 Python,我在 this page 找到了类似的问题和解决方案,但是它使用 Python 库。如果可能的话,我希望 VBA 方面的专家建议我如何在 VBA 中复制它
【问题讨论】:
-
文档是否有“权限密码”?
-
不,它没有任何密码。您还可以访问我在 google drive 上上传的文件以查看它们
-
好的——见下面我的回答。您可能需要 Adobe Acrobat 的“完整版”(不是“阅读器”)
-
我的要求是找到一堆PDF文件的页码,就像你打开一个文件一样,看看有多少页。我不想手动打开每个受保护的 PDF 文件并更改 PDF 中的任何设置。即使要更改任何设置,我也希望通过代码以自动方式完成。注意:我不想提取任何页面,只想要文件的总页数。
-
我明白了。 “extract”这个词把我吓跑了。那么在那种情况下......
标签: vba excel pdf text-extraction