Sophie

Sophie

distrib > Fedora > 17 > x86_64 > by-pkgid > cf79c2d0ed7fa2678c515072ee6f31e4 > files > 88

jasperreports-manual-4.0.2-4.fc17.noarch.rpm

<html xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://jasperreports.sourceforge.net/jasperreports">
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JasperReports 4.0.2 - PDF Encrypt Sample</title>
<style type="text/css">
.title {
	font-family: Arial, Verdana, Helvetica, sans-serif;
	font-size: 28px;
	font-weight: normal;
}

.toc {
	font-family: Courier New, Courier, serif;
	font-size: 12px;
	font-weight: normal;
}

.name {
	font-family: Courier New, Courier, serif;
	font-size: 16px;
	font-weight: bold;
}

.label {
	font-family: Arial, Verdana, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	font-style: italic;
}

.description {
	font-family: Arial, Verdana, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: normal;
}

.value {
	font-family: Courier New, Courier, serif;
	font-size: 12px;
	font-weight: normal;
}

.element {
	font-family: Courier New, Courier, serif;
	font-size: 12px;
	font-weight: normal;
}

.attribute {
	font-family: Courier New, Courier, serif;
	font-size: 12px;
	font-weight: bold;
}

.code {
	font-family: Courier New, Courier, serif;
	font-size: 12px;
	font-weight: normal;
}

.copy {
	font-decoration: none;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 8pt;
	font-style: normal;
	color: #000000;
}

.subtitle {
	font-family: inherit;
	font-size: inherit;
	font-style: inherit;
	font-weight: bold;
	text-decoration: none;
	color: inherit;
}

</style>
</head>
<body bgcolor="#FFFFFF">
<a name="top"></a>
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td colspan="2" align="right"><span class="element"><a href="../../sample.reference.html">Sample Reference</a> - <a href="../../schema.reference.html">Schema Reference</a> - <a href="../../config.reference.html">Configuration Reference</a> - <a href="http://jasperreports.sourceforge.net/api/index.html">API (Javadoc)</a></span>
<br>
</td>
</tr>
<tr>
<td colspan="2">
<hr size="1">
</td>
</tr>
<tr valign="middle">
<td nowrap="true"><span class="title">JasperReports - PDF Encrypt Sample (version 4.0.2)</span></td><td align="right"><img src="../../resources/jasperreports.png" border="0"></td>
</tr>
<tr>
<td colspan="2">
<hr size="1">
</td>
</tr>
</table>
<br>
<span class="description"><span class="description">Shows how reports could be encrypted when exported to PDF.</span></span>
<br>
<br>
<span class="element"><a href="http://sourceforge.net/projects/jasperreports/files/jasperreports/JasperReports%204.0.2/jasperreports-4.0.2-project.zip/download" target="_blank">Download All Sample Source Files</a></span>
<br>
<span class="element"><a href="http://jasperforge.org/scm/viewvc.php/tags/jr-4-0-2/jasperreports/demo/samples/pdfencrypt/?root=jasperreports" target="_blank">Browse Sample Source Files on SVN</a></span>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 20px;">
<br>
</td><td>
<br>
</td>
</tr>
<tr>
<td colspan="2"><span class="label">Main Features in This Sample</span></td>
</tr>
<tr>
<td>
<br>
</td><td><span class="element"><a href="#pdfencrypt">Encrypted PDF</a></span></td>
</tr>
</table>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td><img src="../../resources/px.gif" border="0" width="20" height="1"></td><td><img src="../../resources/px.gif" border="0" width="20" height="1"></td><td><img src="../../resources/px.gif" border="0" width="20" height="1"></td><td><img src="../../resources/px.gif" border="0" width="20" height="1"></td><td width="80%">
<br>
</td><td width="20%">
<br>
</td>
</tr>
<tr>
<td colspan="6" align="right"><a name="pdfencrypt"></a><a href="#top" class="toc">top</a></td>
</tr>
<tr>
<td colspan="6">
<hr size="1">
</td>
</tr>
<tr valign="top">
<td><img src="../../resources/jr-16x16.png" border="0"></td><td colspan="4"><span class="name">Encrypted PDF</span></td><td align="right"><span class="copy">Documented by 
	<a href="mailto:shertage@users.sourceforge.net" class="copy">Sanda Zaharia</a></span></td>
</tr>
<tr>
<td colspan="6">
<br>
</td>
</tr>
<tr valign="top">
<td>
<br>
</td><td nowrap="true"><span class="label">Description / Goal</span></td><td>
<br>
</td><td colspan="3"><span class="description">
How to produce encrypted PDF reports.
    </span></td>
</tr>
<tr valign="top">
<td>
<br>
</td><td colspan="1"><span class="label">Since</span></td><td>
<br>
</td><td colspan="3"><span class="description">0.5.1</span></td>
</tr>
<tr>
<td colspan="6">
<br>
</td>
</tr>
<tr>
<td>
<br>
</td><td colspan="5"><span class="description">
<b>PDF Encryption</b>    

<br>

