Articles in this section
Category / Section

How to restrict printing and copying of PDF document for security documents

3 mins read

Document Security

To restrict all the permissions in a PDF document, you need to set the PdfPermissionsFlags as default, and at least the document needs to be protected using an owner password.

C#

PdfDocument document = new PdfDocument();
 
// Document security
PdfSecurity security = document.Security;
security.OwnerPassword = "syncfusion";
security.Permissions = PdfPermissionsFlags.Default;

 

In order to restrict particular permissions in a PDF document, the document needs to be protected using an owner password. Please find the below code snippet to restrict particular permissions.

C#

PdfDocument document = new PdfDocument();
 
// Document security
PdfSecurity security = document.Security;
security.OwnerPassword = "syncfusion";
security.Permissions = ~(PdfPermissionsFlags.CopyContent | PdfPermissionsFlags.Print);

 

By using below code snippet, we enable the permission of PDF document from printing, editing and copying with owner password.

C#

PdfDocument document = new PdfDocument();
 
// Document security
PdfSecurity security = document.Security;
security.OwnerPassword = "syncfusion";
security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.AccessibilityCopyContent;

 

Restrict Copying and Printing permission of the PDF document can be shown in the below code snippet.

C#

// Create a new PDF document.
PdfDocument document = new PdfDocument();
 
// Create a new page
PdfPage page = document.Pages.Add();
 
PdfGraphics graphics = page.Graphics;
PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold);
PdfBrush brush = PdfBrushes.Black;
 
// Document security.
PdfSecurity security = document.Security;
 
// Specifies key size and encryption algorithm using 256-bit key in AES mode.
security.KeySize = PdfEncryptionKeySize.Key256Bit;
security.Algorithm = PdfEncryptionAlgorithm.AES;
security.OwnerPassword = "syncfusion";
 
// It restrict printing and copying of PDF document
security.Permissions = ~(PdfPermissionsFlags.CopyContent | PdfPermissionsFlags.Print);
 
graphics.DrawString("This document is protected with owner password", font, brush, new PointF(0, 40));

 

Sample Link :

https://www.syncfusion.com/downloads/support/directtrac/general/ze/SignatureSample1209667260


Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.

 

Conclusion

I hope you enjoyed learning about How to restrict printing and copying of PDF document for security documents.

You can refer to our PDF feature tour page to learn about its other groundbreaking feature representations. You can also explore our documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied