Articles in this section
Category / Section

How to disallow text copying and printing in PDF using C# and VB.NET?

2 mins read

Syncfusion Essential PDF is the .NET PDF library used to create, read, and edit PDF documents. Using this library, you can disallow text copying and printing the PDF document.

Steps to disallow text copying and printing PDF file programmatically:

  1. Create a new C# console application project. Create new console application in .NET PDF library
  2. Install the Syncfusion.Pdf.WinForms NuGet package as reference to your .NET Framework applications from NuGet.org. Install Nuget packages in .NET PDF library
  3. Include the following namespaces in the Program.cs file.

C#

using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;

 

VB.NET

Imports Syncfusion.Pdf.Parsing
Imports Syncfusion.Pdf.Security

 

  1. Use the following C# or VB.NET code snippet to disallow text copying and printing in a PDF document.

C#

//Load the existing PDF document
PdfLoadedDocument document = new PdfLoadedDocument("input.pdf");
 
//Set the user password 
document.Security.UserPassword = "user";
 
//Set the owner password
document.Security.OwnerPassword = "owner";
 
//Set permission to default to disallowing text copy and printing
document.Security.Permissions = PdfPermissionsFlags.Default;
 
//Save the document
document.Save("output.pdf");
 
//Close the document
document.Close(true);

       

VB.NET

'Load the existing PDF document
Dim document As New PdfLoadedDocument("input.pdf")
 
'Set the user password 
 document.Security.UserPassword = "user"
 
'Set the owner password
document.Security.OwnerPassword = "owner"
 
'Set permission to default to disallowing text copy and printing
document.Security.Permissions = PdfPermissionsFlags.Default 
 
'Save the document
document.Save("output.pdf")
 
'Close the document
document.Close(True)

 

By executing the program, you will get the PDF document as follows. printing in .NET PDF library

A complete working sample can be downloaded from SecuritySample.zip

Note:

You can also disallow the text copying and printing without using document open password by removing the following code.

 

//Set the user password 
document.Security.UserPassword = "user";

 

Take a moment to peruse the documentation, where you can find other options like encrypting, decrypting and digitalizing a PDF document.

Refer here to explore the rich set of Syncfusion Essential PDF features.

Note:

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

 

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