<br>
There are situations when documents are supposed to be accessed by authorized users only. 
<br>
Using the file encryption represents a method of protecting a document from unauthorized access. 
There are two categories of document users: the document owner (which provides full document access 
granted by default) and regular document users (with limited access permissions. User permissions 
and document restrictions can be set by the document owner only.
<br>
To distinguish between these user categories, the document is allowed to store within up to two 
passwords: an owner password and a user password. The application decides whether to encrypt a document 
based on the presence of any of these passwords or access restrictions. If they are set, 
the document will be encrypted, making all its content unreadable to unauthorized users. 
<br>

<br>
User permissions and all other information required to validate the passwords will be stored in 
the document's encryption dictionary. 
<br>

<br>
When a user attempts to open an encrypted document protected with a password, a dialog will open 
prompting for the appropriate password. If the password matches, then all user permissions are activated 
and the document can be open, decrypted, and displayed in a readable form on the screen. 
<br>
If no password is set, when open the document no password is requested and full access is granted by default. 
<br>
Opening the document with the owner password enables the full access to the document, including the possibility 
to change passwords and access permissions. 
<br>
Opening the document with the user password enables some additional operations to be performed, with respect 
to the user access permissions stored in the encryption dictionary. 
<br>

<br>

<b>Encrypted PDF in JasperReports</b>    

<br>

<br>
When exporting to the PDF format the engine has to know five additional things about the generated document 
and uses five dedicated exporter parameters for this:
<ul>

<li>Is the document encrypted? A flag parameter called 
<span class="element"><a href="http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/export/JRPdfExporterParameter.html#IS_ENCRYPTED" target="_blank">IS_ENCRYPTED</a></span> 
answers to this question. If set to <span class="code"><code>Boolean.TRUE</code></span>, this instructs the exporter to
encrypt the resulting PDF document. By default PDF files are not encrypted.<br>One can use the related 
<span class="code"><code>net.sf.jasperreports.export.pdf.encrypted</code></span> hint property for the same purpose.</li> 

<li>Which key to use for the encrypted document? By default the PDF exporter uses a 40-bit key for encryption, 
but if needed, it can use a 128-bit one. Setting the 
<span class="element"><a href="http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/export/JRPdfExporterParameter.html#IS_128_BIT_KEY" target="_blank">IS_128_BIT_KEY</a></span> 
flag to <span class="code"><code>true</code></span> will instruct the engine to use a 128-bit key. <br>One can use the related 
<span class="code"><code>net.sf.jasperreports.export.pdf.128.bit.key</code></span> 
hint property for the same purpose.</li>

<li>The user password. This can be set using the 
<span class="element"><a href="http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/export/JRPdfExporterParameter.html#USER_PASSWORD" target="_blank">USER_PASSWORD</a></span> 
or the related <span class="code"><code>net.sf.jasperreports.export.pdf.user.password</code></span> 
hint property.</li>

<li>The owner password. This can be set using the 
<span class="element"><a href="http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/export/JRPdfExporterParameter.html#OWNER_PASSWORD" target="_blank">OWNER_PASSWORD</a></span> 
or the related <span class="code"><code>net.sf.jasperreports.export.pdf.owner.password</code></span> 
hint property.</li>

<li>User permissions. They can be set in the 
<span class="element"><a href="http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/export/JRPdfExporterParameter.html#PERMISSIONS" target="_blank">PERMISSIONS</a></span> export parameter. 
This exporter parameter accepts <span class="code"><code>java.lang.Integer</code></span> values 
representing the PDF permissions for the generated document. The open permissions for 
the document can be <span class="code"><code>AllowPrinting</code></span>, <span class="code"><code>AllowModifyContents</code></span>, <span class="code"><code>AllowCopy</code></span>, 
<span class="code"><code>AllowModifyAnnotations</code></span>, <span class="code"><code>AllowFillIn</code></span>, <span class="code"><code>AllowScreenReaders</code></span>, <span class="code"><code>AllowAssembly</code></span>, 
and <span class="code"><code>AllowDegradedPrinting</code></span> (these are all in the <span class="code"><code>PdfWriter</code></span> class of the iText 
library). Permissions can be combined by applying bitwise <span class="code"><code>OR</code></span> to them.</li>

</ul>

<b>Encrypted PDF Example</b>    

<br>

<br>
This sample makes use of the above export parameters in order to generate an encrypted document. Taking a look at the 
<span class="code"><code>pdf()</code></span> method in the <span class="code"><code>src/PdfEncryptApp.java</code></span> file, one can see how to set them all:
<pre>
  exporter.setParameter(JRPdfExporterParameter.IS_ENCRYPTED, Boolean.TRUE);
  exporter.setParameter(JRPdfExporterParameter.IS_128_BIT_KEY, Boolean.TRUE);
  exporter.setParameter(JRPdfExporterParameter.USER_PASSWORD, "jasper");
  exporter.setParameter(JRPdfExporterParameter.OWNER_PASSWORD, "reports");
  exporter.setParameter(
    JRPdfExporterParameter.PERMISSIONS, 
    new Integer(PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING)
    );</pre>

<b>Running the Sample</b>

<br>

<br>
Running the sample requires the <a href="http://ant.apache.org/" target="_blank" class="element">Apache Ant</a> library. Make sure that <span class="code"><code>ant</code></span> is already installed on your system (version 1.5 or later).
<br>
In a command prompt/terminal window set the current folder to <span class="code"><code>demo/samples/pdfencrypt</code></span> within the JasperReports source project and run the <span class="code"><code>&gt; ant test view</code></span> command.
<br>
It will generate all supported document types containing the sample report in the <span class="code"><code>demo/samples/pdfencrypt/build/reports</code></span> directory. 
<br>
Then the report will open in the JasperReports internal viewer.
    </span></td>
</tr>
<tr>
<td colspan="6">
<br>
</td>
</tr>
</table>
<br>
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td>
<hr size="1">
</td>
</tr>
<tr>
<td align="center"><span class="copy">&copy; 2001-2010 Jaspersoft Corporation <a href="http://www.jaspersoft.com" target="_blank" class="copy">www.jaspersoft.com</a></span></td>
</tr>
</table>
</body>
</html>