如何解决MS Access 密码保护 PDF 使用 Ghostscript - PDF 文档空白
这是我的第一篇文章 - 温柔点!
我希望从 MS Access(2013 版)中对 PDF 报告进行密码保护
我发现 this question and answer on Stack 很有用,但遇到了障碍
创建报告时,它具有所有必要的信息,但在调用函数(以密码保护 PDF)后,PDF 报告为空白。名称相同且 PDF 受密码保护 - 但它是空白的!
传递给 Ghostscript 的指令是
-q -dSAFER -dnopAUSE -dBATCH -sDEVICE=pdfwrite -sOwnerPassword=170284 -sUserPassword=170284 -dCompatibilityLevel=2.0 -sOutputFile=D:\Data\ Report.pdf
Public Function fctPDO_Print_pdf_GhostScript(strSourceFolder As String,strTargetFolder As String,strFile_for_pdf As String,Optional strUserPassword As String = "",Optional strOwnerPassword As String = "") As String
' http://www.herber.de/forum/archiv/1164to1168/1165503_Zusammenfuehren_von_PDF_Files.html#1165503
' https://stackoverflow.com/questions/49953421/ghostscript-with-aes-256-password-protection-for-pdf-2-0-documents
' PDO: Prints a pdf (originally multi-pdf). Requires Ghostscript,and read/write rights.
' Existing files are overwritten without asking.
' Provide both passwords to lock. Ghostscript does rc4,being comparatively unsafe.
'
On Error Resume Next
Dim fso As Object,WshShell As Object
Dim strCommand As String
Dim strGhostScript As String
Set fso = CreateObject("Scripting.FileSystemObject")
'Path to gswin32c.exe
strGhostScript = "C:\Program Files (x86)\gs9.54.0\bin\gswin64c.exe"
'Shell-command prepare
strTargetFolder = fso.GetFolder(strTargetFolder).ShortPath
strGhostScript = fso.GetFile(strGhostScript).ShortPath
'PDO: Password-Phrase,with Ghostscript only RC4 possible...
strCommand = strGhostScript & " -q -dSAFER -dnopAUSE -dBATCH -sDEVICE=pdfwrite -sOwnerPassword=" & strOwnerPassword
strCommand = strCommand & " -sUserPassword=" & strUserPassword & " -dCompatibilityLevel=2.0"
strCommand = strCommand & " -sOutputFile=" & strTargetFolder & "\" & strFile_for_pdf
'Execute
Debug.Print strCommand
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run strCommand,True
Set WshShell = nothing
fctPDO_Print_pdf_GhostScript = strTargetFolder & strFile_for_pdf
' Cleanup:
Err_Handler:
Set fso = nothing
End Function
我尝试了很多调试方法,包括传递指令的变化,但没有取得多大成功 - 这超出了我的工资
我希望有人能发现错误并提供帮助
提前致谢
解决方法
感谢@Kens 的提示。更新了现在可以工作的代码:
Public Function fctPDO_Print_pdf_GhostScript(strSourceFolder As String,strTargetFolder As String,strOriginalFile As String,strTargetFile As String,Optional strUserPassword As String = "",Optional strOwnerPassword As String = "") As String
' PDO: Prints a pdf (originally multi-pdf). Requires Ghostscript,and read/write rights.
' Existing files are overwritten without asking.
' Provide both passwords to lock. Ghostscript does rc4,being comparatively unsafe.
'
On Error Resume Next
Dim fso As Object,WshShell As Object
Dim strCommand As String
Dim strGhostScript As String
Set fso = CreateObject("Scripting.FileSystemObject")
'Path to gswin32c.exe
strGhostScript = "C:\Program Files (x86)\gs9.54.0\bin\gswin64c.exe"
'Shell-command prepare
strTargetFolder = fso.GetFolder(strTargetFolder).ShortPath
strGhostScript = fso.GetFile(strGhostScript).ShortPath
'PDO: Password-Phrase,with Ghostscript only RC4 possible...
strCommand = strGhostScript & " -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOwnerPassword=" & strOwnerPassword
strCommand = strCommand & " -sUserPassword=" & strUserPassword & " -dCompatibilityLevel=2.0"
strCommand = strCommand & " -sOutputFile=" & strTargetFolder & "\" & strTargetFile
strCommand = strCommand & " " & strSourceFolder & "\" & strOriginalFile
'Execute
Debug.Print strCommand
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run strCommand,True
Set WshShell = Nothing
fctPDO_Print_pdf_GhostScript = strTargetFolder & strTargetFile
' Cleanup:
Err_Handler:
Set fso = Nothing
End Function
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。