// Create to a pdf file stream FileOutputStream outputStream = null; try { outputStream = new FileOutputStream("SetSecurityOptionsToPDF.pdf"); } catch (FileNotFoundException e) { e.printStackTrace(); } // Create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); worksheet.getRange("A1").setValue("GrapeCity Documents for Excel"); worksheet.getRange("A1").getFont().setSize(25); //The security settings of pdf when converting excel to pdf. PdfSecurityOptions securityOptions = new PdfSecurityOptions(); //Sets the user password. securityOptions.setUserPassword("user"); //Sets the owner password. securityOptions.setOwnerPassword("owner"); //Allow to print pdf document. securityOptions.setPrintPermission(true); //Print the pdf document in high quality. securityOptions.setFullQualityPrintPermission(true); //Allow to copy or extract the content of the pdf document. securityOptions.setExtractContentPermission(true); //Allow to modify the pdf document. securityOptions.setModifyDocumentPermission(true); //Allow to insert, rotate, or delete pages and create bookmarks or thumbnail images of the pdf document. securityOptions.setAssembleDocumentPermission(true); //Allow to modify text annotations and fill the form fields of the pdf document. securityOptions.setModifyAnnotationsPermission(true); //Filling the form fields of the pdf document is not allowed. securityOptions.setFillFormsPermission(false); PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); //Sets the secutity settings of the pdf. pdfSaveOptions.setSecurityOptions(securityOptions); //Save the workbook into pdf file. workbook.save(outputStream, pdfSaveOptions); // Close the file stream try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); }
// Create to a pdf file stream var outputStream: FileOutputStream? = null try { outputStream = FileOutputStream("SetSecurityOptionsToPDF.pdf") } catch (e: FileNotFoundException) { e.printStackTrace() } // Create a new workbook var workbook = Workbook() val worksheet = workbook.worksheets.get(0) worksheet.getRange("A1").setValue("GrapeCity Documents for Excel") worksheet.getRange("A1").font.size = 25.0 //The security settings of pdf when converting excel to pdf. val securityOptions = PdfSecurityOptions() //Sets the user password. securityOptions.setUserPassword("user") //Sets the owner password. securityOptions.setOwnerPassword("owner") //Allow to print pdf document. securityOptions.printPermission = true //Print the pdf document in high quality. securityOptions.fullQualityPrintPermission = true //Allow to copy or extract the content of the pdf document. securityOptions.extractContentPermission = true //Allow to modify the pdf document. securityOptions.modifyDocumentPermission = true //Allow to insert, rotate, or delete pages and create bookmarks or thumbnail images of the pdf document. securityOptions.assembleDocumentPermission = true //Allow to modify text annotations and fill the form fields of the pdf document. securityOptions.modifyAnnotationsPermission = true //Filling the form fields of the pdf document is not allowed. securityOptions.fillFormsPermission = false val pdfSaveOptions = PdfSaveOptions() //Sets the secutity settings of the pdf. pdfSaveOptions.securityOptions = securityOptions //Save the workbook into pdf file. workbook.save(outputStream, pdfSaveOptions) // Close the file stream try { if(outputStream != null){ outputStream.close() } } catch (e: IOException) { e.printStackTrace() }