2.4.1. Single Notes Document Conversion

Here is the SWING PDF Converter JAVA API code to demonstrate single document conversion.
 

/** 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 a PDF file

 * and store it on your hard drive

 */

 

package com.swsoftware.pdfc.api.samples;

 

import com.swsoftware.pdfc.api.*;

import lotus.domino.*;

 

public class DocConvert {

 

      public static void main(String[] args) {

 

            Session s;

            Document doc = null;

            String server, dbPath, docID ;

 

            try {

                  NotesThread.sinitThread();

                  // Your notes ID password so a session can be created

                  s = NotesFactory.createSessionWithFullAccess("<YOUR PASSWORD>");

                  // the name of the server at which the database that contains the document being converted resides

                  server = "sw01" ;

                  //database path to notes database that contains document

                  dbPath = "Project\\PDF Converter\\Ver 2\\PDFConverterWorkVer2.nsf" ;     

                  // NoteID of document being created

                  docID = "1EBA" ;

 

                  SwPDFCreator pdfc = new SwPDFCreator(s);

                  SwPDFDocument pdfDoc ;

                 

                  if (pdfc.init("<LICENCE KEY>")) { // if the license key is valid

 

                         doc = s.getDatabase(server, dbPath).getDocumentByID(docID);                 

 

                        if (doc != null){

                              // 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();

            }

      }

 

}

Comments