Aspose.Pdf

Allow or Disallow Privileges on PDF Document

Aspose.Pdf continues to provide more security features to protect the use of your valuable information in PDF documents. Using Aspose.Pdf , developers can set several privileges on the PDF documents to control their use.

 

Security class in Aspose.Pdf has several properties to set different kinds of privileges on the PDF documents as given below:

 

 

All of these above privileges related properties are of boolean types and can be controlled by setting to true or false. These above properties allow developers to restrict or allow annotations modification, contents modification, copying the content, degraded printing, document assembling, form filling, printing the pages and screen readers.

 

Note: All above boolean properties are by default, true.

 

Code Snippet

 

[C#]

 

//Instantiate Pdf instance by calling its empty constructor

Pdf pdf1 = new Pdf();

 

//Assign a security instance to Pdf object           

pdf1.Security = new Security();

 

//Restrict annotation modification

pdf1.Security.IsAnnotationsModifyingAllowed = false;

 

//Restrict contents modification

pdf1.Security.IsContentsModifyingAllowed = false;

 

//Restrict copying the data

pdf1.Security.IsCopyingAllowed = false;

 

//Allow to print the document

pdf1.Security.IsPrintingAllowed = true;

 

//Restrict form filling

pdf1.Security.IsFormFillingAllowed = false;

 

//Add a section in the Pdf

Section sec1 = pdf1.Sections.Add();

 

//Create a text paragraph                          

Text text1 = new Text(sec1,"this is text content");

 

//Set the top maring of text paragraph to 30

text1.Margin.Top = 30;

 

//Add the text paragraph to the section

sec1.Paragraphs.Add(text1);

 

//Save the Pdf                           

pdf1.Save(...);

 

[VB.NET]

 

'Instantiate Pdf instance by calling its empty constructor

Dim pdf1 As Pdf =  New Pdf()

 

'Assign a security instance to Pdf object

pdf1.Security = New Security()

 

'Restrict annotation modification

pdf1.Security.IsAnnotationsModifyingAllowed = False

 

'Restrict contents modification

pdf1.Security.IsContentsModifyingAllowed = False

 

'Restrict copying the data

pdf1.Security.IsCopyingAllowed = False

 

'Allow to print the document

pdf1.Security.IsPrintingAllowed = True

 

'Restrict form filling

pdf1.Security.IsFormFillingAllowed = False

 

'Add a section in the Pdf

Dim sec1 As Section =  pdf1.Sections.Add()

 

'Create a text paragraph

Dim text1 As Text =  New Text(sec1,"this is text content")

 

'Set the top maring of text paragraph to 30

text1.Margin.Top = 30

 

'Add the text paragraph to the section

sec1.Paragraphs.Add(text1)

 

'Save the Pdf

pdf1.Save(...)

 

[JAVA]

 

//Instantiate Pdf object by calling its empty constructor

Pdf pdf1 = new Pdf();

 

//Assign a security instance to Pdf object

pdf1.setSecurity( new Security() );

 

//Restrict annotation modification

pdf1.getSecurity().setAnnotationsModifyingAllowed(false);                                         

 

//Restrict contents modification

pdf1.getSecurity().setContentsModifyingAllowed(false);

 

//Restrict copying the data

pdf1.getSecurity().setCopyingAllowed(false);

 

//Allow to print the document

pdf1.getSecurity().setPrintingAllowed(true);

 

//Restrict form filling

pdf1.getSecurity().setFormFillingAllowed(false);

 

//Add a section in the Pdf

Section sec1 = pdf1.getSections().add();

 

//Create a text paragraph

Text text1 = new Text(sec1,"this is text content");

 

//Set the top maring of text paragraph to 30

text1.getMargin().setTop(30);

 

//Add the text paragraph to the section                                         

sec1.getParagraphs().add(text1);

 

// Save the Pdf

FileOutputStream fileOut = new FileOutputStream(new File(...));

pdf1.save(fileOut);

 

[XML]

 

<?xml version="1.0" encoding="utf-8" ?>

  <Pdf xmlns="Aspose.Pdf" IsAnnotationsModifyingAllowed="true"

        IsContentsModifyingAllowed="false" IsCopyingAllowed="false"

        IsPrintingAllowed="true" IsFormFillingAllowed="false">

   <Section>

           <Text MarginTop="30">

                   <Segment>this is text content</Segment>

           </Text>

   </Section>

  </Pdf>