[]
        
(Showing Draft Content)

Support Security Options

Sometimes, users need to secure their digital documents with user/owner passwords, print permission, content permission, annotation permission etc. PDF documents have always been the preferred format for sharing digital files among professionals. The GcExcel library supports Security Options while saving Excel spreadsheets to PDF files. It helps in securing a PDF Document by restricting the PDF’s access to unauthorized users as per the options specified.

With GcExcel's PdfSecurityOptions class, you can restrict access to your PDF document, while converting Excel spreadsheet to PDF document. You can choose through the following security properties in the PdfSecurityOptions class:

Properties

Description

UserPassword

Gets or sets the user password of the PDF document.

OwnerPassword

Gets or sets the owner password of the PDF document. This password is required to change the permissions for the PDF document.

PrintPermission

Gets or sets the permission to print the PDF document. The default value is true for this property.

FullQualityPrintPermission

Gets or sets the permission to print in high quality. The default value is true for this property, and it only works when PrintPermission property is set to true.

ExtractContentPermission

Gets or sets the permission to copy or extract content. The default value is true for this property.

ModifyDocumentPermission

Gets or sets the permission to modify the PDF document. The default value is true for this property.

AssembleDocumentPermission

Gets or sets the permission to insert, rotate or delete pages, and create bookmarks/thumbnail images. The default value is true for this property. If you want to prevent a user from inserting, rotating or deleting pages, you need to set ModifyDocumentPermission property to false as well.

ModifyAnnotationsPermission

Gets or sets the permission to modify text annotations and fill the form fields. The default value is true for this property.

FillFormsPermission

Gets or sets the permission to fill the form fields even if the ModifyAnnotationsPermission property returns false. The default value for this property is true. Note that if you want to prevent a user from filling interactive form fields, you need to set the ModifyAnnotationsPermission property to false.

Using Code

Refer to the following example to add security options while exporting Excel spreadsheets to PDF documents.

public void SavePDFPdfSecurityOptions()
{
    // Initialize workbook
    Workbook workbook = new Workbook();
    // Fetch default worksheet 
    IWorksheet worksheet = workbook.Worksheets[0];
    // Data
    object[,] data = new object[,]{
 {"Name", "City", "Birthday", "Sex", "Weight", "Height", "Age"},
 {"Bob", "NewYork", new DateTime(1968, 6, 8), "male", 80, 180, 56},
 {"Betty", "NewYork", new DateTime(1972, 7, 3), "female", 72, 168, 45},
 {"Gary", "NewYork", new DateTime(1964, 3, 2), "male", 71, 179, 50},
 {"Hunk", "Washington", new DateTime(1972, 8, 8), "male", 80, 171, 59},
 {"Cherry", "Washington", new DateTime(1986, 2, 2), "female", 58, 161, 34},
 {"Coco", "Virginia", new DateTime(1982, 12, 12), "female", 58, 181, 45},
 {"Lance", "Chicago", new DateTime(1962, 3, 12), "female", 49, 160, 57},
 { "Eva", "Washington", new DateTime(1993, 2, 5), "female", 71, 180, 81}};
    // Set data
    worksheet.Range["A1:G9"].Value = data;

    //The security settings of pdf when converting excel to pdf
    PdfSecurityOptions securityOptions = new PdfSecurityOptions();
    //Sets the user password
    securityOptions.UserPassword = "user";
    //Sets the owner password
    securityOptions.OwnerPassword = "owner";
    //Printing the pdf document is not allowed
    securityOptions.PrintPermission = false;
    //Filling the form fields of the pdf document is not allowed
    securityOptions.FillFormsPermission = false;

    PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
    //Sets the security settings of the pdf
    pdfSaveOptions.SecurityOptions = securityOptions;

    // Saving workbook to PDF
    workbook.Save(@"4-SavePDFPdfSecurityOptions.pdf", pdfSaveOptions);
}

Note: GcExcel uses RC4 encryption with key from 40 to 128 bit length and allows to define additional permission flags.