PDF Print Security and Xpdf

The security model for PDF files is inherently insecure, because it relies on the viewer/reader software to respect the security features specified by the PDF standard. Since there are open source PDF viewers, like Xpdf, it is trivial to modify a PDF viewer to ignore the PDF standard's security model and allow printing, modifying, copying of "protected" PDF files.

After downloading the Xpdf source code, simply edit the XRef.cc file to ignore the security checks, and then recompile. Here is the section of code you would need to modify:

GBool XRef::okToPrint(GBool ignoreOwnerPW) {
  return (!ignoreOwnerPW && ownerPasswordOk) || (permFlags & permPrint);
}
 
GBool XRef::okToChange(GBool ignoreOwnerPW) {
  return (!ignoreOwnerPW && ownerPasswordOk) || (permFlags & permChange);
}
 
GBool XRef::okToCopy(GBool ignoreOwnerPW) {
  return (!ignoreOwnerPW && ownerPasswordOk) || (permFlags & permCopy);
}
 
GBool XRef::okToAddNotes(GBool ignoreOwnerPW) {
  return (!ignoreOwnerPW && ownerPasswordOk) || (permFlags & permNotes);
}
</code>
 
Modify it as follows:
<code>
GBool XRef::okToPrint(GBool ignoreOwnerPW) {
  return (1);
}
 
GBool XRef::okToChange(GBool ignoreOwnerPW) {
  return (1);
}
 
GBool XRef::okToCopy(GBool ignoreOwnerPW) {
  return (1);
}
 
GBool XRef::okToAddNotes(GBool ignoreOwnerPW) {
  return (1);
}

Then compile Xpdf by running ./configure and ./make.

If you run into problems with dependencies when compiling Xpdf and are using Debian or Ubuntu, just run apt-get install xpdf ghostscript so it can handle getting all the dependencies.

At this point, you can either open the PDF using Xpdf and print it, or if you want to permanently convert it to an unprotected PDF, run:

pdftops file.pdf file.ps
ps2pdf file.ps unprotected.pdf

Leave a Reply

Your email address will not be published. Required fields are marked *