// Create a pdf file stream FileOutputStream outputStream = null; try { outputStream = new FileOutputStream("SetDocumentPropertiesToPDF.pdf"); } catch (FileNotFoundException e) { e.printStackTrace(); } // Create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); worksheet.getRange("A1").setValue("Document Solutions for Excel"); worksheet.getRange("A1").getFont().setSize(25); DocumentProperties documentProperties = new DocumentProperties(); //Sets the name of the person that created the PDF document. documentProperties.setAuthor("Jaime Smith"); //Sets the title of the PDF document. documentProperties.setTitle("Document Info Sample"); //Set the PDF version. documentProperties.setPdfVersion(1.5f); //Set the subject of the PDF document. documentProperties.setSubject("DocumentInfo"); //Set the keyword associated with the PDF document. documentProperties.setKeywords("Keyword1"); //Set the creation date and time of the PDF document. documentProperties.setCreationDate(new GregorianCalendar(2019,5,24)); //Set the date and time the PDF document was most recently modified. documentProperties.setModifyDate(new GregorianCalendar(2020,5,24)); //Set the name of the application that created the original PDF document. documentProperties.setCreator("Creator"); //Set the name of the application that created the PDF document. documentProperties.setProducer("Producer"); PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); //Sets the document properties of the pdf. pdfSaveOptions.setDocumentProperties(documentProperties); //Save the workbook into pdf file. workbook.save(outputStream, pdfSaveOptions); // Close the file stream try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); }
// Create a pdf file stream FileOutputStream("SetDocumentPropertiesToPDF.pdf").use { outputStream -> // Create a new workbook var workbook = Workbook() val worksheet = workbook.worksheets.get(0) worksheet.getRange("A1").setValue("Document Solutions for Excel") worksheet.getRange("A1").font.size = 25.0 val documentProperties = DocumentProperties() //Sets the name of the person that created the PDF document. documentProperties.setAuthor("Jaime Smith") //Sets the title of the PDF document. documentProperties.setTitle("Document Info Sample") //Set the PDF version. documentProperties.pdfVersion = 1.5f //Set the subject of the PDF document. documentProperties.setSubject("DocumentInfo") //Set the keyword associated with the PDF document. documentProperties.setKeywords("Keyword1") //Set the creation date and time of the PDF document. documentProperties.creationDate = GregorianCalendar(2019, 5, 24) //Set the date and time the PDF document was most recently modified. documentProperties.modifyDate = GregorianCalendar(2020, 5, 24) //Set the name of the application that created the original PDF document. documentProperties.setCreator("Creator") //Set the name of the application that created the PDF document. documentProperties.setProducer("Producer") val pdfSaveOptions = PdfSaveOptions() //Sets the document properties of the pdf. pdfSaveOptions.documentProperties = documentProperties //Save the workbook into pdf file. workbook.save(outputStream, pdfSaveOptions) // End using the file stream }