Chapter 12. Protecting your PDF

 

This chapter covers

  • Providing metadata
  • Compressing and decompressing PDFs
  • Encrypting documents
  • Adding digital signatures

You have created many different documents containing data, such as movies, directors, and movie screenings taken from a database, but you haven’t added any information about the owner of this data. You could make sure that people find out who created the document by adding metadata.

You’ve also peeked inside some of the PDF files you created, and you’ve seen that the content of a document is compressed by default. You could use iText to decompress content streams to read the PDF syntax that makes up a page or a form XObject.

For confidential documents, you’ll want to protect the document. To achieve this, we’re going to discuss how to encrypt content streams. You can do this using a password, or you can encrypt a PDF using a public key. Only the person who owns the corresponding private key will be able to open the document.

Digital signatures work the other way around: you sign a document using your private key, and whoever reads your document can use your public key (or the root certificate of a certificate authority) to make sure the document wasn’t forged by somebody else.

But let’s begin with the beginning, and start by adding metadata.

12.1. Adding metadata

12.2. PDF and compression

12.3. Encrypting a PDF document

12.4. Digital signatures, OCSP, and timestamping

12.5. Summary