怎么给文件设置密码:如何为PDF文件导出设置密码(vba save as pdf with pword)

我需要添加提取 PDF 的密码。

Dim FileName As String
Dim FilePath As String
FileName = Me.Full_Name & "_" & Me.ID
FilePath = "C:\Users\Desktop\" & FileName & ".Pdf"
DoCmd.OutputTo acOutputReport, "Report", acFormatPDF, FilePath
MsgBox "Exported Successfully"
1

这里有一个使用 Ghostscript 的解决方案。首先像你已经做的那样打印你的 pdf,然后调用下面的函数。Ghostscript 在许可协议下是免费的,afaik

Public Function fctPDO_Print_pdf_GhostScript(strFile_for_pdf As String, Optional strUserPword As String = "", Optional strOwnerPword 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-pword-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 pwords to lock. Ghostscript does rc4 , being comparatively unsafe.
        '
          On Error Resume Next
          Dim fso As Object, WshShell As Object
          Dim strZielOrdner As String
          Dim strQuellOrdner As String
          Dim strCommand As String
          Dim strGhostScript As String
          Dim strFile_with_Path As String
          Dim strTargetFile_without_Path As String
          Set fso = CreateObject("Scripting.FileSystemObject")
         'Path to gswin32c.exe
          strGhostScript = "C:\Program Files (x86)\gs\gs9.19\bin\gswin32c.exe"
         ' Define folder
          strQuellOrdner = "D:\PDO_test"
          strZielOrdner = "D:\PDO_test"
         ' Shell-command prepare
          strZielOrdner = fso.GetFolder(strZielOrdner).ShortPath
          strGhostScript = fso.GetFile(strGhostScript).ShortPath
          strCommand = strGhostScript & " -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite"
            ' PDO: Pwort-Phrase, with Ghostscript only RC4 possible...
            If ((strUserPword <> "") And (strOwnerPword <> "")) Then
                strCommand = strCommand & " -sOwnerPword=" & strOwnerPword & " -sUserPword=" & strUserPword & " -dCompatibilityLevel=2.0"
            End If
          strCommand = strCommand & " -sOutputFile=" & Chr(34)
          strCommand = strCommand & strZielOrdner & "\"   'PDO: Danach kommt die Zieldatei und die einzelnen, anzubindenden Dateien.
          strTargetFile_without_Path = "Beratungsprotokoll_2018_Sammel.pdf"
          strFile_with_Path = strFile_for_pdf
               ' PDO: Gesamtcommand pt togehter ad executed
                strCommand = strCommand & strTargetFile_without_Path & Chr(34) & strFile_with_Path
                Debug.Print strCommand
                Set WshShell = CreateObject("WScript.Shell")
                WshShell.Run strCommand, 0, True
                Set WshShell = Nothing
            fctPDO_Print_pdf_GhostScript = strZielOrdner & "\" & strTargetFile_without_Path
        ' Cleanup:
Err_Handler:
          Set fso = Nothing
          MsgBox "Done"
        End Function

本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处

(331)
Co奶茶怎么样:stl地图性能怎么样(stl map c++)
上一篇
饥荒干草代码是多少:这个伪代码的复杂度 (Ø)是多少(psudo code)
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(52条)