• small extention

    By Alexander Kogan 2 decades ago

    // Simple method to save mails as PDF file - thanks

    import lotus.domino.*;

    import java.io.FileOutputStream;

    import java.util.Vector;

    import com.lowagie.text.Paragraph;

    import com.lowagie.text.Chapter;

    import com.lowagie.text.Font;

    import com.lowagie.text.List;

    import com.lowagie.text.Table;

    import com.lowagie.text.Document;

    import com.lowagie.text.DocumentException;

    import com.lowagie.text.pdf.PdfWriter;

    public class JavaAgent extends AgentBase {


    public void NotesMain() {<br/>
    


        try {<br/>
            Session session = getSession();<br/>
            <br/>
            AgentContext agentContext = session.getAgentContext();<br/>
    


           //get document's object<br/>
            Database db = agentContext.getCurrentDatabase();<br/>
            DocumentCollection dc = agentContext.getUnprocessedDocuments();<br/>
           // use the full class name to avoid conflict with com.lowagie.text.Document class<br/>
            lotus.domino.Document doc = dc.getFirstDocument();<br/>
            RichTextItem body = (RichTextItem)doc.getFirstItem(&quot;Body&quot;);<br/>
           //create document's object<br/>
            Document document = new Document();<br/>
            try {<br/>
                PdfWriter.getInstance(document, new FileOutputStream(&quot;c:\\CreatePDFInlotus.pdf&quot;));<br/>
               //open doc for r/w<br/>
                document.open();<br/>
               //add text<br/>
                document.add(new Paragraph (&quot;Subject: &quot; + doc.getItemValueString(&quot;Subject&quot;)));<br/>
                Vector times = doc.getItemValueDateTimeArray(&quot;PostedDate&quot;);<br/>
                Object time = times.elementAt(0);<br/>
                 document.add(new Paragraph (&quot;PostedDate: &quot; +  ((DateTime)time).getLocalTime()));<br/>
                document.add(new Paragraph (&quot;From: &quot; + &quot;   &quot; + doc.getItemValueString(&quot;From&quot;)));<br/>
                document.add(new Paragraph (&quot;To  : &quot; + &quot;   &quot; + doc.getItemValueString(&quot;SendTo&quot;)));<br/>
                document.add(new Paragraph (&quot;CopyTo  : &quot; + &quot;   &quot; + doc.getItemValueString(&quot;CopyTo&quot;)));<br/>
                document.add(new Paragraph (&quot;__________________________________________________________________&quot;));<br/>
                document.add(new Paragraph (body.getFormattedText(false, 0, 0)));<br/>
               //if error<br/>
                } catch (DocumentException de) {<br/>
                    System.err.println(de.getMessage());<br/>
                }<br/>
                <br/>
                document.close();<br/>
                body.addNewLine(2);<br/>
                body.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null, &quot;c:\\CreatePDFInlotus.pdf&quot;, null);<br/>
                doc.save(true, true);<br/>
        } catch(Exception e) {<br/>
            e.printStackTrace();<br/>
        }<br/>
    }<br/>
    

    }