Knowledgebase (2311)
Children categories
C#/VB.NET: Change Security Permissions of PDF Documents
2022-09-29 07:38:00 Written by AdministratorWhen you protect your PDF documents with passwords you can optionally specify a set of permissions. The permissions determine how users can interact with the file. For example, you can apply permissions to your document to prohibit the user from printing or using cut and paste operations. This article demonstrates how to change security permissions of PDF documents using Spire.PDF for .NET in C# and VB.NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Change Security Permissions of a PDF Document
The following are the steps to apply security permissions to a PDF document using Spire.PDF for .NET.
- Create a PdfDocument object.
- Load a sample PDF file using PdfDocument.LoadFileFile() method.
- Specify open password and permission password. The open password can be set to empty so that the generated document will not require a password to open.
- Encrypt the document with the open password and permission password, and set the security permissions using PdfDocument.Security.Encypt() method. This method takes PdfPermissionsFlags enumeration as a parameter, which defines user access permissions for an encrypted document.
- Save the document to another PDF file using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Security;
namespace ChangeSecurityPermission
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a sample PDF file
doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");
//Specify open password
string openPsd = string.Empty;
//Specify permission password
string permissionPsd = "e-iceblue";
//Encrypt the document with open password and permission password, and set the permissions and encryption key size
PdfSecurityPolicy securityPolicy = new PdfPasswordSecurityPolicy(openPsd, permissionPsd);
// Set the encryption algorithm to AES 128-bit
securityPolicy.EncryptionAlgorithm = PdfEncryptionAlgorithm.AES_128;
// Allow printing of the document
securityPolicy.DocumentPrivilege.AllowPrint = true;
// Allow filling form fields in the document
securityPolicy.DocumentPrivilege.AllowFillFormFields = true;
doc.Encrypt(securityPolicy);
//Save the document to another PDF file
doc.SaveToFile("SecurityPermissions.pdf");
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
How to split text into two columns and add line between them
2015-05-28 08:51:50 Written by AdministratorColumns are widely used to set page layout, for which could split text into two or more columns so that the text could flow from one column to the next on the same page. Using Spire.Doc, we could achieve this feature and add a line between columns at the same time. This article is going to introduce how to split text into two columns and add line between them.
Note: please download the latest version of Spire.Doc and add Spire.Doc .dll as reference of Visual Studio.
Step 1: Create a new document and load from file
Document document = new Document();
document.LoadFromFile("S.docx");
Step 2: Add a column to section one, set the width of columns and the spacing between columns. Here we set width as 100f and spacing as 20f.
document.Sections[0].AddColumn(100f, 20f);
Step 3: Add a line between the two columns
document.Sections[0].PageSetup.ColumnsLineBetween = true;
Step 4: Save the document and launch to see effects
document.SaveToFile("result.docx",FileFormat.Docx2013);
System.Diagnostics.Process.Start("result.docx");
Before adding the columns:

Effects:

Full Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Doc;
namespace Column
{
class Program
{
static void Main(string[] args)
{
Document document = new Document();
document.LoadFromFile("S.docx");
document.Sections[0].AddColumn(100f, 20f);
document.Sections[0].PageSetup.ColumnsLineBetween = true;
document.SaveToFile("result.docx",FileFormat.Docx2013);
System.Diagnostics.Process.Start("result.docx");
}
}
}
Text Box has been widely used in word documents to present additional information to readers. As a powerful and easy to use .NET word component, Spire.Doc has powerful function to work with text box. We have already showed you how to insert text box to word document and extract Text from Text Boxes in Word document. In this article let's see how to remove text box from word document in C#.
Spire.Doc supports to remove the particular text box or clear all the text boxes from the word documents. We will show you the details as below. Firstly, check the original word document contains three text boxes on it.

Here comes to the steps of how to remove the text box from word document by using the class of TextBoxes.
Step 1: Create a new document and load from file.
Document Doc = new Document();
Doc.LoadFromFile("Sample.docx");
Step 2: Remove the first text box by using the class of TextBoxes.
Doc.TextBoxes.RemoveAt(0);
Step 3: Save and launch the file.
Doc.SaveToFile("result.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("result.docx");
Effective screenshot:

If you want to clear all the text boxes at one time, the following code snippet will fulfill it.
Screenshot after clear all the text boxes:
Doc.TextBoxes.Clear();

Full codes:
namespace Removetextbox
{
class Program
{
static void Main(string[] args)
{
Document Doc = new Document();
Doc.LoadFromFile("Sample.docx");
Doc.TextBoxes.RemoveAt(0);
//Doc.TextBoxes.Clear();
Doc.SaveToFile("result.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("result.docx");
}
}
}