Hey all,
Found lots of help on this site to get me started but I really am quite lost. If appropriate, tell me (politely pls) to go learn some more ![]()
Here is the scenario…
-Only for use from the notes client.
-Java agent is being called by LS via a form action.
-I pass in the NoteID (agent.run) and get a handle on the backend doc. for processing (was able in early test to use doc context)
-I have successfully added the itext207.jar to my agent
-I can create very nice tables and add content
-I can save the resulting pdf to a notes document
GOALS:
-add a header and footer on each page (table of data to be repeated for both)
-pagenumbers
-eventually will want to get a document collection and write variable number of rows of data to the pdf
CODE:
Here is the basis of the Java agent: removed most of the content to help shorten it.
import lotus.domino.*;
import java.io.*;
import com.lowagie.text.Font;
import com.lowagie.text.*;
import java.util.*;
import com.lowagie.text.pdf.*;
import java.io.PrintWriter;
import java.math.*;
import java.text.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Rectangle;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.Chunk;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Phrase;
import com.lowagie.text.Image;
import com.lowagie.text.html.HtmlWriter;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.RandomAccessFileOrArray;
import com.lowagie.text.pdf.codec.TiffImage;
import com.lowagie.text.Element;
import com.lowagie.text.PageSize;
public class JavaAgent extends AgentBase {
Label l;
PdfPCell cell;
Paragraph p1;
String tiff_file;
String imTiff_file;
String pdf_file;
String strInPutXMLData;
String strOutPutImage;
String PdfWriteDirBase;
String PdfWriteDir;
String path;
Locale locale = Locale.US;
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Agent nAgent = agentContext.getCurrentAgent();
Database db = agentContext.getCurrentDatabase();
String strNoteID = nAgent.getParameterDocID();
lotus.domino.Document doc = db.getDocumentByID(strNoteID);
String userInput = doc.getItemValueString( "ORD_PO_NUM" );
if ( userInput == null ) userInput = "Nothing Entered";
/* make a filename */
String fName = userInput + "_CC.pdf";
String filePath= "C:\\" + fName ;
PrintWriter pw = getAgentOutput();
/* create the pdf doc */
com.lowagie.text.Document document = new com.lowagie.text.Document(PageSize.LETTER);
/* create a writer to listen to the document */
PdfWriter writer = PdfWriter.getInstance( document, new FileOutputStream(filePath));
//Set PDF Properties
document.addTitle("XYZ Inc.");
document.addSubject("XYZ Inc.");
document.addCreator("XYZ Inc.");
document.addAuthor("XYZ Inc.");
//START: PDF Document
document.open();
document.setMargins(18, 18, 36, 36);
/* add a page */
document.newPage();
// some paragraph of text containing a value from a field on the doc
Paragraph myP1 = new Paragraph( "XYZ Inc." , new Font(Font.TIMES_ROMAN,16, Font.BOLD));
myP1.setAlignment(Element.ALIGN_CENTER);
document.add(myP1);
/* close the document */
document.close();
/* create a new document to contain the file */
lotus.domino.Document tempDoc=null;
RichTextItem pdfAttach;
tempDoc=db.createDocument();
tempDoc.replaceItemValue("Form","TempPDF");
tempDoc.replaceItemValue("UserInput", userInput + "_CC");
pdfAttach = tempDoc.createRichTextItem("PDFAttch");
pdfAttach.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null, filePath, null);
/* save the doc */
tempDoc.save(true, true);
File fPath = new File(filePath);
fPath.delete();
} catch(Exception e) {
e.printStackTrace();
}
}
}
If you wanna still help here is what I have for examples from the iowagie site to do the rest…
http://itext.ugent.be/library/com/lowagie/examples/directcontent/pageevents/EndPage.java
I just can’t figure out how to make these work (or incorporate them to the project for that matter). Any direction would be greatly appreciated.
Obviously I am a complete newb when it comes to java so please be gentle. Any code examples would be very sweet.
Rewards and bids welcome… LOL!
Thanks all and have a GREAT day!