Class PdfEncryptor
- Namespace
- iTextSharp.text.pdf
- Assembly
- iTextSharp.LGPLv2.Core.dll
This class takes any PDF and returns exactly the same but encrypted. All the content, links, outlines, etc, are kept. It is also possible to change the info dictionary.
public static class PdfEncryptor
- Inheritance
-
PdfEncryptor
- Inherited Members
Methods
Encrypt(PdfReader, Stream, bool, string, string, int)
Entry point to encrypt a PDF document. The encryption parameters are the same as in PdfWriter . 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. @throws DocumentException on error @throws IOException on error
public static void Encrypt(PdfReader reader, Stream os, bool strength, string userPassword, string ownerPassword, int permissions)
Parameters
reader
PdfReaderthe read PDF
os
Streamthe output destination
strength
booltrue for 128 bit key length, false for 40 bit key length
userPassword
stringthe user password. Can be null or empty
ownerPassword
stringthe owner password. Can be null or empty
permissions
intthe user permissions
Encrypt(PdfReader, Stream, bool, string, string, int, INullValueDictionary<string, string>)
Entry point to encrypt a PDF document. The encryption parameters are the same as in PdfWriter . 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. the info dictionary. Entries with null values delete the key in the original info dictionary @throws DocumentException on error @throws IOException on error
public static void Encrypt(PdfReader reader, Stream os, bool strength, string userPassword, string ownerPassword, int permissions, INullValueDictionary<string, string> newInfo)
Parameters
reader
PdfReaderthe read PDF
os
Streamthe output destination
strength
booltrue for 128 bit key length, false for 40 bit key length
userPassword
stringthe user password. Can be null or empty
ownerPassword
stringthe owner password. Can be null or empty
permissions
intthe user permissions
newInfo
INullValueDictionary<string, string>an optional String map to add or change
Encrypt(PdfReader, Stream, byte[], byte[], int, bool)
Entry point to encrypt a PDF document. The encryption parameters are the same as in PdfWriter . 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. @throws DocumentException on error @throws IOException on error
public static void Encrypt(PdfReader reader, Stream os, byte[] userPassword, byte[] ownerPassword, int permissions, bool strength128Bits)
Parameters
reader
PdfReaderthe read PDF
os
Streamthe output destination
userPassword
byte[]the user password. Can be null or empty
ownerPassword
byte[]the owner password. Can be null or empty
permissions
intthe user permissions
strength128Bits
booltrue for 128 bit key length, false for 40 bit key length
Encrypt(PdfReader, Stream, byte[], byte[], int, bool, INullValueDictionary<string, string>)
Entry point to encrypt a PDF document. The encryption parameters are the same as in PdfWriter . 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. the info dictionary. Entries with null values delete the key in the original info dictionary @throws DocumentException on error @throws IOException on error
public static void Encrypt(PdfReader reader, Stream os, byte[] userPassword, byte[] ownerPassword, int permissions, bool strength128Bits, INullValueDictionary<string, string> newInfo)
Parameters
reader
PdfReaderthe read PDF
os
Streamthe output destination
userPassword
byte[]the user password. Can be null or empty
ownerPassword
byte[]the owner password. Can be null or empty
permissions
intthe user permissions
strength128Bits
booltrue for 128 bit key length, false for 40 bit key length
newInfo
INullValueDictionary<string, string>an optional String map to add or change
Encrypt(PdfReader, Stream, int, string, string, int)
Entry point to encrypt a PDF document. The encryption parameters are the same as in PdfWriter . 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. Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext values delete the key in the original info dictionary @throws DocumentException on error @throws IOException on error
public static void Encrypt(PdfReader reader, Stream os, int type, string userPassword, string ownerPassword, int permissions)
Parameters
reader
PdfReaderthe read PDF
os
Streamthe output destination
type
intthe type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128.
userPassword
stringthe user password. Can be null or empty
ownerPassword
stringthe owner password. Can be null or empty
permissions
intthe user permissions
Encrypt(PdfReader, Stream, int, string, string, int, INullValueDictionary<string, string>)
Entry point to encrypt a PDF document. The encryption parameters are the same as in PdfWriter . 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. Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext the info dictionary. Entries with null values delete the key in the original info dictionary @throws DocumentException on error @throws IOException on error
public static void Encrypt(PdfReader reader, Stream os, int type, string userPassword, string ownerPassword, int permissions, INullValueDictionary<string, string> newInfo)
Parameters
reader
PdfReaderthe read PDF
os
Streamthe output destination
type
intthe type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128.
userPassword
stringthe user password. Can be null or empty
ownerPassword
stringthe owner password. Can be null or empty
permissions
intthe user permissions
newInfo
INullValueDictionary<string, string>an optional String map to add or change
GetPermissionsVerbose(int)
Give you a verbose analysis of the permissions.
public static string GetPermissionsVerbose(int permissions)
Parameters
permissions
intthe permissions value of a PDF file
Returns
- string
a String that explains the meaning of the permissions value
IsAssemblyAllowed(int)
Tells you if document assembly is allowed. @since 2.0.7
public static bool IsAssemblyAllowed(int permissions)
Parameters
permissions
intthe permissions value of a PDF file
Returns
- bool
true if document assembly is allowed
IsCopyAllowed(int)
Tells you if copying is allowed. @since 2.0.7
public static bool IsCopyAllowed(int permissions)
Parameters
permissions
intthe permissions value of a PDF file
Returns
- bool
true if copying is allowed
IsDegradedPrintingAllowed(int)
Tells you if degraded printing is allowed. @since 2.0.7
public static bool IsDegradedPrintingAllowed(int permissions)
Parameters
permissions
intthe permissions value of a PDF file
Returns
- bool
true if degraded printing is allowed
IsFillInAllowed(int)
Tells you if filling in fields is allowed. @since 2.0.7
public static bool IsFillInAllowed(int permissions)
Parameters
permissions
intthe permissions value of a PDF file
Returns
- bool
true if filling in fields is allowed
IsModifyAnnotationsAllowed(int)
Tells you if modifying annotations is allowed. @since 2.0.7
public static bool IsModifyAnnotationsAllowed(int permissions)
Parameters
permissions
intthe permissions value of a PDF file
Returns
- bool
true if modifying annotations is allowed
IsModifyContentsAllowed(int)
Tells you if modifying content is allowed. @since 2.0.7
public static bool IsModifyContentsAllowed(int permissions)
Parameters
permissions
intthe permissions value of a PDF file
Returns
- bool
true if modifying content is allowed
IsPrintingAllowed(int)
Tells you if printing is allowed. @since 2.0.7
public static bool IsPrintingAllowed(int permissions)
Parameters
permissions
intthe permissions value of a PDF file
Returns
- bool
true if printing is allowed
IsScreenReadersAllowed(int)
Tells you if repurposing for screenreaders is allowed. @since 2.0.7
public static bool IsScreenReadersAllowed(int permissions)
Parameters
permissions
intthe permissions value of a PDF file
Returns
- bool
true if repurposing for screenreaders is allowed