chore(pdf): encrypt pdfs with password using external pdftk
This commit is contained in:
parent
a0271009b2
commit
09b2a88b4e
@ -149,6 +149,7 @@ dependencies:
|
|||||||
- unidecode
|
- unidecode
|
||||||
- pandoc
|
- pandoc
|
||||||
- pandoc-types
|
- pandoc-types
|
||||||
|
- typed-process
|
||||||
- insert-ordered-containers
|
- insert-ordered-containers
|
||||||
- servant
|
- servant
|
||||||
- servant-server
|
- servant-server
|
||||||
|
|||||||
@ -74,7 +74,7 @@ in pkgs.mkShell {
|
|||||||
++ (with pkgs;
|
++ (with pkgs;
|
||||||
[ nodejs-14_x postgresql_12 openldap google-chrome exiftool memcached minio minio-client
|
[ nodejs-14_x postgresql_12 openldap google-chrome exiftool memcached minio minio-client
|
||||||
gup skopeo
|
gup skopeo
|
||||||
busybox # for print services
|
# busybox # for print services, but interferes with build commands in develop-shell
|
||||||
pdftk #pdftk just for testing pdf-passwords
|
pdftk #pdftk just for testing pdf-passwords
|
||||||
#texlive.combined.scheme-full # works
|
#texlive.combined.scheme-full # works
|
||||||
#texlive.combined.scheme-medium
|
#texlive.combined.scheme-medium
|
||||||
|
|||||||
@ -14,6 +14,9 @@ import qualified Text.Pandoc as P
|
|||||||
import qualified Text.Pandoc.PDF as P
|
import qualified Text.Pandoc.PDF as P
|
||||||
import qualified Text.Pandoc.Builder as P
|
import qualified Text.Pandoc.Builder as P
|
||||||
|
|
||||||
|
import System.Exit
|
||||||
|
import System.Process.Typed -- for calling pdftk for pdf encryption
|
||||||
|
|
||||||
-- import Model.Types.Markup -- TODO-QSV: should this module be moved accordingly?
|
-- import Model.Types.Markup -- TODO-QSV: should this module be moved accordingly?
|
||||||
|
|
||||||
{- Recall:
|
{- Recall:
|
||||||
@ -246,3 +249,27 @@ sendLetter printJobName pdf printJobRecipient printJobSender printJobCourse prin
|
|||||||
return printJobFilename
|
return printJobFilename
|
||||||
|
|
||||||
|
|
||||||
|
-----------
|
||||||
|
-- pdftk --
|
||||||
|
-----------
|
||||||
|
--
|
||||||
|
-- We use the external tool pdftk for PDF encryption like so
|
||||||
|
-- > pdftk in.pdf output out.pdf user_pw tomatenmarmelade
|
||||||
|
-- we can use stdin and std out like so
|
||||||
|
-- > pdftk - output - user_pw tomatenmarmelade
|
||||||
|
--
|
||||||
|
|
||||||
|
encryptPDF :: MonadIO m => String -> LBS.ByteString -> m (Either LBS.ByteString LBS.ByteString)
|
||||||
|
encryptPDF pw bs = exit2either <$> readProcess pc
|
||||||
|
where
|
||||||
|
pc = setStdin (byteStringInput bs) $
|
||||||
|
proc "pdftk" ["-" -- read from stdin
|
||||||
|
, "output", "-" -- write to stdout
|
||||||
|
, "user_pw", pw -- encrypt pdf content
|
||||||
|
, "dont_ask" -- no interaction
|
||||||
|
, "allow", "Printing" -- allow printing despite encryption
|
||||||
|
]
|
||||||
|
|
||||||
|
exit2either :: (ExitCode, a, b) -> Either b a
|
||||||
|
exit2either (ExitSuccess , ok, _) = Right ok
|
||||||
|
exit2either (ExitFailure _ , _, err) = Left err
|
||||||
Reference in New Issue
Block a user