61

I've found lots of info on decrypting PDF files, but none on encrypting them. What tool can do this for me?

Edit: There are two good answers below, but in my specific case the PDF was a scan, not a document that I'd created.

Martin Schröder
  • 6,772
  • 1
  • 19
  • 35
mfisch
  • 3,603
  • 2
  • 28
  • 39
  • 1
    Related questions on [Stack Overflow](http://stackoverflow.com/questions/tagged/pdf+encryption) and [Super User](http://superuser.com/questions/tagged/pdf+encryption). – Martin Schröder Feb 21 '13 at 21:56
  • Duplicate of [a Linux-wide question on Unix.SE](https://unix.stackexchange.com/q/187404/13308). – palswim Sep 26 '18 at 23:21

6 Answers6

74

Use pdftk. From its man page:

Encrypt a PDF using 128-Bit Strength (the Default) and Withhold All Permissions (the Default)

$ pdftk [mydoc].pdf output [mydoc.128].pdf owner_pw [foopass]

Same as Above, Except a Password is Required to Open the PDF

$ pdftk [mydoc].pdf output [mydoc.128].pdf owner_pw [foo] user_pw [baz]

Same as Above, Except Printing is Allowed (after the PDF is Open)

$ pdftk [mydoc].pdf output [mydoc.128].pdf owner_pw [foo] user_pw [baz] allow printing

pdftk has a lot of other uses as well and is worth installing if one works extensively with PDF files. To quote from the write-up in Synaptic:

If PDF is electronic paper, then pdftk is an electronic stapler-remover, hole-punch, binder, secret-decoder-ring, and X-Ray-glasses. Pdftk is a simple tool for doing everyday things with PDF documents. Keep one in the top drawer of your desktop and use it to:

  • Merge PDF documents
  • Split PDF pages into a new document
  • Decrypt input as necessary (password required)
  • Encrypt output as desired
  • Fill PDF Forms with FDF Data and/or Flatten Forms
  • Apply a Background Watermark
  • Report PDF on metrics, including metadata and bookmarks
  • Update PDF Metadata
  • Attach Files to PDF Pages or the PDF Document
  • Unpack PDF Attachments
  • Burst a PDF document into single pages
  • Uncompress and re-compress page streams
  • Repair corrupted PDF (where possible)
carnendil
  • 5,421
  • 2
  • 30
  • 55
  • 4
    If you wish a GUI for pdftk, you can try pdfchain that works good. For the above needing, you can use the Concatenate tab, adding only one PDF, and settings permissions options and password. – Stefano Feb 26 '13 at 22:27
  • 1
    The most recent release of pdfchain brings a number of enhancements but isn't available from the official repositories yet. You can install it via this PPA (maintained by the developers): https://launchpad.net/~pdfchain-team/+archive/ppa – Glutanimate Feb 27 '13 at 10:33
  • 1
    I tried the first example with pdftk 1.44, and I could open the resulting PDF without a password using evince. Only after adding `user_pw` was the document actually protected. – Joey Adams Aug 08 '13 at 20:43
  • 2
    @JoeyAdams ``owner_pw`` is intended to protect the pdf against modifications; the second example specifically adds ``user_pw`` to require a password to _read_ the file. – carnendil Sep 05 '17 at 17:43
  • If you just want a single password to open it, you can use `pdftk [mydoc].pdf output [mydoc.128].pdf user_pw [baz]`, skipping the owner setting. – colan Mar 22 '20 at 22:09
25

If you use LibreOffice and export a document as PDF (Menu > File > Export as PDF), there's the option to set a password:

enter image description here

  • Unfortunately my PDF is from a scan, but that would be a good general solution. – mfisch Feb 20 '13 at 17:30
  • 2
    Shouldn't it still be possible since you can import images into LibreOffice and then export as PDF? –  Feb 20 '13 at 17:36
  • I had a scanned document that the macOS Preview.app failed to encrypt correctly. Using LibreOffice to encrypt the PDF was the only way I was able to get this done, short of putting the doc on a linux server, installing pdftk and doing it on the CLI. – JinnKo Feb 16 '18 at 11:29
19

qpdf can encrypt and decrypt pdfs. And linearize them, too.

examples:

  • decryption:
    • qpdf --password='·······' --decrypt input.pdf output.pdf
  • encryption: 256bit AES

Link to qpdf online Manual

Ubuntu Launchpad PPA

Martin Schröder
  • 6,772
  • 1
  • 19
  • 35
  • 3
    Couple of good things about qpdf, which I just tried out: (1) it supports 256bits AES encryption, whereas pdftk is only 128bits; (2) it has a great manual here: http://qpdf.sourceforge.net/files/qpdf-manual.html – sxc731 Jul 22 '16 at 16:20
3

PDF Chain is an awesome tool for this. It is a GUI for pdftk

johndz
  • 31
  • 1
2

One possible solution is to use jpdf Tweak.

To Do
  • 15,172
  • 12
  • 70
  • 116
2

Master PDF Editor is a very good GUI for editing pdf also can encrypt. It also uses latest PDF standard. Used PDF Chain and Master PDF editor, both to encrypt a pdf, With PDF Chain the PDF outputed was larger and lost bookmarks, was almost double the size.

Jcfunk
  • 21
  • 1