In this topic you will gain understanding about how to convert XLSX to PDF having restricted permissions using C#. Sometimes it happens that you want to pass on information to others but also want to impose some restrictions like restrict them to copy or print it. The following steps will guide you to generate PDF having restricted permissions from XLSX using C#.
Steps to Convert XLSX to PDF having Restricted Permissions using C#
- Install Aspose.Cells for .NET package using NuGet Package Manager
- Import Aspose.Cells in the beginning with using directive
- Initialize the license to avoid trial version message
- Load XLSX file into Workbook instance that is to be converted to PDF
- For setting the parameters of output PDF file, initialize PDFSaveOptions instance
- To set security options, initialize the SecurityOptions parameter in PDFSaveOptions instance
- Set the copy/extract and print restrictions in the SecurityOptions parameter
- Save the workbook using the PDFSaveOptions settings
The following example demonstrates the process to export Excel to PDF having restricted permissions using C#. Here a sample XLSX file is loaded and then it is saved as PDF having restrictions for the user to copy/extract text from it or print it.
Sample Code for Excel to Restricted Permissions PDF using C#
The above code generates PDF with few restrictions. You can add more restrictions like requirement of password to open by setting PdfSaveOptions.SecurityOptions.UserPassword. Note that the copy/extract and print restrictions will remain effective and UserPassword is just for opening the PDF. If you want to allow the user to open this PDF file without restrictions, set the PdfSaveOptions.SecurityOptions.OwnerPassword by entering which the user will be able to copy/extract or print this PDF file. You can perform other conversions also like convert Excel to XPS in C#.