Encrypt PDF in Java
PDF documents can be encrypted using the DynamicPDF Generator or Merger products. Listed below are steps and sample code for both the products.
How to Encrypt PDF
Aes128Security, Aes256Security, RC4128Security, and RC440Security classes present in ceTe.DynamicPDF.Cryptography namespace can be used to Encrypt PDF.
Below is a list of some security settings which can be set along with passwords while encrypting a PDF document.
- If accessibility programs should be able to read the documents text and images for the user
- If the document can be assembled and manipulated by the user
- If form filling should be allowed by the user
- If the document can be printed at a high resolution by the user
- The documents components to be encrypted
Steps for Encrypting a PDF Document
- Create a
Document
object. - Create a
Page
object and add it toDocument
. - Create a
RC4128Security
object by setting the owner and user password. - Set the required security properties and the security to the
Document
. - Invoke the
Draw
method on the Document to output the PDF.
Sample code - Java
Document document = new Document();
Page page = new Page();
document.getPages().add(page);
RC4128Security security = new RC4128Security("owner", "user");
security.setAllowCopy(false);
document.setSecurity(security);
document.Draw(@"Output.pdf");
How to Encrypt an Existing PDF
DynamicPDF Merger product can be used to Encrypt an existing PDF document.
Steps for Encrypting an existing PDF
- Create a
MergeDocument
object with the path to the PDF file. - Create a
RC4128Security
object by setting the owner and user password. - Set the required security properties and the security to the Document.
- Invoke the
Draw
method on the Document to output the PDF.
Sample code - Java
MergeDocument document = new MergeDocument("pdf-a.pdf");
RC4128Security security = new RC4128Security("owner", "user");
security.setAllowCopy(false);
document.setSecurity(security);
document.Draw(@"Output.pdf");
Getting Started
DynamicPDF Generator and Merger Information
More information can be found here:
Available in Other Platforms
Generator and Merger PDF Libraries are available for .NET and COM/AxtiveX platforms. Refer to the respective product pages for more details.
- DynamicPDF Generator
- .NET - DynamicPDF Generator for .NET
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX
- DynamicPDF Merger
- .NET - DynamicPDF Merger for .NET
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX