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(", "); tableSI3.addCell("Phone:"); tableSI3.addCell(" "); tableSI3.addCell(""); tableSI3.addCell(" "); tableSI3.addCell(" "); tableSI3.addCell(" "); tableSI3.addCell("Terms:"); tableSI3.addCell(" "); tableSI3.addCell("Payable Net 15 Days"); pdfDoc.add(tableSI3); //**** END: PDF Body **** pdfDoc.close(); //END: PDF Document l.setText("Completed PDF Creation...."); addButton(); //Set fields on Current Lotus Notes Document String filepath = PdfAtt.getAbsolutePath(); lnDoc.replaceItemValue("PDFCreateFlag", "True"); lnDoc.replaceItemValue("PDFLocation", path); lnDoc.save(true, false); } catch(Exception e) { e.printStackTrace(); } } public void addButton() { Button b = new Button("OK"); b.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { frame.dispose(); } } ); frame.add(b, "South"); frame.show(); } } 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.*; public class HOLDValues { public static final String strCompanyName = "www.andersontechs.com"; public static final String strAddress1 = "
"; public static final String strAddress2 = ", "; public static final String strPhone1 = ""; public static String ReplaceSubString(String SourceS, String SearchS, String ReplaceS) { while(SourceS.indexOf( SearchS ) >= 0 ) { String leftString = SourceS.substring(0, SourceS.indexOf( SearchS ) ); String rightString = SourceS.substring( SearchS.length() + SourceS.indexOf( SearchS ) ); SourceS = leftString + ReplaceS + rightString; } return SourceS; } public static String replace(String str, String pattern, String replace) { int s = 0; int e = 0; StringBuffer result = new StringBuffer(); while ((e = str.indexOf(pattern, s)) >= 0) { result.append(str.substring(s, e)); result.append(replace); s = e+pattern.length(); } result.append(str.substring(s)); return result.toString(); } public static String getCurrentDate() { try { String sMonth2; String sDay2; String sHour242; String sMin2; String sSec2; Calendar cal = new GregorianCalendar(); // Get the components of the date int era = cal.get(Calendar.ERA); // 0=BC, 1=AD int year = cal.get(Calendar.YEAR); // 2004 int month = cal.get(Calendar.MONTH); // 0=Jan, 1=Feb, ... int day = cal.get(Calendar.DAY_OF_MONTH); // 1... int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // 1=Sunday, 2=Monday, ... int gDate = year & month & day; String sYear = String.valueOf(year); String sMonth = String.valueOf(month + 1); int gLen = sMonth.length(); if(gLen == 1){ sMonth2 = "0" + sMonth; }else { sMonth2 = sMonth; } String sDay = String.valueOf(day); int gLenD = sDay.length(); if(gLenD == 1){ sDay2 = "0" + sDay; }else { sDay2 = sDay; } String sDate = String.valueOf(sMonth2) + "/" + String.valueOf(sDay2) + "/" + String.valueOf(sYear); return sDate; } catch(Exception e) { return "No"; } } }