reddit / emacs

Password-protect current pdf buffer or dired file

xenodium · 2022-06-02 21:50
aimebertrand · 2022-06-07 18:55
Hello there, Like the function a lot and will use ist extensivelly for my archiving of stuff. I may have found an issue. I think you have to quote the %-sequences in the command for files with spaces in them like so: (defun pdf-password-protect () "Password protect current pdf in buffer or `dired' file." (interactive) (unless (executable-find "qpdf") (user-error "qpdf not installed")) (unless (equal "pdf" (or (when (buffer-file-name) (downcase (file-name-extension (buffer-file-name)))) (when (dired-get-filename nil t) (downcase (file-name-extension (dired-get-filename nil t)))))) (user-error "no pdf to act on")) (let* ((user-password (read-passwd "user-password: ")) (owner-password (read-passwd "owner-password: ")) (input (or (buffer-file-name) (dired-get-filename nil t))) (output (concat (file-name-sans-extension input) "_enc.pdf"))) (message (string-trim (shell-command-to-string (format "qpdf --verbose --encrypt '%s' '%s' 256 -- '%s' '%s'" user-password owner-password input output))))))
xenodium · 2022-06-07 22:54
Ah, yes. You're right. Thanks for the fix. Updated post.