This is a bit more advanced sample that shows how to set PDF settings and protect the generated PDF from printing and unauthorized opening. User is required to enter a password to open a PDF file and it has prohibited printing.
/** SWING Software * http://www.swingsoftware.com * * This sample demonstrates how you can use SWING PDF Converter JAVA API to convert a single Lotus Notes Document to PDF and * set advanced PDF settings, using the SwPDFSettings class, to protect the generated PDF document. */
package com.swsoftware.pdfc.api.samples;
import lotus.domino.Document; import lotus.domino.NotesException; import lotus.domino.NotesFactory; import lotus.domino.NotesThread; import lotus.domino.Session;
import com.swsoftware.pdfc.api.SwPDFCreator; import com.swsoftware.pdfc.api.SwPDFDocument; import com.swsoftware.pdfc.api.SwPDFSettings;
public class SecureDocConvert {
public static void main(String[] args) {
Session s; Document doc = null; String server, dbPath, docID ;
try { NotesThread.sinitThread(); s = NotesFactory.createSessionWithFullAccess("<YOUR PASSWORD>"); server = "sw01" ; dbPath = "Project\\PDF Converter\\Ver 2\\PDFConverterWorkVer2.nsf" ; docID = "1EBA" ;
SwPDFCreator pdfc = new SwPDFCreator(s); SwPDFDocument pdfDoc ; SwPDFSettings pdfSet = new SwPDFSettings();
if (pdfc.init("<LICENCE KEY>")) { // if the license key is valid
doc = s.getDatabase(server, dbPath).getDocumentByID(docID);
if (doc != null){
// set PDF options pdfSet.setEnable128bitEncryption(true); // enable encryption of generated PDF pdfSet.setEnablePrinting(false); // disable printing of generated PDF pdfSet.setUserPassword("password"); // user password required to open a generated PDF pdfSet.setMasterPassword("password"); // master password required to set PDF restrictions pdfc.setPDFSettings(pdfSet); // apply PDF settings
// Convert Notes Document to PDF pdfDoc = pdfc.processDocument(doc); System.out.println("File saved to: " + pdfDoc.SaveToFile("C:\\result.pdf")); } }
//Cleanup if (doc != null) doc.recycle(); doc = null; if (s != null) s.recycle(); s = null; pdfc = null; pdfDoc = null;
} catch (NotesException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally{ NotesThread.stermThread(); } }
} |