Passwords, Security & Metadata
IronPDF provides developers with strong PDF security options, supporting the customization and setting of PDF metadata, passwords, permissions, and more. With IronPDF's passwords, security, and metadata options, you can create custom permissions and security levels to fit the need of your PDF document. This is done thanks to the use of classes such as the SecuritySettings
and MetaData
classes. Some options include limiting the PDF documents to be unprintable, setting them to read-only, and 128-bit encryption, and password protection of your PDF documents.
Setting custom metadata works by implementing the MetaData class to access the various PDF metadata options, and setting them with your customized values. This includes changing the author, keywords, modified data, and more. Setting custom security settings includes the ability to set custom user and owner passwords, printing permissions, read-only mode, and more.
5 Steps to setting PDF passwords, metadata, and security
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");
System.Collections.Generic.List<string> metadatakeys = pdf.MetaData.Keys();
var metadatakeys = pdf.MetaData.Keys();
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
In order to begin customizing the security of your PDF documents, you must first load in an existing PDF or create a new one. Here, we have loaded an existing password-protected PDF document, where we have input the password needed to open the PDF document. Once the PDF is loaded, we then use pdf.MetaData.Keys();
to get the PDF's current metadata. To remove existing PDF metadata values, use the RemoveMetaDataKey
method. To begin setting new metadata value, use pdf.MetaData.metadatafield (e.g. pdf.MetaData.Keywords
), and then just assign the new value to it. Metadata fields such as Title and Keywords take string values, whereas the ModifiedData field takes datetime values.
Next, we have set new Security settings using the SecuritySettings class. As you can see, there are a variety of settings that you can set here. This gives you full control over the permissions and security levels for each PDF document you work with. To access these settings, you just need to make sure you use pdf.SecuritySettings
, followed by the setting you want to adjust. For example, the MakePdfDocumentReadOnly
property sets the PDF document to be read-only, encrypting the content at 128-bit. Other options for SecuritySettings include:
- AllowUserAnnotations: Controls whether or not users can annotate the PDF.
- AllowUserPrinting: Controls printing permissions for the document.
- AllowUserFormData: Sets the permissions for whether users can fill-in forms.
- OwnerPassword: Sets the owner password for the PDF, which is used to disable or enable the other security settings
- UserPassword: Sets the user password for the PDF, which must be entered in order to open or print the document.
Once you have set the custom metadata, passwords, and security settings for your PDF document, use the pdf.SaveAs
method to save your PDF to a specified location.
Click here to view the How-to-Guide, including examples, sample code and files >