import lotus.domino.*; import java.io.*; import java.util.*; import java.awt.*; import java.math.*; import java.text.*; import java.lang.*; import java.awt.*; import java.awt.event.*; import com.lowagie.text.*; import com.lowagie.text.pdf.*; 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 createPOPDFAgent extends AgentBase{ Frame frame; 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; NumberFormat formatterDecimal = new DecimalFormat("###,###,###,###.0#"); NumberFormat formatterNoCents = new DecimalFormat("###,###,###,###"); public void NotesMain (){ String richTextField = null; lotus.domino.Document lnDoc = null; int imageId = 1; String docUNID = null; try{ //Set up Notes objects Session session = getSession(); AgentContext agentContext = session.getAgentContext(); Database db = agentContext.getCurrentDatabase(); lnDoc = agentContext.getDocumentContext(); NoteCollection nc = db.createNoteCollection(false); nc.buildCollection(); if(lnDoc != null) { nc.add(lnDoc); } //Export to file docUNID = lnDoc.getUniversalID(); //Create a frame to show progress frame = new Frame(); l = new Label("Starting Data Collection...."); frame.add(l, "Center"); frame.setSize(400, 100); frame.show(); l.setText("Starting Data Collection...."); addButton(); //Get PDF Data String strForm = lnDoc.getItemValueString("Form"); String strProjectNumber = lnDoc.getItemValueString("ProjectNumber"); String strRate = lnDoc.getItemValueString("Rate"); String strDate = lnDoc.getItemValueString("Date"); String strStartTime = lnDoc.getItemValueString("StartTime"); String strEndTime = lnDoc.getItemValueString("EndTime"); String strHours = lnDoc.getItemValueString("Hours"); String strBillableAmount = lnDoc.getItemValueString("BillableAmount"); String strTasks = lnDoc.getItemValueString("Tasks"); String strCompany = lnDoc.getItemValueString("Company"); l.setText("Starting PDF Creation...."); addButton(); //Get location of where the PDF will be stored, if Folder does not exist it will create it PdfWriteDirBase = "C:\\Temp\\"; PdfWriteDir = "\\PDF\\"; String strPDFDirectory = PdfWriteDirBase + PdfWriteDir; boolean exists = (new File(strPDFDirectory)).exists(); if (exists) { System.out.println("Directory: Does esist"); } else { System.out.println("Directory: Does not esist"); boolean success = (new File(strPDFDirectory)).mkdirs(); if (!success) { System.out.println("Directory: Not able to create directory " + strPDFDirectory); } } //PDF Creation //This tells Lotus Notes where you created the PDF so that Notes can later get the PDF using other applications if needed session.setEnvironmentVar("POPDFDirectory", "", true); path = PdfWriteDirBase + PdfWriteDir + "\\" + "ATS-" + strProjectNumber + ".pdf"; session.setEnvironmentVar("POPDFDirectory", path, true); File PdfAtt = new File(path); //This defines the PDF page orientation com.lowagie.text.Document pdfDoc = new com.lowagie.text.Document(PageSize.A4.rotate()); //Defines the PDF output PdfWriter writer = PdfWriter.getInstance(pdfDoc, new FileOutputStream(path)); //Set PDF Properties pdfDoc.addTitle(HOLDValues.strCompanyName + ": Invoice"); pdfDoc.addSubject("Created from the " + HOLDValues.strCompanyName + " Invoice Agent"); pdfDoc.addKeywords(HOLDValues.strCompanyName); pdfDoc.addCreator(HOLDValues.strCompanyName + " Agent"); pdfDoc.addAuthor(HOLDValues.strCompanyName); //START: PDF Document pdfDoc.open(); pdfDoc.setMargins(22, 22, 22, 22); //**** START: PDF Body **** //PDF File - Title Table pdfDoc.add(new Paragraph(" ")); PdfPTable tableTitle = new PdfPTable(1); cell = new PdfPCell(new Paragraph(HOLDValues.strCompanyName + " - Invoice Date: " + HOLDValues.getCurrentDate())); cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableTitle.addCell(cell); cell = new PdfPCell(new Paragraph("Project #: " + strProjectNumber)); cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableTitle.addCell(cell); pdfDoc.add(tableTitle); //Adds Blank line //p1 = new Paragraph(new Chunk(" ", FontFactory.getFont(FontFactory.HELVETICA, 1))); //pdfDoc.add(p1); //PDF File - Customer Table Header pdfDoc.add(new Paragraph(" ")); PdfPTable tableCustomer = new PdfPTable(1); cell = new PdfPCell(new Paragraph("CUSTOMER:")); cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableCustomer.addCell(cell); pdfDoc.add(tableCustomer); //PDF File - Customer Table Data float[] widthsSI1 = {1.0f, .1f, 4.0f}; PdfPTable tableSI1 = new PdfPTable(widthsSI1); tableSI1.addCell("Name:"); tableSI1.addCell(" "); tableSI1.addCell(HOLDValues.strCompanyName); tableSI1.addCell("Address:"); tableSI1.addCell(" "); tableSI1.addCell(HOLDValues.strAddress1); tableSI1.addCell(" "); tableSI1.addCell(" "); tableSI1.addCell(HOLDValues.strAddress2); tableSI1.addCell("Phone:"); tableSI1.addCell(" "); tableSI1.addCell(HOLDValues.strPhone1); pdfDoc.add(tableSI1); //Adds Blank line p1 = new Paragraph(new Chunk(" ", FontFactory.getFont(FontFactory.HELVETICA, 2))); pdfDoc.add(p1); //PDF File - Invoice Table Data float[] widthsSI2 = {4.0f, 1.0f, 1.0f, 1.0f}; PdfPTable tableSI2 = new PdfPTable(widthsSI2); tableSI2.addCell("Description"); tableSI2.addCell("Hours"); tableSI2.addCell("Rate"); tableSI2.addCell("Amount"); tableSI2.addCell(strCompany + ": "); tableSI2.addCell(" "); tableSI2.addCell(" "); tableSI2.addCell(" "); tableSI2.addCell(" " + strTasks); tableSI2.addCell(strHours); tableSI2.addCell("$ " + strRate); tableSI2.addCell("$ " + strBillableAmount); tableSI2.addCell(" "); tableSI2.addCell(" "); tableSI2.addCell(" "); tableSI2.addCell(" "); tableSI2.addCell(" "); tableSI2.addCell(" "); tableSI2.addCell(" "); tableSI2.addCell(" "); tableSI2.addCell(" "); tableSI2.addCell(" "); tableSI2.addCell(" "); tableSI2.addCell(" "); pdfDoc.add(tableSI2); //Adds Blank line //p1 = new Paragraph(new Chunk(" ", FontFactory.getFont(FontFactory.HELVETICA, 2))); //pdfDoc.add(p1); //PDF File - Payment To Table Header pdfDoc.add(new Paragraph(" ")); PdfPTable tablePayTo = new PdfPTable(1); cell = new PdfPCell(new Paragraph("PAYMENT DETAILS:")); cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tablePayTo.addCell(cell); pdfDoc.add(tablePayTo); //PDF File - Payment To Table Data float[] widthsSI3 = {1.0f, .1f, 4.0f}; PdfPTable tableSI3 = new PdfPTable(widthsSI3); tableSI3.addCell(" "); tableSI3.addCell(" "); tableSI3.addCell("Make all checks payable to:"); tableSI3.addCell("Name:"); tableSI3.addCell(" "); tableSI3.addCell("Michael Marcavage"); tableSI3.addCell("Address:"); tableSI3.addCell(" "); tableSI3.addCell("
"); tableSI3.addCell(" "); tableSI3.addCell(" "); tableSI3.addCell("