Commit eae8370cd9c4e6ac748931a425721303561bd6ac

Authored by Jay Berkenbilt
1 parent a3576a73

Add optional /Length key in crypt filter dictionary

ChangeLog
1 2013-06-14 Jay Berkenbilt <ejb@ql.org> 1 2013-06-14 Jay Berkenbilt <ejb@ql.org>
2 2
  3 + * Add /Length key to crypt filter dictionary for encrypted files.
  4 + This key is optional, but some version of MacOS reportedly fail to
  5 + open encrypted PDF files without this key.
  6 +
3 * Bug fix: properly handle object stream generation when the 7 * Bug fix: properly handle object stream generation when the
4 original file has some compressible objects with generation != 0. 8 original file has some compressible objects with generation != 0.
5 9
libqpdf/QPDFWriter.cc
@@ -726,8 +726,12 @@ QPDFWriter::setEncryptionParametersInternal( @@ -726,8 +726,12 @@ QPDFWriter::setEncryptionParametersInternal(
726 std::string method = (this->encrypt_use_aes 726 std::string method = (this->encrypt_use_aes
727 ? ((V < 5) ? "/AESV2" : "/AESV3") 727 ? ((V < 5) ? "/AESV2" : "/AESV3")
728 : "/V2"); 728 : "/V2");
  729 + // The PDF spec says the /Length key is optional, but the PDF
  730 + // previewer on some versions of MacOS won't open encrypted
  731 + // files without it.
729 encryption_dictionary["/CF"] = 732 encryption_dictionary["/CF"] =
730 - "<< /StdCF << /AuthEvent /DocOpen /CFM " + method + " >> >>"; 733 + "<< /StdCF << /AuthEvent /DocOpen /CFM " + method +
  734 + " /Length " + std::string((V < 5) ? "16" : "32") + " >> >>";
731 } 735 }
732 736
733 this->encrypted = true; 737 this->encrypted = true;
qpdf/qtest/qpdf/V4-aes-clearmeta.pdf
No preview for this file type
qpdf/qtest/qpdf/V4-aes.pdf
No preview for this file type
qpdf/qtest/qpdf/V4-clearmeta.pdf
No preview for this file type
qpdf/qtest/qpdf/V4.pdf
No preview for this file type
qpdf/qtest/qpdf/c-r4.pdf
No preview for this file type
qpdf/qtest/qpdf/c-r5-in.pdf
No preview for this file type
qpdf/qtest/qpdf/c-r6-in.pdf
No preview for this file type