// 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("Body");<br/>
//create document's object<br/>
Document document = new Document();<br/>
try {<br/>
PdfWriter.getInstance(document, new FileOutputStream("c:\\CreatePDFInlotus.pdf"));<br/>
//open doc for r/w<br/>
document.open();<br/>
//add text<br/>
document.add(new Paragraph ("Subject: " + doc.getItemValueString("Subject")));<br/>
Vector times = doc.getItemValueDateTimeArray("PostedDate");<br/>
Object time = times.elementAt(0);<br/>
document.add(new Paragraph ("PostedDate: " + ((DateTime)time).getLocalTime()));<br/>
document.add(new Paragraph ("From: " + " " + doc.getItemValueString("From")));<br/>
document.add(new Paragraph ("To : " + " " + doc.getItemValueString("SendTo")));<br/>
document.add(new Paragraph ("CopyTo : " + " " + doc.getItemValueString("CopyTo")));<br/>
document.add(new Paragraph ("__________________________________________________________________"));<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, "c:\\CreatePDFInlotus.pdf", null);<br/>
doc.save(true, true);<br/>
} catch(Exception e) {<br/>
e.printStackTrace();<br/>
}<br/>
}<br/>
}