List of usage examples for com.lowagie.text Element ALIGN_LEFT
int ALIGN_LEFT
To view the source code for com.lowagie.text Element ALIGN_LEFT.
Click Source Link
From source file:com.actelion.research.spiritapp.print.CagePrinterPDF.java
License:Open Source License
public static void printCages(List<Container> cages, boolean printGroupsTreatments, boolean printTreatmentDesc, boolean whiteBackground) throws Exception { final int margin = 15; File f = File.createTempFile("cages__", ".pdf"); Document doc = new Document(PageSize.A4.rotate()); Image maleImg, femaleImg, nosexImg; try {/*from w w w. j av a 2s . c o m*/ maleImg = Image.getInstance(CagePrinterPDF.class.getResource("male.png")); femaleImg = Image.getInstance(CagePrinterPDF.class.getResource("female.png")); nosexImg = Image.getInstance(CagePrinterPDF.class.getResource("nosex.png")); } catch (Exception e) { throw new Exception("Could not find images in the classpath: " + e); } FileOutputStream os = new FileOutputStream(f); PdfWriter writer = PdfWriter.getInstance(doc, os); doc.open(); PdfContentByte canvas = writer.getDirectContentUnder(); float tileW = (doc.getPageSize().getWidth()) / 4; float tileH = (doc.getPageSize().getHeight()) / 2; for (int i = 0; i < cages.size(); i++) { Container cage = cages.get(i); Study study = cage.getStudy(); Set<Group> groups = cage.getGroups(); Group group = cage.getGroup(); Set<Biosample> animals = new TreeSet<>(Biosample.COMPARATOR_NAME); animals.addAll(cage.getBiosamples()); //Find the treatments applied to this group Set<NamedTreatment> allTreatments = new LinkedHashSet<>(); for (Group gr : groups) { allTreatments.addAll(gr.getAllTreatments(-1)); } //Draw if (i % 8 == 0) { if (i > 0) doc.newPage(); drawCageSeparation(doc, canvas); } int col = (i % 8) % 4; int row = (i % 8) / 4; float x = margin + tileW * col; float x2 = x + tileW - margin; float baseY = tileH * row; float y; //Display Sex canvas.moveTo(tileW * col - 50, doc.getPageSize().getHeight() - (tileH * row + 50)); Image img = null; String sex = getMetadata(animals, "Sex"); if (study.isBlindAll()) { img = nosexImg; } else if (sex.equals("M")) { img = maleImg; } else if (sex.equals("F")) { img = femaleImg; } else if (sex.length() > 0) { img = nosexImg; } if (img != null) { img.scaleToFit(20, 20); img.setAbsolutePosition(tileW * (col + 1) - 33, doc.getPageSize().getHeight() - (tileH * row + 12 + margin)); doc.add(img); } if (group != null && group.getColor() != null && (study != null && !study.isBlind()) && !whiteBackground) { Color c = group.getColor(); canvas.saveState(); canvas.setRGBColorFill(c.getRed() / 3 + 170, c.getGreen() / 3 + 170, c.getBlue() / 3 + 170); canvas.rectangle(x - margin + 1, doc.getPageSize().getHeight() - baseY - tileH + 1, tileW - 2, tileH - 2); canvas.fill(); canvas.restoreState(); } Color treatmentColor = Color.BLACK; if (allTreatments.size() > 0 && !study.isBlind() && printGroupsTreatments) { int offset = 0; for (NamedTreatment t : allTreatments) { if (t.getColor() != null) { if (allTreatments.size() == 1) treatmentColor = new Color(t.getColor().getRed() / 2, t.getColor().getGreen() / 2, t.getColor().getBlue() / 2); canvas.saveState(); canvas.setColorStroke(Color.BLACK); canvas.setRGBColorFill(t.getColor().getRed(), t.getColor().getGreen(), t.getColor().getBlue()); y = baseY + 42 + 15 + 86 + 13 + 22 + 14 + 23 + 28; canvas.rectangle(x + 20 + offset * 5, doc.getPageSize().getHeight() - y - (offset % 2) * 4, 22, 22); canvas.fillStroke(); canvas.restoreState(); offset++; } } } canvas.beginText(); canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_BOLD, "Cp1252", false), 16f); canvas.showTextAligned(Element.ALIGN_LEFT, cage.getContainerId(), x, doc.getPageSize().getHeight() - (baseY + 23), 0); canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, "Cp1252", false), 11f); y = 42 + baseY; canvas.showTextAligned(Element.ALIGN_LEFT, "Type: ", x, doc.getPageSize().getHeight() - y, 0); y += 15; canvas.showTextAligned(Element.ALIGN_LEFT, "Animals_ID: ", x, doc.getPageSize().getHeight() - y, 0); y += 86; canvas.showTextAligned(Element.ALIGN_LEFT, "Delivery date: ", x, doc.getPageSize().getHeight() - y, 0); y += 13; canvas.showTextAligned(Element.ALIGN_LEFT, "PO Number: ", x, doc.getPageSize().getHeight() - y, 0); y += 22; canvas.showTextAligned(Element.ALIGN_LEFT, "Study: ", x, doc.getPageSize().getHeight() - y, 0); y += 14; if (study != null && !study.isBlind() && printGroupsTreatments) canvas.showTextAligned(Element.ALIGN_LEFT, "Group: ", x, doc.getPageSize().getHeight() - y, 0); y += 23; if (study != null && !study.isBlind() && printGroupsTreatments) canvas.showTextAligned(Element.ALIGN_LEFT, "Treatment: ", x, doc.getPageSize().getHeight() - y, 0); y += 50; canvas.showTextAligned(Element.ALIGN_LEFT, "License: ", x, doc.getPageSize().getHeight() - y, 0); y += 13; canvas.showTextAligned(Element.ALIGN_LEFT, "Experimenter: ", x, doc.getPageSize().getHeight() - y, 0); canvas.endText(); y = 42 + baseY; print(canvas, study.isBlindAll() ? "Blinded" : getMetadata(animals, "Type"), x + 65, doc.getPageSize().getHeight() - y, x2, 11, 11, FontFactory.HELVETICA, Color.BLACK, 11f); y += 15; if (animals.size() <= 6) { int n = 0; for (Biosample animal : animals) { print(canvas, animal.getSampleId(), x + 75, doc.getPageSize().getHeight() - y - 12 * n, x2 - 50, 12, 12, FontFactory.HELVETICA, Color.BLACK, 11f); if (animal.getSampleName() != null && animal.getSampleName().length() > 0) { print(canvas, "[ " + animal.getSampleName() + " ]", x2 - 60, doc.getPageSize().getHeight() - y - 12 * n, x2, 12, 12, FontFactory.HELVETICA_BOLD, Color.BLACK, 11f); } n++; } } else { int nPerRow = animals.size() / 2; int n = 0; for (Biosample animal : animals) { int nx = n / nPerRow; int ny = n % nPerRow; print(canvas, animal.getSampleId(), x + nx * (x2 - x) / 2, doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12, 12, FontFactory.HELVETICA, Color.BLACK, 10f); if (animal.getSampleName() != null && animal.getSampleName().length() > 0) { print(canvas, "[ " + animal.getSampleName() + " ]", x + (1 + nx) * (x2 - x) / 2 - 35, doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12, 12, FontFactory.HELVETICA_BOLD, Color.BLACK, 10f); } n++; } } y += 86; print(canvas, getMetadata(animals, "Delivery Date"), x + 75, doc.getPageSize().getHeight() - y, x2, 0, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 13; print(canvas, getMetadata(animals, "PO Number"), x + 75, doc.getPageSize().getHeight() - y, x2, 0, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 22; print(canvas, study.getStudyIdAndInternalId(), x + 40, doc.getPageSize().getHeight() - y, x2, 0, 11, BaseFont.HELVETICA_BOLD, Color.BLACK, 11f); y += 14; if (!study.isBlind() && printGroupsTreatments) print(canvas, getGroups(animals), x + 40, doc.getPageSize().getHeight() - y, x2, 22, 11, BaseFont.HELVETICA_BOLD, Color.BLACK, 11f); y += 23; if (!study.isBlind() && printGroupsTreatments) print(canvas, getTreatments(animals, printTreatmentDesc), x + 62, doc.getPageSize().getHeight() - y, x2, 50, printTreatmentDesc ? 9 : 12, FontFactory.HELVETICA, treatmentColor, printTreatmentDesc ? 9f : 10f); y += 50; print(canvas, study.getMetadataMap().get("LICENSENO"), x + 74, doc.getPageSize().getHeight() - y, x2, 15, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 13; print(canvas, study.getMetadataMap().get("EXPERIMENTER"), x + 74, doc.getPageSize().getHeight() - y, x2, 20, 10, FontFactory.HELVETICA, Color.BLACK, 10f); } doc.close(); os.close(); Desktop.getDesktop().open(f); try { Thread.sleep(500); } catch (Exception e) { } }
From source file:com.actelion.research.spiritapp.print.CagePrinterPDF.java
License:Open Source License
private static void print(PdfContentByte canvas, String txt, float x, float y, float maxX, int maxHeight, int lineHeight, String fontName, Color color, float fontSize) throws Exception { float width = maxX - x - 5; float minY = Math.min(y, y - maxHeight + lineHeight - 3); if (txt == null) return;//from w w w.j a va 2 s .c o m canvas.setFontAndSize(BaseFont.createFont(fontName, "Cp1252", false), fontSize); while (txt.length() > 0 && y >= minY) { int index = 0; while (true) { int index2 = index + 1; if (index2 >= txt.length()) { index = index2; break; } float w = canvas.getEffectiveStringWidth(txt.substring(0, index2), true); System.out.println("CagePrinterPDF.print() " + txt.substring(0, index2) + " " + w + "," + width); if (w > width) break; index = index2; } if (index < 0) index = txt.length(); String t = txt.substring(0, index); System.out.println( "CagePrinterPDF.print() " + t + " at " + x + "x" + y + " (of " + txt + ") minY=" + minY); txt = txt.substring(index).trim(); Phrase phrase = new Paragraph(t, FontFactory.getFont(fontName, fontSize, color)); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase, x, y, 0); y -= lineHeight; } }
From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java
License:Open Source License
public static void addHeader(PdfWriter writer, String header) { class MyFooter extends PdfPageEventHelper { com.lowagie.text.Font ffont; @Override/*from ww w . ja v a 2s . c o m*/ public void onEndPage(PdfWriter writer, Document document) { try { ffont = new com.lowagie.text.Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED), 6f, com.lowagie.text.Font.ITALIC); } catch (Exception e) { e.printStackTrace(); return; } String date = FormatterUtils.formatDateTime(new Date()); PdfContentByte cb = writer.getDirectContent(); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase(header, ffont), document.left(), document.top() + 5, 0); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase("Page " + writer.getCurrentPageNumber(), ffont), (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() - 5, 0); ColumnText.showTextAligned(cb, Element.ALIGN_RIGHT, new Phrase(date, ffont), document.right(), document.bottom() - 5, 0); } } writer.setPageEvent(new MyFooter()); }
From source file:com.afrisoftech.reports.PatientRegFormPdf.java
public void generatePdf(String patientName, String patientAge, String PatientGender, String patientNationality, String patientIDPassport, String placeofBirth, String patientOccupation, String maritalStatus, String patientReligion, String patientTelephone, String patientEmail, String patientVillage, String patientLocation, String patientHomeCounty, String patientResidenceCounty, String patientNOK, String patientRelation, String patientNOKTelephone, String patientReferFrom, String bookingDate, String specialtyClinic, String statusNHIF, String NHIFNumber, String educationLevel, String employerTelephone, String patientEmployer, String paidAmount, String receiptNumber, String cSheetNo, String invoiceNumber, String interviewerName, String interviewDate, String servicePoint, String unitNumber, String patientNumber, String admissionWard, String admissionDate, String admissionType, String claimNumber, java.util.Date date, String gender, String typeofAccident, String modeofArrival, String nameofPoliceOfficer, String policeForceNO, String policeStationAccident, String dateAccident, String nameofDriver, String accidentVehicleNo, String driverLicenceNo, String driversIDNo, String registrationTimes) { java.util.Date date111 = date; java.lang.String formLabel = null; if (admissionWard.toCharArray().length < 1) { formLabel = "PATIENT REGISTRATION FORM"; } else {//from w ww. j a v a2s .c o m formLabel = "PATIENT ADMISSION FORM"; } java.lang.Process wait_for_Pdf2Show; java.util.Calendar cal = java.util.Calendar.getInstance(); java.util.Date dateStampPdf = cal.getTime(); java.lang.String pdfDateStamp = dateStampPdf.toString(); try { java.io.File tempFile = java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf"); tempFile.deleteOnExit(); java.lang.Runtime rt = java.lang.Runtime.getRuntime(); java.lang.String debitTotal = null; java.lang.String creditTotal = null; //com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); try { try { PdfWriter writer = com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile)); com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter( new Phrase(formLabel + " : ", pFontHeader2), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue)); docPdf.setFooter(footer); docPdf.open(); java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); try { com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(6); int headerwidths[] = { 16, 16, 16, 16, 16, 16 }; table.setWidths(headerwidths); table.setWidthPercentage((105)); com.lowagie.text.pdf.PdfPTable table2 = new com.lowagie.text.pdf.PdfPTable(2); int headerwidths2[] = { 30, 70 }; table2.setWidths(headerwidths2); table2.setWidthPercentage((100)); table2.getDefaultCell().setFixedHeight(50); //phrase = new Phrase("", pFontHeader1); //table.addCell(phrase); table2.getDefaultCell().setColspan(2); table2.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); Image img = Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo()); img.scalePercent(50); // img.sc//aleAbsolute(200, 200); table2.addCell(img); String compName = null; String District = null; String Region = null; String date2 = null; try { java.sql.Statement st3 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); java.sql.ResultSet rset2 = st3.executeQuery( "SELECT hospital_name,district_branch,region FROM pb_hospitalprofile"); java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date"); while (rset2.next()) { compName = dbObject.getDBObject(rset2.getObject(1), ""); District = dbObject.getDBObject(rset2.getObject(2), ""); Region = dbObject.getDBObject(rset2.getObject(3), ""); } while (rset4.next()) { date2 = dbObject.getDBObject(rset4.getObject(1), ""); } } catch (java.sql.SQLException ex) { javax.swing.JOptionPane.showMessageDialog(new java.awt.Frame(), ex.getMessage()); ex.printStackTrace(); } table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); // table.getDefaultCell().set Phrase phrase = new Phrase(compName.toUpperCase(), pFontHeader3); table2.addCell(phrase); table.addCell(table2); // painting the logo table.setWidths(headerwidths); table.setWidthPercentage((105)); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setColspan(5); phrase = new Phrase(formLabel, pFontHeader2); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); table.getDefaultCell().setColspan(1); phrase = new Phrase("FORM: 260", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); // table.getDefaultCell().set phrase = new Phrase("1. PATIENT PERSONAL DETAILS", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); dbObject = new com.afrisoftech.lib.DBObject(); phrase = new Phrase("Patient Name: " + patientName, pFontHeader); table.addCell(phrase); phrase = new Phrase("Age: " + dbObject.getDBObject((Object) patientAge, "") + "", pFontHeader); table.addCell(phrase); phrase = new Phrase("Nationality: " + dbObject.getDBObject(patientNationality, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("ID-Passport: " + dbObject.getDBObject(patientIDPassport, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Place of Birth: " + dbObject.getDBObject(placeofBirth, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Occupation: " + dbObject.getDBObject(patientOccupation, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Marital Status: " + dbObject.getDBObject(maritalStatus, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Religion: " + dbObject.getDBObject(patientReligion, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Patient Tel.: " + dbObject.getDBObject(patientTelephone, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Patient Email.: " + dbObject.getDBObject(patientEmail, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Patient Gender.: " + dbObject.getDBObject(gender, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Registration Time : " + dbObject.getDBObject(registrationTimes, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("2. PATIENT RESIDENCE", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Home Village: " + dbObject.getDBObject(patientVillage, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Residence: " + dbObject.getDBObject(patientLocation, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("County of Birth: " + dbObject.getDBObject(patientHomeCounty, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase( "County of Residence: " + dbObject.getDBObject(patientResidenceCounty, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("3. NEXT OF KIN", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Next of Kin: " + dbObject.getDBObject(patientNOK, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Relationship: " + dbObject.getDBObject(patientRelation, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("NOK Telephone: " + dbObject.getDBObject(patientNOKTelephone, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("4. CURRENT ATTENDANCE AT FACILITY", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Referred From: " + dbObject.getDBObject(patientReferFrom, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Appointment Date: " + dbObject.getDBObject(date111, ""), pFontHeadercolor); table.addCell(phrase); phrase = new Phrase("Specialty Clinic: " + dbObject.getDBObject(specialtyClinic, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("5. PATIENT SOCIAL ECONOMIC HISTORY", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("NHIF Registered: " + dbObject.getDBObject(statusNHIF, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("NHIF No.: " + dbObject.getDBObject(NHIFNumber, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Education Level: " + dbObject.getDBObject(educationLevel, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Employer: " + dbObject.getDBObject(patientEmployer, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Telephone: " + dbObject.getDBObject(employerTelephone, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("6. DEPOSITS AND OTHER PAYMENTS", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Amount Paid: " + dbObject.getDBObject(paidAmount, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Receipt No.: " + dbObject.getDBObject(receiptNumber, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("C-Sheet No.: " + dbObject.getDBObject(cSheetNo, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Invoice Number: " + dbObject.getDBObject(invoiceNumber, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(4); phrase = new Phrase("NHIF Claim No.: " + dbObject.getDBObject(claimNumber, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase(" ", pFontHeader); // table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("7. INTERVIEWERS INFORMATION", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Interviewer: " + dbObject.getDBObject(interviewerName, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Date: " + dbObject.getDBObject(interviewDate, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Service Point: " + dbObject.getDBObject(servicePoint, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("8. ADMISSION INFORMATION", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Admission Ward: " + dbObject.getDBObject(admissionWard, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Admission Date: " + dbObject.getDBObject(admissionDate, ""), pFontHeadercolor); table.addCell(phrase); phrase = new Phrase("Admission Type: " + dbObject.getDBObject(admissionType, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); ///RTA DETAILS if (typeofAccident.length() > 0 || modeofArrival.length() > 0 || nameofPoliceOfficer.length() > 0 || policeForceNO.length() > 0 || policeStationAccident.length() > 0 || dateAccident.length() > 0 || nameofDriver.length() > 0 || accidentVehicleNo.length() > 0 || driverLicenceNo.length() > 0 || driversIDNo.length() > 0) { table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("RTA DETAILS : ", pFontHeader2); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( dbObject.getDBObject("Type of Accident:- " + typeofAccident, "") + "" + dbObject.getDBObject(". MODE of ARRIVAL:-" + modeofArrival, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( dbObject.getDBObject("Name Of Police Officer :- " + nameofPoliceOfficer, "") + "." + "" + dbObject .getDBObject(" Police Officer Force No:-" + policeForceNO, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( dbObject.getDBObject( "Police Station Accident Scene :- " + policeStationAccident, "") + ". " + dbObject.getDBObject("Accident Date:-" + dateAccident, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( dbObject.getDBObject("Name of Driver:- " + nameofDriver, "") + dbObject .getDBObject(". Accident Vehicle NO:-" + accidentVehicleNo, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( "Driving Licence No:- " + dbObject.getDBObject(driverLicenceNo, "") + ". Driver's ID No :-" + dbObject.getDBObject(driversIDNo, ""), pFontHeader); table.addCell(phrase); } ///RTA END table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setBorder(PdfCell.RECTANGLE); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" Patient Number : ".toUpperCase() + dbObject.getDBObject(patientNumber, "").toUpperCase(), pFontHeader3); table.addCell(phrase); // phrase = new Phrase(" ", pFontHeader); // table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( "Unit Number : ".toUpperCase() + dbObject.getDBObject(unitNumber, "").toUpperCase(), pFontHeader2); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); //PdfWriter writer = PdfWriter.getInstance(docPdf, new FileOutputStream(tempFile)); PdfContentByte cb = writer.getDirectContent(); Barcode128 code128 = new Barcode128(); code128.setCode(patientNumber.toUpperCase() + " " + patientName.toUpperCase()); code128.setBarHeight(16); code128.setTextAlignment(Element.ALIGN_LEFT); docPdf.add(table); docPdf.add(code128.createImageWithBarcode(cb, null, null)); // docPdf.add(new com.itextpdf.text.Paragraph("Barcode QRCode")); // BarcodeQRCode qrcode = new BarcodeQRCode(patientNumber.toUpperCase() + " " + patientName.toUpperCase(), 1, 1, null); // com.itextpdf.text.Image qrimg = qrcode.getImage(); // docPdf.add(qrimg); // docPdf.add(table); } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } } catch (java.io.FileNotFoundException fnfExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage()); } } catch (com.lowagie.text.DocumentException lwDocexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage()); } docPdf.close(); com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile); } catch (java.io.IOException IOexec) { IOexec.printStackTrace(); javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage()); } }
From source file:com.afrisoftech.reports.PatientRegReprintFormPdf.java
public void generatePdf(java.sql.Connection con, String patientNo, String type, String receipt_no, String receipt_time) {/*from w w w. j ava2 s .c o m*/ String patientName = null; String patientAge = null; String PatientGender = null; String patientNationality = null; String patientIDPassport = null; String placeofBirth = null; String patientOccupation = null; String maritalStatus = null; String patientReligion = null; String patientTelephone = null; String patientEmail = null; String patientVillage = null; String patientLocation = null; String patientHomeCounty = null; String patientResidenceCounty = null; String patientNOK = null; String patientRelation = null; String patientNOKTelephone = null; String patientReferFrom = null; String bookingDate = null; String specialtyClinic = null; String statusNHIF = null; String NHIFNumber = null; String educationLevel = null; String employerTelephone = null; String patientEmployer = null; String paidAmount = null; String receiptNumber = null; String cSheetNo = null; String invoiceNumber = null; String interviewerName = null; String interviewDate = null; String servicePoint = null; String unitNumber = null; String patientNumber = null; String admissionWard = null; String admissionDate = null; String admissionType = null; String claimNumber = null; java.util.Date date = null; String gender = null; String typeofAccident = null; String modeofArrival = null; String nameofPoliceOfficer = null; String policeForceNO = null; String policeStationAccident = null; String dateAccident = null; String nameofDriver = null; String accidentVehicleNo = null; String driverLicenceNo = null; String driversIDNo = null; String patNo = null; patNo = patientNo; try { // java.sql.ResultSet rse124 = stm124.executeQuery("SELECT first_name, second_name, nok, residence, \n" + //" address, year_of_birth, tel_no, sex, date, pay_mode, payer, account_no, \n" + //" description, category, expiry_date, last_visit, department, member_name, \n" + //" card_no, emails, id_no, nok_add, old_patient_no, pat_nationality, \n" + //" nok_telno, nok_relationship, nok_residence, nok_email, pat_marital_status, \n" + //" tribe, district, locations, sub_location, chief_name, sub_chief, \n" + //" information_source, education_level, occupation, pat_religion, \n" + //" patient_race, birth_place, waiting_patient, email, home_county, \n" + //" residence_county, nhif_status, nhif_number, employer_name, employer_telephone, \n" + //" refer_source, charge_sheet_no, specialty_clinic\n" + //" FROM hp_patient_register; where patient_no='"+patNo+"' "); if (type.equals("OP")) { java.sql.Statement stm12456 = con.createStatement(); java.sql.ResultSet rse124 = stm12456 .executeQuery("SELECT hp.patient_no, first_name, second_name, last_name, nok, residence," + " address, year_of_birth, tel_no, sex, date, pay_mode, payer, account_no, " + " description, category, expiry_date, last_visit, department, member_name," + " card_no, emails, id_no, nok_add, old_patient_no, pat_nationality," + " nok_telno, nok_relationship, nok_residence, nok_email, pat_marital_status," + " tribe, district, locations, sub_location, chief_name, sub_chief," + " information_source, education_level, occupation, pat_religion," + " patient_race, birth_place, waiting_patient, email, home_county," + " residence_county, nhif_status, nhif_number, employer_name, employer_telephone," + " refer_source, charge_sheet_no, specialty_clinic, accident_type, arrival_mode, police_officer_no, police_station,date_time, driver_name, accident_vehicle_no, driver_license, driver_id_no,service_point,user_name FROM hp_patient_register hp LEFT JOIN rta_info rt on hp.patient_no=rt.patient_no WHERE hp.patient_no='" + patNo + "' ORDER BY date_time desc limit 1 "); while (rse124.next()) { patientName = rse124.getString(2).toUpperCase() + " " + rse124.getString(3).toUpperCase(); patientAge = PatientAge.getPatientActualAge(con, com.afrisoftech.lib.SQLDateFormat.getSQLDate(rse124.getDate("year_of_birth"))); PatientGender = rse124.getString("sex"); patientNationality = rse124.getString("pat_nationality"); patientIDPassport = rse124.getString("id_no"); placeofBirth = rse124.getString("birth_place"); patientOccupation = rse124.getString("occupation"); maritalStatus = rse124.getString("pat_marital_status"); patientReligion = rse124.getString("pat_religion"); patientTelephone = rse124.getString("tel_no"); patientEmail = rse124.getString("emails"); patientVillage = rse124.getString("residence"); patientLocation = rse124.getString("locations"); patientHomeCounty = rse124.getString("home_county"); patientResidenceCounty = rse124.getString("residence_county"); patientNOK = rse124.getString("nok"); patientRelation = rse124.getString("nok_relationship"); //jddfsjdsj patientNOKTelephone = rse124.getString("nok_telno"); patientReferFrom = rse124.getString("refer_source"); bookingDate = rse124.getString("date"); specialtyClinic = rse124.getString("specialty_clinic"); statusNHIF = rse124.getString("nhif_status"); NHIFNumber = rse124.getString("nhif_number"); educationLevel = rse124.getString("education_level"); employerTelephone = rse124.getString("employer_telephone"); patientEmployer = rse124.getString("employer_name"); paidAmount = ""; receiptNumber = ""; cSheetNo = rse124.getString("charge_sheet_no"); invoiceNumber = ""; interviewerName = rse124.getString("user_name"); interviewDate = rse124.getString("date"); servicePoint = rse124.getString("service_point"); unitNumber = rse124.getString("patient_race"); patientNumber = rse124.getString("patient_no"); admissionWard = ""; admissionDate = ""; admissionType = ""; claimNumber = ""; date = com.afrisoftech.lib.SQLDateFormat.getSQLDate(rse124.getDate("date")); gender = rse124.getString("sex"); typeofAccident = rse124.getString("accident_type"); modeofArrival = rse124.getString("arrival_mode"); nameofPoliceOfficer = rse124.getString("police_officer_no"); policeForceNO = rse124.getString("police_officer_no"); policeStationAccident = rse124.getString("police_station"); dateAccident = rse124.getString("date_time"); nameofDriver = rse124.getString("driver_name"); accidentVehicleNo = rse124.getString("accident_vehicle_no"); driverLicenceNo = rse124.getString("driver_license"); driversIDNo = rse124.getString("driver_id_no"); System.out.println(""); } ///getting the receipt details try { java.sql.Statement stmt11 = connectDB.createStatement(); //java.sql.ResultSet rset11 = stmt11.executeQuery("SELECT description,receipt_no, debit FROM ac_cash_collection where patient_no='" + patientNumberTxt.getText() + "' and receipt_time::date >= current_date-1 "); java.sql.ResultSet rset11 = stmt11.executeQuery( "SELECT description,receipt_no, debit FROM ac_cash_collection where patient_no='" + patNo + "' and receipt_no='" + receipt_no + "' and receipt_time::date='" + receipt_time + "'::date "); while (rset11.next()) { receiptNumber = rset11.getObject(2).toString(); paidAmount = rset11.getObject(3).toString(); System.out.println("This is the receipt no " + receiptNumber + " and this is the AMOUNT " + paidAmount); } } catch (Exception ex) { ex.printStackTrace(); ex.getMessage(); } ///end } else if (type.equals("IP")) { } } catch (java.sql.SQLException sq) { javax.swing.JOptionPane.showMessageDialog(null, sq.getMessage(), "Error Message!", javax.swing.JOptionPane.ERROR_MESSAGE); System.out.println(sq.getMessage()); } java.util.Date date111 = date; java.lang.String formLabel = null; // if(admissionWard.toCharArray().length < 1){ // // formLabel = "PATIENT REGISTRATION FORM"; // // } else { // formLabel = "PATIENT ADMISSION FORM"; // } if (type.equals("OP")) { formLabel = "PATIENT REGISTRATION FORM"; } else { formLabel = "PATIENT ADMISSION FORM"; } java.lang.Process wait_for_Pdf2Show; java.util.Calendar cal = java.util.Calendar.getInstance(); java.util.Date dateStampPdf = cal.getTime(); java.lang.String pdfDateStamp = dateStampPdf.toString(); try { java.io.File tempFile = java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf"); tempFile.deleteOnExit(); java.lang.Runtime rt = java.lang.Runtime.getRuntime(); java.lang.String debitTotal = null; java.lang.String creditTotal = null; //com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); try { try { PdfWriter writer = com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile)); com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter( new Phrase(formLabel + " : ", pFontHeader2), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue)); docPdf.setFooter(footer); docPdf.open(); java.util.Calendar calendar = java.util.Calendar.getInstance(); long dateNow = calendar.getTimeInMillis(); java.sql.Date datenowSql = new java.sql.Date(dateNow); System.out.println(datenowSql.toString()); try { com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(6); int headerwidths[] = { 16, 16, 16, 16, 16, 16 }; table.setWidths(headerwidths); table.setWidthPercentage((105)); com.lowagie.text.pdf.PdfPTable table2 = new com.lowagie.text.pdf.PdfPTable(2); int headerwidths2[] = { 30, 70 }; table2.setWidths(headerwidths2); table2.setWidthPercentage((100)); table2.getDefaultCell().setFixedHeight(50); //phrase = new Phrase("", pFontHeader1); //table.addCell(phrase); table2.getDefaultCell().setColspan(2); table2.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); Image img = Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo()); img.scalePercent(50); // img.sc//aleAbsolute(200, 200); table2.addCell(img); String compName = null; String District = null; String Region = null; String date2 = null; try { java.sql.Statement st3 = connectDB.createStatement(); java.sql.Statement st4 = connectDB.createStatement(); java.sql.ResultSet rset2 = st3.executeQuery( "SELECT hospital_name,district_branch,region FROM pb_hospitalprofile"); java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date"); while (rset2.next()) { compName = rset2.getObject(1).toString(); District = rset2.getObject(2).toString(); Region = rset2.getObject(3).toString(); } while (rset4.next()) { date2 = rset4.getObject(1).toString(); } } catch (java.sql.SQLException ex) { javax.swing.JOptionPane.showMessageDialog(new java.awt.Frame(), ex.getMessage()); ex.printStackTrace(); } table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); // table.getDefaultCell().set Phrase phrase = new Phrase(compName.toUpperCase(), pFontHeader3); table2.addCell(phrase); table.addCell(table2); // painting the logo table.setWidths(headerwidths); table.setWidthPercentage((105)); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setColspan(5); phrase = new Phrase(formLabel, pFontHeader2); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); table.getDefaultCell().setColspan(1); phrase = new Phrase("FORM: 260", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); // table.getDefaultCell().set phrase = new Phrase("1. PATIENT PERSONAL DETAILS", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); dbObject = new com.afrisoftech.lib.DBObject(); phrase = new Phrase("Patient Name: " + patientName, pFontHeader); table.addCell(phrase); phrase = new Phrase("Age: " + dbObject.getDBObject((Object) patientAge, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Nationality: " + dbObject.getDBObject(patientNationality, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("ID-Passport: " + dbObject.getDBObject(patientIDPassport, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Place of Birth: " + dbObject.getDBObject(placeofBirth, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Occupation: " + dbObject.getDBObject(patientOccupation, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Marital Status: " + dbObject.getDBObject(maritalStatus, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Religion: " + dbObject.getDBObject(patientReligion, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Patient Tel.: " + dbObject.getDBObject(patientTelephone, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Patient Email.: " + dbObject.getDBObject(patientEmail, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Patient Gender.: " + dbObject.getDBObject(gender, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("2. PATIENT RESIDENCE", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Home Village: " + dbObject.getDBObject(patientVillage, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Home Location: " + dbObject.getDBObject(patientLocation, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("County of Birth: " + dbObject.getDBObject(patientHomeCounty, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase( "County of Residence: " + dbObject.getDBObject(patientResidenceCounty, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("3. NEXT OF KIN", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Next of Kin: " + dbObject.getDBObject(patientNOK, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Relationship: " + dbObject.getDBObject(patientRelation, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("NOK Telephone: " + dbObject.getDBObject(patientNOKTelephone, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("4. CURRENT ATTENDANCE AT KNH", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Referred From: " + dbObject.getDBObject(patientReferFrom, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Appointment Dates: " + dbObject.getDBObject(date111, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Specialty Clinic: " + dbObject.getDBObject(specialtyClinic, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("5. PATIENT SOCIAL ECONOMIC HISTORY", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); if (statusNHIF != null) { if (statusNHIF.contains("f")) { statusNHIF = "NO"; } else { statusNHIF = "YES"; } } else { statusNHIF = "NO"; } phrase = new Phrase("NHIF Registered: " + dbObject.getDBObject(statusNHIF, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("NHIF No.: " + dbObject.getDBObject(NHIFNumber, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Education Level: " + dbObject.getDBObject(educationLevel, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Employer: " + dbObject.getDBObject(patientEmployer, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Telephone: " + dbObject.getDBObject(employerTelephone, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("6. DEPOSITS AND OTHER PAYMENTS", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Amount Paid: " + dbObject.getDBObject(paidAmount, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Receipt No.: " + dbObject.getDBObject(receiptNumber, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("C-Sheet No.: " + dbObject.getDBObject(cSheetNo, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Invoice Number: " + dbObject.getDBObject(invoiceNumber, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(4); phrase = new Phrase("NHIF Claim No.: " + dbObject.getDBObject(claimNumber, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase(" ", pFontHeader); // table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("7. INTERVIEWERS INFORMATION", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Interviewer: " + dbObject.getDBObject(interviewerName, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Date: " + dbObject.getDBObject(interviewDate, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Service Point: " + dbObject.getDBObject(servicePoint, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY); phrase = new Phrase("8. ADMISSION INFORMATION", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("Admission Ward: " + dbObject.getDBObject(admissionWard, ""), pFontHeader); table.addCell(phrase); phrase = new Phrase("Admission Date: " + dbObject.getDBObject(admissionDate, ""), pFontHeader2); table.addCell(phrase); phrase = new Phrase("Admission Type: " + dbObject.getDBObject(admissionType, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); ///RTA DETAILS // if(typeofAccident.length()>0 || modeofArrival.length()>0 || // nameofPoliceOfficer.length()>0 || policeForceNO.length()>0 || // policeStationAccident.length()>0 || dateAccident.length()>0 || // nameofDriver.length()>0 || accidentVehicleNo.length()>0 || // driverLicenceNo.length()>0 || driversIDNo.length()>0 ){ if (typeofAccident != null || modeofArrival != null || nameofPoliceOfficer != null || policeForceNO != null || policeStationAccident != null || dateAccident != null || nameofDriver != null || accidentVehicleNo != null || driverLicenceNo != null || driversIDNo != null) { table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase("RTA DETAILS : ", pFontHeader2); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(dbObject.getDBObject("Accident Date:-" + dateAccident, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( dbObject.getDBObject("Type of Accident:- " + typeofAccident, "") + "" + dbObject.getDBObject(". MODE of ARRIVAL:-" + modeofArrival, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( dbObject.getDBObject("Name Of Police Officer :- " + nameofPoliceOfficer, "") + "." + "" + dbObject .getDBObject(" Police Officer Force No:-" + policeForceNO, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( dbObject.getDBObject( "Police Station Accident Scene :- " + policeStationAccident, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( dbObject.getDBObject("Name of Driver:- " + nameofDriver, "") + dbObject .getDBObject(". Accident Vehicle NO:-" + accidentVehicleNo, ""), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase( "Driving Licence No:- " + dbObject.getDBObject(driverLicenceNo, "") + ". Driver's ID No :-" + dbObject.getDBObject(driversIDNo, ""), pFontHeader); table.addCell(phrase); } ///RTA END table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(" ", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setBorder(PdfCell.RECTANGLE); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase( " Patient Number : ".toUpperCase() + dbObject.getDBObject(patNo.toUpperCase(), ""), pFontHeader2); table.addCell(phrase); // phrase = new Phrase(" ", pFontHeader); // table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Unit Number : ".toUpperCase() + dbObject.getDBObject(unitNumber, ""), pFontHeader3); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); phrase = new Phrase(" ", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); //PdfWriter writer = PdfWriter.getInstance(docPdf, new FileOutputStream(tempFile)); PdfContentByte cb = writer.getDirectContent(); Barcode128 code128 = new Barcode128(); System.out.println("PATIENT NO " + patNo + " NAME " + patientName); code128.setCode(patNo + " " + patientName); code128.setBarHeight(16); code128.setTextAlignment(Element.ALIGN_LEFT); docPdf.add(table); docPdf.add(code128.createImageWithBarcode(cb, null, null)); // docPdf.add(table); } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage()); } } catch (java.io.FileNotFoundException fnfExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage()); } } catch (com.lowagie.text.DocumentException lwDocexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage()); } docPdf.close(); com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile); } catch (java.io.IOException IOexec) { IOexec.printStackTrace(); javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage()); } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createWordReport_hardware(String filename) { try {//w w w . j av a 2s . co m String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); Document document = new Document(PageSize.A4); RtfWriter2.getInstance(document, new FileOutputStream(filename)); fileName = filename; document.open(); BaseFont bfChinese = BaseFont.createFont("Times-Roman", "", BaseFont.NOT_EMBEDDED); Font titleFont = new Font(bfChinese, 12, Font.BOLD); Font contextFont = new Font(bfChinese, 10, Font.NORMAL); Paragraph title = new Paragraph(""); title.setAlignment(Element.ALIGN_CENTER); document.add(title); String contextString = ":" + impReport.getTimeStamp() + " \n"// + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString); // context.setAlignment(Element.ALIGN_LEFT); // context.setFont(contextFont); // context.setSpacingBefore(5); // context.setFirstLineIndent(5); document.add(context); Table aTable = new Table(4); float[] widths = { 100f, 100f, 300f, 100f }; aTable.setWidths(widths); aTable.setWidth(100); // 90% aTable.setAlignment(Element.ALIGN_CENTER);// aTable.setAutoFillEmptyCells(true); // aTable.setBorderWidth(1); // aTable.setBorderColor(new Color(0, 125, 255)); // aTable.setPadding(2);// aTable.setSpacing(0);// aTable.setBorder(2);// aTable.endHeaders(); aTable.addCell(""); aTable.addCell(""); aTable.addCell(""); aTable.addCell(""); Vector deviceV = (Vector) reportHash.get("deviceV"); for (int m = 0; m < deviceV.size(); m++) { Devicecollectdata devicedata = (Devicecollectdata) deviceV.get(m); String name = devicedata.getName(); String type = devicedata.getType(); String status = devicedata.getStatus(); aTable.addCell(m + 1 + ""); aTable.addCell(type); aTable.addCell(name); aTable.addCell(status); } document.add(aTable); document.close(); // System.out.println("abcdefg"); } catch (Exception e) { SysLogger.error("", e); } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createPdfReport_hardware(String filename) { try {//w w w. j av a 2 s .com String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // Document document = new Document(PageSize.A4); // (Writer)document(Writer) PdfWriter.getInstance(document, new FileOutputStream(filename)); fileName = filename; document.open(); // BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); // Font titleFont = new Font(bfChinese, 12, Font.BOLD); // Font contextFont = new Font(bfChinese, 10, Font.NORMAL); Paragraph title = new Paragraph("", titleFont); // title.setAlignment(Element.ALIGN_CENTER); // title.setFont(titleFont); document.add(title); String contextString = ":" + impReport.getTimeStamp() + " \n"// + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString, contextFont); // context.setAlignment(Element.ALIGN_LEFT); // context.setFont(contextFont); // context.setSpacingBefore(5); // context.setFirstLineIndent(5); document.add(context); document.add(new Phrase("\n")); Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.black); PdfPTable aTable = new PdfPTable(4); float[] widths = { 100f, 100f, 300f, 100f }; aTable.setWidths(widths); aTable.setWidthPercentage(100); aTable.addCell(new Phrase("", contextFont)); aTable.addCell(new Phrase("", contextFont)); aTable.addCell(new Phrase("", contextFont)); aTable.addCell(new Phrase("", contextFont)); Vector deviceV = (Vector) reportHash.get("deviceV"); for (int m = 0; m < deviceV.size(); m++) { Devicecollectdata devicedata = (Devicecollectdata) deviceV.get(m); String name = devicedata.getName(); String type = devicedata.getType(); String status = devicedata.getStatus(); aTable.addCell(new Phrase(m + 1 + "", contextFont)); aTable.addCell(new Phrase(type, contextFont)); aTable.addCell(new Phrase(name, contextFont)); aTable.addCell(new Phrase(status, contextFont)); } /* * Image img = * Image.getInstance(ResourceCenter.getInstance().getSysPath() + * "/resource/image/jfreechart/" + newip + "ConnectUtilization" + * ".png"); * * img.setAlignment(Image.LEFT);// img.scalePercent(75); * document.add(aTable); document.add(img); */ document.add(aTable); document.close(); } catch (Exception e) { SysLogger.error("", e); } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReportusa_oraPDF(String filename) throws DocumentException, IOException { if (impReport.getTable() == null) { fileName = null;//from w ww .j av a 2s . c om return; } try { // Document document = new Document(PageSize.A4); // (Writer)document(Writer) PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); // BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); // Font titleFont = new Font(bfChinese, 12, Font.BOLD); // Font contextFont = new Font(bfChinese, 12, Font.NORMAL); Font contextFont1 = new Font(bfChinese, 11, Font.NORMAL); String hostname = (String) reportHash.get("dbname"); String ip = (String) reportHash.get("ip"); String newip = doip(ip); Paragraph title = new Paragraph(hostname + "", titleFont); // title.setAlignment(Element.ALIGN_CENTER); document.add(title); String Ping = (String) reportHash.get("Ping"); String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); Hashtable maxping = (Hashtable) reportHash.get("ping"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String contextString = ":" + impReport.getTimeStamp() + " \n"// + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString, contextFont1); // context.setAlignment(Element.ALIGN_LEFT); // context.setFont(contextFont); // context.setSpacingBefore(5); // context.setFirstLineIndent(5); document.add(context); document.add(new Paragraph("\n")); PdfPTable aTable = new PdfPTable(4); float[] widths = { 220f, 220f, 220f, 220f }; aTable.setWidths(widths); aTable.setWidthPercentage(100); PdfPCell cell = null; cell = new PdfPCell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new PdfPCell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new PdfPCell(new Phrase("")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); // cell = new PdfPCell(new Phrase((String) maxping.get("pingmax"))); cell = new PdfPCell(new Phrase((String) maxping.get("pingnow")));// HONGLI // MODIFY cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); // cell = new PdfPCell(new Phrase((String) maxping.get("ping"))); cell = new PdfPCell(new Phrase((String) maxping.get("pingmin")));// HONGLI // MODIFY cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new PdfPCell(new Phrase((String) maxping.get("avgpingcon"))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); // Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "ConnectUtilization" + ".png"); img.setAlignment(Image.MIDDLE);// img.scalePercent(76); document.add(aTable); document.add(img); document.add(new Paragraph("\n")); if (impReport.getChart() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(), impReport.getChart().getWidth(), impReport.getChart().getHeight()); } catch (IOException ioe) { } Image img1 = Image.getInstance(baos.toByteArray()); img1.setAbsolutePosition(0, 0); img1.setAlignment(Image.MIDDLE);// document.add(img1); } document.close(); } catch (Exception e) { // SysLogger.error("Error in ExcelReport.createReport()",e); SysLogger.error("", e); } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReportusa_oraDoc(String filename) throws DocumentException, IOException { try {/*from w w w . ja v a 2 s . c o m*/ // Document document = new Document(PageSize.A4); // (Writer)document(Writer) RtfWriter2.getInstance(document, new FileOutputStream(filename)); document.open(); // BaseFont bfChinese = BaseFont.createFont("Times-Roman", "", BaseFont.NOT_EMBEDDED); // Font titleFont = new Font(bfChinese, 12, Font.BOLD); // Font contextFont = new Font(bfChinese, 12, Font.NORMAL); String hostname = (String) reportHash.get("dbname"); String ip = (String) reportHash.get("ip"); String newip = doip(ip); // System.out.println("newi ========================"+newip); Paragraph title = new Paragraph(hostname + "", titleFont); // title.setAlignment(Element.ALIGN_CENTER); // title.setFont(titleFont); document.add(title); String Ping = (String) reportHash.get("Ping"); String starttime = (String) reportHash.get("starttime"); String totime = (String) reportHash.get("totime"); Hashtable maxping = (Hashtable) reportHash.get("ping"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String contextString = ":" + impReport.getTimeStamp() + " \n" + ":" + starttime + " " + totime; Paragraph context = new Paragraph(contextString, contextFont); // context.setAlignment(Element.ALIGN_LEFT); // context.setSpacingBefore(5); // context.setFirstLineIndent(5); document.add(context); Table aTable = new Table(4); float[] widths = { 220f, 220f, 220f, 220f }; aTable.setWidths(widths); aTable.setWidth(100); // 90% aTable.setAlignment(Element.ALIGN_CENTER);// aTable.setAutoFillEmptyCells(true); // aTable.setBorderWidth(1); // aTable.setBorderColor(new Color(0, 125, 255)); // aTable.setPadding(2);// aTable.setSpacing(0);// aTable.setBorder(2);// aTable.endHeaders(); Cell cell = null; cell = new Cell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new Cell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new Cell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new Cell(new Phrase("", titleFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new Cell(""); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); // cell = new Cell(new Phrase((String) // maxping.get("pingmax"),contextFont)); cell = new Cell(new Phrase((String) maxping.get("pingnow"), contextFont));// HONGLI // MODIFY cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); // cell = new Cell(new Phrase((String) // maxping.get("ping"),contextFont)); cell = new Cell(new Phrase((String) maxping.get("pingmin"), contextFont));// HONGLI // MODIFY cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); cell = new Cell(new Phrase((String) maxping.get("avgpingcon"), contextFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); // cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // aTable.addCell(cell); // Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "ConnectUtilization" + ".png"); document.add(aTable); document.add(img); document.close(); } catch (Exception e) { SysLogger.error("", e); } }
From source file:com.afunms.report.abstraction.ExcelReport1.java
public void createReport_networkDoc(String file) throws DocumentException, IOException { String runmodel = PollingEngine.getCollectwebflag(); Hashtable CPU = (Hashtable) reportHash.get("CPU"); String Ping = (String) reportHash.get("Ping"); String ip = (String) reportHash.get("ip"); String newip = doip(ip);//from w ww . java2 s . c om Calendar colTime = (Calendar) reportHash.get("time"); Date cc = colTime.getTime(); Vector netifVector = (Vector) reportHash.get("netifVector"); Hashtable portconfigHash = (Hashtable) reportHash.get("portconfigHash"); List reportports = (List) reportHash.get("reportports"); Vector iprouterVector = (Vector) reportHash.get("iprouterVector"); Hashtable Memory = (Hashtable) reportHash.get("Memory"); Hashtable Disk = (Hashtable) reportHash.get("Disk"); String hostname = (String) reportHash.get("equipname"); Hashtable memMaxHash = (Hashtable) reportHash.get("memmaxhash"); Hashtable maxping = (Hashtable) reportHash.get("ping"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String[] netIfItemch = { "", "", "", "(M)", "", "", "" }; String[] ipRouterItemch = { "", "", "", "", "", "" }; String[] memoryItem = { "Capability", "Utilization" }; String[] diskItem = { "AllSize", "UsedSize", "Utilization", "INodeUsedSize", "INodeUtilization" }; String[] diskItemch = { "", "", "", "i-node", "i-node" }; String[] iproutertype = { "", "", "", "direct(3)", "indirect(4)" }; String[] iprouterproto = { "", "other(1)", "local(2)", "netmgmt(3)", "icmp(4)", "egp(5)", "ggp(6)", "hello(7)", "rip(8)", "is-is(9)", "es-is(10)", "ciscoIgrp(11)", "bbnSpfIgp(12)", "ospf(13)", "bgp(14)" }; // Document document = new Document(PageSize.A4); // (Writer)document(Writer) RtfWriter2.getInstance(document, new FileOutputStream(file)); document.open(); // BaseFont bfChinese = BaseFont.createFont("Times-Roman", "", BaseFont.NOT_EMBEDDED); // Font titleFont = new Font(bfChinese, 12, Font.BOLD); // Font contextFont = new Font(bfChinese, 10, Font.NORMAL); Paragraph title = new Paragraph(hostname + "", titleFont); // title.setAlignment(Element.ALIGN_CENTER); // title.setFont(titleFont); document.add(title); String contextString = ":" + impReport.getTimeStamp() + " \n"// + ":" + sdf.format(cc); Paragraph context = new Paragraph(contextString, titleFont); // context.setAlignment(Element.ALIGN_LEFT); // context.setFont(contextFont); // context.setSpacingBefore(5); // context.setFirstLineIndent(5); document.add(context); // Table Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.black); Table aTable = new Table(4); float[] widths = { 220f, 300f, 220f, 220f }; aTable.setWidths(widths); aTable.setWidth(100); // 90% aTable.setAlignment(Element.ALIGN_CENTER);// aTable.setAutoFillEmptyCells(true); // aTable.setBorderWidth(1); // aTable.setBorderColor(new Color(0, 125, 255)); // aTable.setPadding(2);// aTable.setSpacing(0);// aTable.setBorder(2);// aTable.endHeaders(); Cell cellt0 = new Cell(""); cellt0.setBackgroundColor(Color.LIGHT_GRAY); cellt0.setHorizontalAlignment(Element.ALIGN_CENTER); cellt0.setVerticalAlignment(Element.ALIGN_MIDDLE); cellt0.setRowspan(2); Cell cellt1 = new Cell(""); cellt1.setBackgroundColor(Color.LIGHT_GRAY); Cell cellt2 = new Cell(""); cellt2.setBackgroundColor(Color.LIGHT_GRAY); Cell cellt3 = new Cell(""); cellt3.setBackgroundColor(Color.LIGHT_GRAY); aTable.addCell(cellt0); aTable.addCell(cellt1); aTable.addCell(cellt2); aTable.addCell(cellt3); // aTable.addCell("3.2",Ping+"%"); // Cell cellt4 = new Cell(""); // cellt4.setBackgroundColor(Color.LIGHT_GRAY); // aTable.addCell(cellt4); aTable.addCell(Ping + "%"); aTable.addCell((String) maxping.get("pingmax")); aTable.addCell((String) maxping.get("avgpingcon")); Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "ConnectUtilization" + ".png"); img.setAbsolutePosition(0, 0); img.setAlignment(Image.LEFT);// document.add(aTable); document.add(img); // document.add(new Paragraph("\n")); // document.close(); Table aTable1 = new Table(4); float[] width = { 220f, 300f, 220f, 220f }; aTable1.setWidths(width); aTable1.setWidth(100); // 90% aTable1.setAlignment(Element.ALIGN_CENTER);// aTable1.setAutoFillEmptyCells(true); // aTable1.setBorderWidth(1); // aTable1.setBorderColor(new Color(0, 125, 255)); // aTable1.setPadding(2);// aTable1.setSpacing(0);// aTable1.setBorder(2);// aTable1.endHeaders(); cellt0 = new Cell("CPU"); cellt0.setBackgroundColor(Color.LIGHT_GRAY); cellt0.setHorizontalAlignment(Element.ALIGN_CENTER); cellt0.setVerticalAlignment(Element.ALIGN_MIDDLE); cellt1 = new Cell(""); cellt1.setBackgroundColor(Color.LIGHT_GRAY); cellt2 = new Cell(""); cellt2.setBackgroundColor(Color.LIGHT_GRAY); cellt3 = new Cell(""); cellt3.setBackgroundColor(Color.LIGHT_GRAY); aTable1.addCell(cellt0); aTable1.addCell(cellt1); aTable1.addCell(cellt2); aTable1.addCell(cellt3); // aTable.addCell("3.2",Ping+"%"); aTable1.addCell(""); aTable1.addCell((String) CPU.get("cpu") + "%"); aTable1.addCell((String) CPU.get("cpumax")); aTable1.addCell((String) CPU.get("avgcpu")); cellt0.setRowspan(2); Image img1 = Image.getInstance( ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "cpu" + ".png"); img.setAbsolutePosition(0, 0); img.setAlignment(Image.MIDDLE);// document.add(aTable1); document.add(img1); if (netifVector != null && netifVector.size() > 0) { Table aTable2 = new Table(8); float[] width2 = { 300f, 220f, 220f, 180f, 300f, 180f, 220f, 220f }; aTable2.setWidths(width2); aTable2.setWidth(100); // 100% aTable2.setAlignment(Element.ALIGN_CENTER);// aTable2.setAutoFillEmptyCells(true); // aTable2.setBorderWidth(1); // aTable2.setBorderColor(new Color(0, 125, 255)); // aTable2.setPadding(2);// aTable2.setSpacing(0);// aTable2.setBorder(2);// aTable2.endHeaders(); Cell c = new Cell(""); c.setBackgroundColor(Color.LIGHT_GRAY); c.setRowspan(netifVector.size() + 1); c.setHorizontalAlignment(Element.ALIGN_CENTER); c.setVerticalAlignment(Element.ALIGN_MIDDLE); aTable2.addCell(c); // // allRow = allRow; for (int i = 0; i < netIfItemch.length; i++) { Cell cell = new Cell(netIfItemch[i]); cell.setBackgroundColor(Color.LIGHT_GRAY); aTable2.addCell(cell); } Color color = new Color(204, 204, 255); // for (int i = 0; i < netifVector.size(); i++) { // aTable2.addCell(""); String[] strs = (String[]) netifVector.get(i); String ifname = strs[1]; String index = strs[0]; for (int j = 0; j < strs.length; j++) { if (j == 1) { String linkuse = ""; if (portconfigHash != null && portconfigHash.size() > 0) { if (portconfigHash.get(ip + ":" + index) != null) linkuse = (String) portconfigHash.get(ip + ":" + index); } Cell cell1 = new Cell(strs[j]); Cell cell2 = new Cell(linkuse); if (i % 2 != 0) { cell1.setBackgroundColor(color); cell2.setBackgroundColor(color); } aTable2.addCell(cell1); aTable2.addCell(cell2); } else if (j > 1) { Cell cell3 = new Cell(strs[j]); if (i % 2 != 0) { cell3.setBackgroundColor(color); } aTable2.addCell(cell3); } else { Cell cell4 = new Cell(strs[j]); if (i % 2 != 0) { cell4.setBackgroundColor(color); } aTable2.addCell(cell4); } } // end } document.add(aTable2); } if ("0".equals(runmodel)) { // if (iprouterVector != null && iprouterVector.size() > 0) { Table aTable3 = new Table(7); float[] width2 = { 240f, 200f, 300f, 300f, 220f, 180f, 300f }; aTable3.setWidths(width2); aTable3.setWidth(100); // 100% aTable3.setAlignment(Element.ALIGN_CENTER);// aTable3.setAutoFillEmptyCells(true); // aTable3.setBorderWidth(1); // aTable3.setBorderColor(new Color(0, 125, 255)); // aTable3.setPadding(2);// aTable3.setSpacing(0);// aTable3.setBorder(2);// aTable3.endHeaders(); aTable3.addCell(""); // // allRow = allRow+1; for (int i = 0; i < ipRouterItemch.length; i++) { Cell cell = new Cell(ipRouterItemch[i]); aTable3.addCell(cell); } // for (int i = 0; i < iprouterVector.size(); i++) { aTable3.addCell(""); /* allRow = allRow + 1; */ IpRouter iprouter = (IpRouter) iprouterVector.get(i); Cell cell = new Cell(iprouter.getIfindex()); aTable3.addCell(cell); Cell cell1 = new Cell(iprouter.getDest()); aTable3.addCell(cell1); Cell cell2 = new Cell(iprouter.getNexthop()); aTable3.addCell(cell2); Cell cell3 = new Cell(iproutertype[Integer.parseInt(iprouter.getType().longValue() + "")]); aTable3.addCell(cell3); Cell cell4 = new Cell(iprouterproto[Integer.parseInt(iprouter.getProto().longValue() + "")]); aTable3.addCell(cell4); Cell cell5 = new Cell(iprouter.getMask()); aTable3.addCell(cell5); } document.add(aTable3); } } else { // List routerList = (ArrayList) reportHash.get("routerList"); Table aTable3 = new Table(7); float[] width2 = { 240f, 200f, 300f, 300f, 220f, 180f, 300f }; aTable3.setWidths(width2); aTable3.setWidth(100); // 100% aTable3.setAlignment(Element.ALIGN_CENTER);// aTable3.setAutoFillEmptyCells(true); // aTable3.setBorderWidth(1); // aTable3.setBorderColor(new Color(0, 125, 255)); // aTable3.setPadding(2);// aTable3.setSpacing(0);// aTable3.setBorder(2);// aTable3.endHeaders(); aTable3.addCell(""); // // allRow = allRow+1; for (int i = 0; i < ipRouterItemch.length; i++) { Cell cell = new Cell(ipRouterItemch[i]); aTable3.addCell(cell); } if (routerList != null) { for (int i = 0; i < routerList.size(); i++) { aTable3.addCell(""); RouterNodeTemp iprouter = (RouterNodeTemp) routerList.get(i); Cell cell = new Cell(iprouter.getIfindex()); aTable3.addCell(cell); Cell cell1 = new Cell(iprouter.getDest()); aTable3.addCell(cell1); Cell cell2 = new Cell(iprouter.getNexthop()); aTable3.addCell(cell2); Cell cell3 = new Cell(iprouter.getType()); aTable3.addCell(cell3); Cell cell4 = new Cell(iprouter.getProto()); aTable3.addCell(cell4); Cell cell5 = new Cell(iprouter.getMask()); aTable3.addCell(cell5); } document.add(aTable3); } } // doc if (reportports != null && reportports.size() > 0) { // // aTable4.addCell(""); for (int i = 0; i < reportports.size(); i++) { Table aTable4 = new Table(2); float[] width2 = { 300f, 300f }; aTable4.setWidths(width2); aTable4.setWidth(100); // 100% aTable4.setAlignment(Element.ALIGN_CENTER);// aTable4.setAutoFillEmptyCells(true); // aTable4.setBorderWidth(1); // aTable4.setBorderColor(new Color(0, 125, 255)); // aTable4.setPadding(2);// aTable4.setSpacing(0);// aTable4.setBorder(2);// aTable4.endHeaders(); // SysLogger.info(reportports.get(i).getClass()+"============================================="); com.afunms.config.model.Portconfig portconfig = (com.afunms.config.model.Portconfig) reportports .get(i); /* * tmpLabel = new Label(0, allRow, "" + * portconfig.getPortindex() + "(" + portconfig.getName() + * ")", b_labelFormat); * * sheet.addCell(tmpLabel); */ Cell cell = new Cell("" + portconfig.getPortindex() + "(" + portconfig.getName() + ")"); aTable4.addCell(cell); if (portconfig.getLinkuse() == null) portconfig.setLinkuse(""); Cell cell1 = new Cell(":" + portconfig.getLinkuse()); aTable4.addCell(cell1); document.add(aTable4); // Image img2 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + portconfig.getPortindex() + "ifspeed_day.png"); img2.setAbsolutePosition(0, 0); img2.setAlignment(Image.LEFT);// // sheet,0,0,5,1,,, img2.scalePercent(67); document.add(img2); } } // if (impReport.getChart() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(), impReport.getChart().getWidth(), impReport.getChart().getHeight()); } catch (IOException ioe) { } /* * WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos * .toByteArray()); */ Image img2 = Image.getInstance(baos.toByteArray()); img.setAbsolutePosition(0, 0); img.setAlignment(Image.LEFT);// img.scalePercent(67); document.add(img2); } document.close(); }