You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pdfencryption.xml 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!-- $Id$ -->
  17. <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
  18. <document>
  19. <header>
  20. <title>Apache™ FOP: PDF encryption.</title>
  21. <version>$Revision$</version>
  22. <authors>
  23. <person name="J.Pietschmann" email="pietsch@apache.org"/>
  24. <person name="Jeremias Märki" email="jeremias@apache.org"/>
  25. </authors>
  26. </header>
  27. <body>
  28. <section>
  29. <title>Overview</title>
  30. <p>
  31. Apache™ FOP supports encryption of PDF output, thanks to Patrick
  32. C. Lankswert. This feature is commonly used to prevent
  33. unauthorized viewing, printing, editing, copying text from the
  34. document and doing annotations. It is also possible to ask the
  35. user for a password in order to view the contents. Note that
  36. there already exist third party applications which can decrypt
  37. an encrypted PDF without effort and allow the aforementioned
  38. operations, therefore the degree of protection is limited.
  39. </p>
  40. <p>
  41. For further information about features and restrictions regarding PDF
  42. encryption, look at the documentation coming with Adobe Acrobat or the
  43. technical documentation on the Adobe web site.
  44. </p>
  45. </section>
  46. <section>
  47. <title>Usage (command line)</title>
  48. <p>
  49. Encryption is enabled by supplying any of the encryption related
  50. options.
  51. </p>
  52. <p>
  53. An owner password is set with the <code>-o</code> option. This
  54. password is actually used as encryption key. Many tools for
  55. PDF processing ask for this password to disregard any
  56. restriction imposed on the PDF document.
  57. </p>
  58. <p>
  59. If no owner password has been supplied but FOP was asked to apply some
  60. restrictions, a random password is used. In this case it is obviously
  61. impossiible to disregard restrictions in PDF processing tools.
  62. </p>
  63. <p>
  64. A user password, supplied with the <code>-u</code> option, will
  65. cause the PDF display software to ask the reader for this password in
  66. order to view the contents of the document. If no user password was
  67. supplied, viewing the content is not restricted.
  68. </p>
  69. <p>
  70. Further restrictions can be imposed by using the following command-line options:
  71. <table>
  72. <tr>
  73. <th>Option</th>
  74. <th>Description</th>
  75. </tr>
  76. <tr>
  77. <td><code>-noprint</code></td>
  78. <td>disable printing</td>
  79. </tr>
  80. <tr>
  81. <td><code>-nocopy</code></td>
  82. <td>disable copy/paste of content</td>
  83. </tr>
  84. <tr>
  85. <td><code>-noedit</code></td>
  86. <td>disable editing in Adobe Acrobat</td>
  87. </tr>
  88. <tr>
  89. <td><code>-noannotations</code></td>
  90. <td>disable editing of annotations</td>
  91. </tr>
  92. <tr>
  93. <td><code>-nofillinforms</code></td>
  94. <td>disable filling in forms</td>
  95. </tr>
  96. <tr>
  97. <td><code>-noaccesscontent</code></td>
  98. <td>disable text and graphics extraction for accessibility purposes</td>
  99. </tr>
  100. <tr>
  101. <td><code>-noassembledoc</code></td>
  102. <td>disable assembling documents</td>
  103. </tr>
  104. <tr>
  105. <td><code>-noprinthq</code></td>
  106. <td>disable high quality printing</td>
  107. </tr>
  108. </table>
  109. </p>
  110. </section>
  111. <section>
  112. <title>Usage (embedded)</title>
  113. <p>
  114. When FOP is embedded in another Java application you need to set an
  115. options map on the renderer. These are the supported options:
  116. </p>
  117. <table>
  118. <tr>
  119. <th>Option</th>
  120. <th>Description</th>
  121. <th>Values</th>
  122. <th>Default</th>
  123. </tr>
  124. <tr>
  125. <td>encryption-length</td>
  126. <td>The encryption length in bit</td>
  127. <td>Any multiple of 8 between 40 and 128</td>
  128. <td>40</td>
  129. </tr>
  130. <tr>
  131. <td>ownerPassword</td>
  132. <td>The owner password</td>
  133. <td>String</td>
  134. <td/>
  135. </tr>
  136. <tr>
  137. <td>userPassword</td>
  138. <td>The user password</td>
  139. <td>String</td>
  140. <td/>
  141. </tr>
  142. <tr>
  143. <td>allowPrint</td>
  144. <td>Allows/disallows printing of the PDF</td>
  145. <td>"TRUE" or "FALSE"</td>
  146. <td>"TRUE"</td>
  147. </tr>
  148. <tr>
  149. <td>allowCopyContent</td>
  150. <td>Allows/disallows copy/paste of content</td>
  151. <td>"TRUE" or "FALSE"</td>
  152. <td>"TRUE"</td>
  153. </tr>
  154. <tr>
  155. <td>allowEditContent</td>
  156. <td>Allows/disallows editing in Adobe Acrobat</td>
  157. <td>"TRUE" or "FALSE"</td>
  158. <td>"TRUE"</td>
  159. </tr>
  160. <tr>
  161. <td>allowEditAnnotations</td>
  162. <td>Allows/disallows editing of annotations</td>
  163. <td>"TRUE" or "FALSE"</td>
  164. <td>"TRUE"</td>
  165. </tr>
  166. <tr>
  167. <td>allowFillInForms</td>
  168. <td>Allows/disallows filling in forms</td>
  169. <td>"TRUE" or "FALSE"</td>
  170. <td>"TRUE"</td>
  171. </tr>
  172. <tr>
  173. <td>allowAccessContent</td>
  174. <td>Allows/disallows text and graphics extraction for accessibility purposes</td>
  175. <td>"TRUE" or "FALSE"</td>
  176. <td>"TRUE"</td>
  177. </tr>
  178. <tr>
  179. <td>allowAssembleDocument</td>
  180. <td>Allows/disallows assembling document</td>
  181. <td>"TRUE" or "FALSE"</td>
  182. <td>"TRUE"</td>
  183. </tr>
  184. <tr>
  185. <td>allowPrintHq</td>
  186. <td>Allows/disallows high quality printing</td>
  187. <td>"TRUE" or "FALSE"</td>
  188. <td>"TRUE"</td>
  189. </tr>
  190. </table>
  191. <note>
  192. Encryption is enabled as soon as one of these options is set.
  193. </note>
  194. <p>
  195. An example to enable PDF encryption in Java code:
  196. </p>
  197. <source><![CDATA[
  198. import org.apache.fop.pdf.PDFEncryptionParams;
  199. [..]
  200. FOUserAgent userAgent = fopFactory.newFOUserAgent();
  201. useragent.getRendererOptions().put("encryption-params", new PDFEncryptionParams(
  202. null, "password", false, false, true, true));
  203. Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent);
  204. [..]]]></source>
  205. <p>
  206. The parameters for the constructor of PDFEncryptionParams are:
  207. </p>
  208. <ol>
  209. <li>userPassword: String, may be null</li>
  210. <li>ownerPassword: String, may be null</li>
  211. <li>allowPrint: true if printing is allowed</li>
  212. <li>allowCopyContent: true if copying content is allowed</li>
  213. <li>allowEditContent: true if editing content is allowed</li>
  214. <li>allowEditAnnotations: true if editing annotations is allowed</li>
  215. <li>allowFillInForms: true if filling in forms is allowed.</li>
  216. <li>allowAccessContent: true if extracting text and graphics is allowed</li>
  217. <li>allowAssembleDocument: true if assembling document is allowed</li>
  218. <li>allowPrintHq: true if printing to high quality is allowed</li>
  219. </ol>
  220. <p>
  221. Alternatively, you can set each value separately in the Map provided by
  222. FOUserAgent.getRendererOptions() by using the following keys:
  223. </p>
  224. <ol>
  225. <li>user-password: String</li>
  226. <li>owner-password: String</li>
  227. <li>noprint: Boolean or "true"/"false"</li>
  228. <li>nocopy: Boolean or "true"/"false"</li>
  229. <li>noedit: Boolean or "true"/"false"</li>
  230. <li>noannotations: Boolean or "true"/"false"</li>
  231. <li>nofillinforms: Boolean or "true"/"false"</li>
  232. <li>noaccesscontent: Boolean or "true"/"false"</li>
  233. <li>noassembledoc: Boolean or "true"/"false"</li>
  234. <li>noprinthq: Boolean or "true"/"false"</li>
  235. </ol>
  236. </section>
  237. <section>
  238. <title>Environment</title>
  239. <p>
  240. In order to use PDF encryption, FOP has to be compiled with
  241. cryptography support. Currently, only <a
  242. href="http://java.sun.com/j2se/1.4/docs/guide/security/jce/JCERefGuide.html">JCE</a>
  243. is supported. JCE is part of JDK 1.4. For earlier JDKs, it can
  244. be installed separately. The build process automatically
  245. detects JCE presence and installs PDF encryption support if
  246. possible, otherwise a stub is compiled in.
  247. </p>
  248. <p>
  249. Cryptography support must also be present at run time. In particular, a
  250. provider for the RC4 cipher is needed. Unfortunately, the sample JCE
  251. provider in Sun's JDK 1.4 does <strong>not</strong> provide RC4. If you
  252. get a message saying
  253. </p>
  254. <source>"Cannot find any provider supporting RC4"</source>
  255. <p>
  256. then you don't have the needed infrastructure.
  257. </p>
  258. <p>
  259. There are several commercial and a few Open Source packages which
  260. provide RC4. A pure Java implementation is produced by <a
  261. href="http://www.bouncycastle.org/">The Legion of the Bouncy
  262. Castle</a>. <a
  263. href="http://www.mozilla.org/projects/security/pki/jss/">Mozilla
  264. JSS</a> is an interface to a native implementation.
  265. </p>
  266. </section>
  267. <section id="install_crypto">
  268. <title>Installing a crypto provider</title>
  269. <p>
  270. The pure Java implementation from <a
  271. href="http://www.bouncycastle.org/">Bouncy Castle</a> is easy to
  272. install.
  273. </p>
  274. <ol>
  275. <li>
  276. Download the binary distribution for your JDK version.
  277. </li>
  278. <li>
  279. Unpack the distribution. Add the jar file to your classpath. A
  280. convenient way to use the jar on Linux is to simply drop it into the
  281. FOP lib directory, it will be automatically picked up by
  282. <code>fop.sh</code>.
  283. </li>
  284. <li>
  285. Open the <code>java.security</code> file and add<br/>
  286. <code>security.provider.6=org.bouncycastle.jce.provider.BouncyCastleProvider</code>,<br/>
  287. preferably at the end of the block defining the other crypto
  288. providers. For JDK 1.4 this is detailed on <a href="http://java.sun.com/j2se/1.4/docs/guide/security/jce/JCERefGuide.html#InstallProvider">Sun's web site</a>.
  289. </li>
  290. </ol>
  291. <p>
  292. If you have any experience with Mozilla JSS or any other
  293. cryptography provider, please post it to the fop-user list.
  294. </p>
  295. </section>
  296. </body>
  297. </document>