This concise tutorial teaches you how to convert XLSX to PDF having restricted permissions in java. You can set a variety of permissions and restrictions before converting XLSX file to PDF having restricted permissions in java. Ultimately this workbook is saved as a PDF file that can be opened in any viewer or browser with the allowed permissions.
Steps to Convert XLSX to PDF Having Restricted Permissions in Java
- Add Aspose.Cells library reference to the project using Maven repository
- Add a reference to Workbook, PdfSaveOptions, and PdfSecurityOptions classes using the Import keyword
- Load the sample XLSX file that is to be converted to PDF
- Initialize the PdfSaveOptions to set security options
- Set restrictions on copy/extract contents and printing of the PDF in Java
- Save the workbook as a PDF with the restricted permissions
During this short step-by-step tutorial, we see that first, we load an XLSX file that is to be converted to PDF and then set restrictions to the PDF exported from the XLSX file like a restriction to copy or extract text from PDF or restriction to print the PDF. Once the required restrictions are applied, the workbook is saved as a PDF having these restrictions.
Code to Convert XLSX File to PDF Having Restricted Permissions in Java
In this sample code, we used PdfSaveOptions class object for setting the restrictions on PDF converted from an XLSX. This class has PdfSecurityOptions parameter that actually contains options to set the restrictions. At the end of the process, this workbook is saved as a PDF using the PdfSaveOptions object as a parameter to the save() function.
We have converted the XLSX file to PDF however if you want to save the excel file to some other format, refer to the article on how to convert Excel to XPS in Java. Also, note that there is no need to install MS Excel or use Interop to run this code.