com.lowagie.text.pdf
Class PdfCopyForms

java.lang.Object
  extended by com.lowagie.text.pdf.PdfCopyForms
All Implemented Interfaces:
PdfEncryptionSettings, PdfViewerPreferences

public class PdfCopyForms
extends java.lang.Object
implements PdfViewerPreferences, PdfEncryptionSettings

Allows you to add one (or more) existing PDF document(s) to create a new PDF and add the form of another PDF document to this new PDF.

Since:
2.1.5

Constructor Summary
PdfCopyForms(java.io.OutputStream os)
          Creates a new instance.
 
Method Summary
 void addDocument(PdfReader reader)
          Concatenates a PDF document.
 void addDocument(PdfReader reader, java.util.List pagesToKeep)
          Concatenates a PDF document selecting the pages to keep.
 void addDocument(PdfReader reader, java.lang.String ranges)
          Concatenates a PDF document selecting the pages to keep.
 void addJavaScript(java.lang.String js)
          Adds JavaScript to the global document
 void addViewerPreference(PdfName key, PdfObject value)
          Adds a viewer preference.
 void close()
          Closes the output document.
 void copyDocumentFields(PdfReader reader)
          Copies the form fields of this PDFDocument onto the PDF-Document which was added
 PdfWriter getWriter()
          Gets the underlying PdfWriter.
 boolean isFullCompression()
          Gets the 1.5 compression status.
 void open()
          Opens the document.
 void setEncryption(boolean strength, java.lang.String userPassword, java.lang.String ownerPassword, int permissions)
          Sets the encryption options for this document.
 void setEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits)
          Sets the encryption options for this document.
 void setEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionType)
          Sets the encryption options for this document.
 void setEncryption(java.security.cert.Certificate[] certs, int[] permissions, int encryptionType)
          Sets the certificate encryption options for this document.
 void setFullCompression()
          Sets the document's compression to the new 1.5 mode with object streams and xref streams.
 void setOutlines(java.util.List outlines)
          Sets the bookmarks.
 void setViewerPreferences(int preferences)
          Sets the page layout and page mode preferences by ORing one or two of these constants.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PdfCopyForms

public PdfCopyForms(java.io.OutputStream os)
             throws DocumentException
Creates a new instance.

Parameters:
os - the output stream
Throws:
DocumentException - on error
Method Detail

addDocument

public void addDocument(PdfReader reader)
                 throws DocumentException,
                        java.io.IOException
Concatenates a PDF document.

Parameters:
reader - the PDF document
Throws:
DocumentException - on error
java.io.IOException

addDocument

public void addDocument(PdfReader reader,
                        java.util.List pagesToKeep)
                 throws DocumentException,
                        java.io.IOException
Concatenates a PDF document selecting the pages to keep. The pages are described as a List of Integer. The page ordering can be changed but no page repetitions are allowed.

Parameters:
reader - the PDF document
pagesToKeep - the pages to keep
Throws:
DocumentException - on error
java.io.IOException

addDocument

public void addDocument(PdfReader reader,
                        java.lang.String ranges)
                 throws DocumentException,
                        java.io.IOException
Concatenates a PDF document selecting the pages to keep. The pages are described as ranges. The page ordering can be changed but no page repetitions are allowed.

Parameters:
reader - the PDF document
ranges - the comma separated ranges as described in SequenceList
Throws:
DocumentException - on error
java.io.IOException

copyDocumentFields

public void copyDocumentFields(PdfReader reader)
                        throws DocumentException
Copies the form fields of this PDFDocument onto the PDF-Document which was added

Parameters:
reader - the PDF document
Throws:
DocumentException - on error

setEncryption

public void setEncryption(byte[] userPassword,
                          byte[] ownerPassword,
                          int permissions,
                          boolean strength128Bits)
                   throws DocumentException
Sets the encryption options for this document. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.

Parameters:
userPassword - the user password. Can be null or empty
ownerPassword - the owner password. Can be null or empty
permissions - the user permissions
strength128Bits - true for 128 bit key length, false for 40 bit key length
Throws:
DocumentException - if the document is already open

setEncryption

public void setEncryption(boolean strength,
                          java.lang.String userPassword,
                          java.lang.String ownerPassword,
                          int permissions)
                   throws DocumentException
Sets the encryption options for this document. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.

Parameters:
strength - true for 128 bit key length. false for 40 bit key length
userPassword - the user password. Can be null or empty
ownerPassword - the owner password. Can be null or empty
permissions - the user permissions
Throws:
DocumentException - if the document is already open

close

public void close()
Closes the output document.


open

public void open()
Opens the document. This is usually not needed as addDocument() will do it automatically.


addJavaScript

public void addJavaScript(java.lang.String js)
Adds JavaScript to the global document

Parameters:
js - the JavaScript

setOutlines

public void setOutlines(java.util.List outlines)
Sets the bookmarks. The list structure is defined in SimpleBookmark#.

Parameters:
outlines - the bookmarks or null to remove any

getWriter

public PdfWriter getWriter()
Gets the underlying PdfWriter.

Returns:
the underlying PdfWriter

isFullCompression

public boolean isFullCompression()
Gets the 1.5 compression status.

Returns:
true if the 1.5 compression is on

setFullCompression

public void setFullCompression()
Sets the document's compression to the new 1.5 mode with object streams and xref streams. It can be set at any time but once set it can't be unset.

If set before opening the document it will also set the pdf version to 1.5.


setEncryption

public void setEncryption(byte[] userPassword,
                          byte[] ownerPassword,
                          int permissions,
                          int encryptionType)
                   throws DocumentException
Description copied from interface: PdfEncryptionSettings
Sets the encryption options for this document. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.

Specified by:
setEncryption in interface PdfEncryptionSettings
Parameters:
userPassword - the user password. Can be null or empty
ownerPassword - the owner password. Can be null or empty
permissions - the user permissions
encryptionType - the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128. Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext
Throws:
DocumentException - if the document is already open
See Also:
PdfEncryptionSettings.setEncryption(byte[], byte[], int, int)

addViewerPreference

public void addViewerPreference(PdfName key,
                                PdfObject value)
Description copied from interface: PdfViewerPreferences
Adds a viewer preference.

setViewerPreferences

public void setViewerPreferences(int preferences)
Description copied from interface: PdfViewerPreferences
Sets the page layout and page mode preferences by ORing one or two of these constants.

For backward compatibility these values are also supported, but it's better to use method addViewerPreference(key, value) if you want to change the following preferences:

Specified by:
setViewerPreferences in interface PdfViewerPreferences
Parameters:
preferences - the viewer preferences
See Also:
PdfViewerPreferences.setViewerPreferences(int)

setEncryption

public void setEncryption(java.security.cert.Certificate[] certs,
                          int[] permissions,
                          int encryptionType)
                   throws DocumentException
Description copied from interface: PdfEncryptionSettings
Sets the certificate encryption options for this document. An array of one or more public certificates must be provided together with an array of the same size for the permissions for each certificate. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them. Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext

Specified by:
setEncryption in interface PdfEncryptionSettings
Parameters:
certs - the public certificates to be used for the encryption
permissions - the user permissions for each of the certificates
encryptionType - the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128.
Throws:
DocumentException - if the document is already open
See Also:
PdfEncryptionSettings.setEncryption(java.security.cert.Certificate[], int[], int)


iText 2.1.7