List of usage examples for com.lowagie.text.pdf PdfPTable getDefaultCell
public PdfPCell getDefaultCell()
PdfPCell
that will be used as reference for all the addCell
methods except addCell(PdfPCell)
. 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 w w. jav a2 s. c om 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 ww w . j av a 2 s. c om*/ 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.ainfosec.macresponse.report.RtfGenerator.java
License:Open Source License
private static void createDataSection(Paragraph paragraph, DisplayObject displayObject) { if (displayObject == null || displayObject.getObjects() == null) { return;/*from w w w . j a va 2 s .c om*/ } // See if the DisplayObject has a list or a single object if (displayObject.getObjects().size() == 1) { TreeObject treeObject = displayObject.getObjects().get(0); // There's only 1 item // For each column, create/add a label with the title and the data int i = 0; for (String columnName : displayObject.getColumnNames()) { StringBuffer sb = new StringBuffer(); // Add the column title sb.append(displayObject.getColumnTitles()[i]); sb.append(": "); // Get the value of the field try { Field field = treeObject.getClass().getDeclaredField(columnName); String val = (String) field.get(treeObject); if (val == null) { val = ""; } // Add the value sb.append(val); sb.append("\n"); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Put the string into the paragraph paragraph.add(sb.toString()); i++; } } else { PdfPTable table = new PdfPTable(displayObject.getColumnTitles().length); table.setWidthPercentage(100); table.setHorizontalAlignment(Element.ALIGN_CENTER); for (String columnName : displayObject.getColumnTitles()) { table.getDefaultCell().setBackgroundColor(Color.CYAN); table.addCell(columnName); table.getDefaultCell().setBackgroundColor(Color.WHITE); } for (TreeObject to1 : displayObject.getObjects()) { for (String columnName : displayObject.getColumnNames()) { try { Field field = to1.getClass().getDeclaredField(columnName); String val = (String) field.get(to1); if (val == null) { val = ""; } table.addCell(val); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } table.getDefaultCell().setColspan(displayObject.getColumnTitles().length); table.getDefaultCell().setBorder(SWT.NONE); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // TODO Paul number the tables table.addCell("Table: " + displayObject.getTitle()); document.add(new RtfTable(document, table)); } }
From source file:com.allinfinance.system.util.PdfUtil.java
License:Open Source License
public static void create(String mchtId, String selMchtId, String path, List<Object[]> list, LinkedHashMap<String, List<Object[]>> map, Set<String> set) throws Exception { BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); ////ww w .j av a2s. c o m Font font17 = new Font(bfChinese, 17, Font.BOLD); Font font8 = new Font(bfChinese, 8, Font.NORMAL); Font font9 = new Font(bfChinese, 9, Font.NORMAL); Font font9Bold = new Font(bfChinese, 9, Font.BOLD); Font font8Red = new Font(bfChinese, 8, Font.NORMAL); font8Red.setColor(Color.RED); Font font8Green = new Font(bfChinese, 8, Font.NORMAL); font8Green.setColor(Color.GREEN); logger.info("Starting build document..."); Document document = new Document(PageSize.A4, 36, 36, 36, 36); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path)); document.open(); LINECANVAS border = new LINECANVAS(); // float[] widths = { 0.1f, 0.35f, 0.35f, 0.1f, 0.1f }; PdfPTable table = new PdfPTable(widths); table.setWidthPercentage(100); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table.getDefaultCell().setFixedHeight(12); //CELL PdfPCell cellMchntId = new PdfPCell(new Paragraph(mchtId, font8)); cellMchntId.setBorder(PdfPCell.BOTTOM); cellMchntId.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cellMchntName = new PdfPCell(new Paragraph(InformationUtil.getMchtName(mchtId), font8)); cellMchntName.setBorder(PdfPCell.BOTTOM); cellMchntName.setHorizontalAlignment(Element.ALIGN_CENTER); String point = InformationUtil.getCurPaperPoint(selMchtId); PdfPCell cellPoint; cellPoint = new PdfPCell(new Paragraph(point, font8Red)); cellPoint.setBorder(PdfPCell.NO_BORDER); cellPoint.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cellLevel; String level = InformationUtil.getCurPaperLevel(selMchtId); if (Integer.valueOf(point) >= 60) { cellLevel = new PdfPCell(new Paragraph(level, font8Green)); } else { cellLevel = new PdfPCell(new Paragraph(level, font8Red)); } cellLevel.setBorder(PdfPCell.NO_BORDER); cellLevel.setHorizontalAlignment(Element.ALIGN_CENTER); // Image img = Image.getInstance( ServletActionContext.getServletContext().getResource("/ext/resources/images/Title_logo.gif")); img.scalePercent(70); float w = img.getScaledWidth(); float h = img.getScaledHeight(); writer.getDirectContent().addImage(img, w, 0, 0, h, 36, PageSize.A4.getHeight() - 36 - h); // PdfPCell cell = new PdfPCell(new Paragraph("?", font17)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setColspan(5); cell.setFixedHeight(h); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); cell = new PdfPCell(); cell.setFixedHeight(20); cell.setColspan(5); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); table.addCell(new Paragraph("?", font8)); table.addCell(cellMchntId); table.addCell(" "); table.addCell(new Paragraph(": ", font8)); table.addCell(cellPoint); table.addCell(new Paragraph("??", font8)); table.addCell(cellMchntName); table.addCell(" "); table.addCell(new Paragraph(": ", font8)); table.addCell(cellLevel); document.add(table); document.add(new Paragraph("\n\n")); //? PdfPTable t = new PdfPTable(1); Iterator<Object[]> it0 = list.iterator(); int i = 1; while (it0.hasNext()) { Object[] obj = it0.next(); PdfPCell c = new PdfPCell(); c.addElement(new Paragraph("Q" + String.valueOf(i++) + "" + obj[1].toString(), font9Bold)); List<Object[]> opts = map.get(obj[0].toString()); String opt = ""; Iterator<Object[]> it1 = opts.iterator(); while (it1.hasNext()) { Object[] o = it1.next(); if (set.contains(o[0])) { opt += "? "; opt += o[1].toString(); opt += " "; } else { opt += " "; opt += o[1].toString(); opt += " "; } } c.addElement(new Paragraph(opt.trim(), font9)); c.setBorder(PdfPCell.NO_BORDER); if (i - 1 != list.size()) { c.setCellEvent(border); } t.addCell(c); } PdfPTable oTable = new PdfPTable(1); oTable.setWidthPercentage(100); PdfPCell ce = new PdfPCell(t); ce.setBorderColor(Color.GRAY); oTable.addCell(ce); document.add(oTable); document.close(); logger.info("Finish build document..."); }
From source file:com.allinfinance.system.util.PdfUtil.java
License:Open Source License
public static void create(String path, List<Object[]> list, LinkedHashMap<String, List<Object[]>> map) throws Exception { BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); ////from w w w. j av a 2 s .c o m Font font17 = new Font(bfChinese, 17, Font.BOLD); Font font8 = new Font(bfChinese, 8, Font.NORMAL); Font font10 = new Font(bfChinese, 10, Font.NORMAL); Font font10Bold = new Font(bfChinese, 10, Font.BOLD); Font font8Red = new Font(bfChinese, 8, Font.NORMAL); font8Red.setColor(Color.RED); Font font8Green = new Font(bfChinese, 8, Font.NORMAL); font8Green.setColor(Color.GREEN); logger.info("Starting build document..."); Document document = new Document(PageSize.A4, 36, 36, 36, 36); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path)); document.open(); LINECANVAS border = new LINECANVAS(); // float[] widths = { 0.1f, 0.35f, 0.55f }; PdfPTable table = new PdfPTable(widths); table.setWidthPercentage(100); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table.getDefaultCell().setFixedHeight(12); //CELL PdfPCell cellMchntId = new PdfPCell(new Paragraph("XXXXXXXXXXXXXXX", font8)); cellMchntId.setBorder(PdfPCell.BOTTOM); cellMchntId.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cellMchntName = new PdfPCell(new Paragraph("?", font8)); cellMchntName.setBorder(PdfPCell.BOTTOM); cellMchntName.setHorizontalAlignment(Element.ALIGN_CENTER); // Image img = Image.getInstance( ServletActionContext.getServletContext().getResource("/ext/resources/images/Title_logo.gif")); img.scalePercent(70); float w = img.getScaledWidth(); float h = img.getScaledHeight(); writer.getDirectContent().addImage(img, w, 0, 0, h, 36, PageSize.A4.getHeight() - 36 - h); // PdfPCell cell = new PdfPCell(new Paragraph("?", font17)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setColspan(3); cell.setFixedHeight(h); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); cell = new PdfPCell(); cell.setFixedHeight(20); cell.setColspan(3); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); table.addCell(new Paragraph("?", font8)); table.addCell(cellMchntId); table.addCell(" "); table.addCell(new Paragraph("??", font8)); table.addCell(cellMchntName); table.addCell(" "); document.add(table); document.add(new Paragraph("\n\n")); //? PdfPTable t = new PdfPTable(1); Iterator<Object[]> it0 = list.iterator(); int i = 1; while (it0.hasNext()) { Object[] obj = it0.next(); PdfPCell c = new PdfPCell(); c.addElement(new Paragraph("Q" + String.valueOf(i++) + "" + obj[1].toString(), font10Bold)); List<Object[]> opts = map.get(obj[0].toString()); String opt = ""; Iterator<Object[]> it1 = opts.iterator(); while (it1.hasNext()) { Object[] o = it1.next(); opt += " "; opt += o[1].toString(); opt += " "; } c.addElement(new Paragraph(opt.trim(), font10)); c.setBorder(PdfPCell.NO_BORDER); if (i - 1 != list.size()) { c.setCellEvent(border); } t.addCell(c); } PdfPTable oTable = new PdfPTable(1); oTable.setWidthPercentage(100); PdfPCell ce = new PdfPCell(t); ce.setBorderColor(Color.GRAY); oTable.addCell(ce); document.add(oTable); document.close(); logger.info("Finish build document..."); }
From source file:com.bytecode.customexporter.PDFCustomExporter.java
protected void exportCells(DataTable table, PdfPTable pdfTable) { for (UIColumn col : table.getColumns()) { if (col instanceof DynamicColumn) { ((DynamicColumn) col).applyStatelessModel(); }/*from www. j a v a2s .c om*/ if (col.isRendered() && col.isExportable()) { if (col.getSelectionMode() != null) { pdfTable.addCell(new Paragraph(col.getSelectionMode(), this.cellFont)); continue; } addColumnValue(pdfTable, col.getChildren(), this.cellFont, "data"); } } pdfTable.completeRow(); FacesContext context = null; if (table.getRowIndex() == 0) { for (UIComponent component : table.getChildren()) { if (component instanceof RowExpansion) { RowExpansion rowExpansion = (RowExpansion) component; if (rowExpansion.getChildren() != null) { if (rowExpansion.getChildren().get(0) instanceof DataTable) { DataTable childTable = (DataTable) rowExpansion.getChildren().get(0); childTable.setRowIndex(-1); } if (rowExpansion.getChildren().get(0) instanceof DataList) { DataList childList = (DataList) rowExpansion.getChildren().get(0); childList.setRowIndex(-1); } } } } } for (UIComponent component : table.getChildren()) { if (component instanceof RowExpansion) { RowExpansion rowExpansion = (RowExpansion) component; if (rowExpansion.getChildren() != null) { if (rowExpansion.getChildren().get(0) instanceof DataTable) { DataTable childTable = (DataTable) rowExpansion.getChildren().get(0); PdfPTable pdfTableChild = exportPDFTable(context, childTable, false, false, "-", false); PdfPCell cell = new PdfPCell(); cell.addElement(pdfTableChild); cell.setColspan(pdfTable.getNumberOfColumns()); pdfTable.addCell(cell); } if (rowExpansion.getChildren().get(0) instanceof DataList) { DataList list = (DataList) rowExpansion.getChildren().get(0); PdfPTable pdfTableChild = exportPDFTable(context, list, false, "-"); pdfTableChild.getDefaultCell().setBorder(Rectangle.NO_BORDER); PdfPCell cell = new PdfPCell(); cell.addElement(pdfTableChild); cell.setColspan(pdfTable.getNumberOfColumns()); } } } pdfTable.completeRow(); } }
From source file:com.crm.webapp.util.PDFCustomExporter.java
License:Apache License
protected void exportCells(DataTable table, PdfPTable pdfTable, int rowIndex) { for (UIColumn col : table.getColumns()) { UIComponent component = (UIComponent) col; ////Adding RowIndex for custom Export if (component.getId().equalsIgnoreCase("subject")) { int value = rowIndex; PdfPCell cell = new PdfPCell(new Paragraph(value + "")); //addColumnAlignments(component, cell); if (facetBackground != null) { cell.setBackgroundColor(facetBackground); }/*from w w w. java 2 s.c om*/ cell.setHorizontalAlignment(Element.ALIGN_CENTER); System.out.println("value is" + value); pdfTable.addCell(cell); } if (!col.isRendered()) { continue; } if (col instanceof DynamicColumn) { ((DynamicColumn) col).applyModel(); } if (col.isExportable()) { if (col.getSelectionMode() != null) { pdfTable.addCell(new Paragraph(col.getSelectionMode(), this.cellFont)); continue; } addColumnValue(pdfTable, col.getChildren(), this.cellFont, "data"); } } pdfTable.completeRow(); FacesContext context = null; if (table.getRowIndex() == 0) { for (UIComponent component : table.getChildren()) { if (component instanceof RowExpansion) { RowExpansion rowExpansion = (RowExpansion) component; if (rowExpansion.getChildren() != null) { if (rowExpansion.getChildren().get(0) instanceof DataTable) { DataTable childTable = (DataTable) rowExpansion.getChildren().get(0); childTable.setRowIndex(-1); } if (rowExpansion.getChildren().get(0) instanceof DataList) { DataList childList = (DataList) rowExpansion.getChildren().get(0); childList.setRowIndex(-1); } } } } } table.setRowIndex(table.getRowIndex() + 1); for (UIComponent component : table.getChildren()) { if (component instanceof RowExpansion) { RowExpansion rowExpansion = (RowExpansion) component; if (rowExpansion.getChildren() != null) { if (rowExpansion.getChildren().get(0) instanceof DataTable) { DataTable childTable = (DataTable) rowExpansion.getChildren().get(0); PdfPTable pdfTableChild = exportPDFTable(context, childTable, false, false, "-", false); PdfPCell cell = new PdfPCell(); cell.addElement(pdfTableChild); cell.setColspan(pdfTable.getNumberOfColumns()); pdfTable.addCell(cell); } if (rowExpansion.getChildren().get(0) instanceof DataList) { DataList list = (DataList) rowExpansion.getChildren().get(0); PdfPTable pdfTableChild = exportPDFTable(context, list, false, "-"); pdfTableChild.getDefaultCell().setBorder(Rectangle.NO_BORDER); PdfPCell cell = new PdfPCell(); cell.addElement(pdfTableChild); cell.setColspan(pdfTable.getNumberOfColumns()); } } } pdfTable.completeRow(); } }
From source file:com.efficio.fieldbook.web.demo.controller.BarCodeController.java
License:Open Source License
/** * Upload file./*from w w w . ja v a 2 s .c o m*/ * * @param uploadForm the upload form * @param result the result * @param model the model * @return the string */ @ResponseBody @RequestMapping(method = RequestMethod.POST) public String uploadFile(@ModelAttribute("barCodeForm") BarCodeForm barCodeForm, BindingResult result, Model model, HttpServletResponse response) { int width = 60; int height = 48; String delimeter = "|"; StringBuilder barCodeString = new StringBuilder(); barCodeString.append(barCodeForm.getEntryNo()).append(delimeter).append(barCodeForm.getGid()) .append(delimeter).append(barCodeForm.getDesignation()).append(delimeter) .append(barCodeForm.getName()).append(delimeter).append(barCodeForm.getRep()).append(delimeter) .append(barCodeForm.getColumn()).append(delimeter).append(barCodeForm.getRange()); BitMatrix bitMatrix; try { String barCodeLabel = "3|SM114-1A-1-1-1B"; //barCodeLabel = barCodeString.toString(); bitMatrix = new Code128Writer().encode(barCodeLabel, BarcodeFormat.CODE_128, width, height, null); String imageLocation = Math.random() + ".png"; //"src/test/resources/barcode/zxing_barcode.png"; MatrixToImageWriter.writeToStream(bitMatrix, "png", new FileOutputStream(new File(imageLocation))); String currentDate = DateUtil.getCurrentDate(); String fileName = currentDate + ".doc"; response.setHeader("Content-disposition", "attachment; filename=" + fileName); File xls = new File(fileName); // the selected name + current date FileInputStream in; try { Image image1 = Image.getInstance(imageLocation); //image1.scalePercent(50); //image1.setAbsolutePosition(10f, 10f); //document.add(image1); //PageSize.A4 Document document = new Document(PageSize.LETTER); // step 2 PdfWriter.getInstance(document, new FileOutputStream(fileName)); // step 3 document.open(); // step 4 // we'll use 4 images in this example /* Image[] img = { Image.getInstance(String.format(RESOURCE, "0120903")), Image.getInstance(String.format(RESOURCE, "0290334")), Image.getInstance(String.format(RESOURCE, "0376994")), Image.getInstance(String.format(RESOURCE, "0348150")) };*/ PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100); // first movie table.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM); Phrase phrase = new Phrase(); phrase.add("Entry # " + barCodeForm.getEntryNo()); phrase.add("\n"); phrase.add("Designation " + barCodeForm.getDesignation()); phrase.add("\n"); phrase.add("Rep " + barCodeForm.getRep()); phrase.add("\n"); phrase.add("GID " + barCodeForm.getGid()); phrase.add("\n"); phrase.add("Trial/Nursery Name " + barCodeForm.getName()); phrase.add("\n"); phrase.add("Col " + barCodeForm.getColumn()); phrase.add("\n"); phrase.add("Range " + barCodeForm.getRange()); table.addCell(phrase); // we add the image with addCell() table.addCell(image1); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM); table.addCell("X-Men: The Last Stand"); // we add the image with addCell() table.addCell(image1); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM); table.addCell("X-Men: The Last Stand"); // we add the image with addCell() table.addCell(image1); // we complete the table (otherwise the last row won't be rendered) table.completeRow(); document.add(table); document.close(); in = new FileInputStream(xls); OutputStream out = response.getOutputStream(); byte[] buffer = new byte[BUFFER_SIZE]; // use bigger if you want int length = 0; while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } in.close(); out.close(); } catch (FileNotFoundException e) { LOG.error(e.getMessage(), e); } catch (IOException e) { LOG.error(e.getMessage(), e); } return ""; } catch (WriterException e) { LOG.error(e.getMessage(), e); } catch (Exception e) { LOG.error(e.getMessage(), e); } return show(barCodeForm, model); }
From source file:com.geek.tutorial.itext.acroform.TextFieldForm.java
License:Open Source License
public TextFieldForm() throws Exception { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TextFieldForm.pdf")); document.open();//w ww . ja va2s . c o m PdfPTable table = new PdfPTable(2); table.getDefaultCell().setPadding(5f); // Code 1, will only affect empty field table.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell; // Code 2, add name TextField table.addCell("Name"); TextField nameField = new TextField(writer, new Rectangle(0, 0, 200, 10), "nameField"); nameField.setBackgroundColor(Color.WHITE); nameField.setBorderColor(Color.BLACK); nameField.setBorderWidth(1); nameField.setBorderStyle(PdfBorderDictionary.STYLE_SOLID); nameField.setText(""); nameField.setAlignment(Element.ALIGN_LEFT); nameField.setOptions(TextField.REQUIRED); cell = new PdfPCell(); cell.setMinimumHeight(10); cell.setCellEvent(new FieldCell(nameField.getTextField(), 200, writer)); table.addCell(cell); // force upper case javascript writer.addJavaScript("var nameField = this.getField('nameField');" + "nameField.setAction('Keystroke'," + "'forceUpperCase()');" + "" + "function forceUpperCase(){" + "if(!event.willCommit)event.change = " + "event.change.toUpperCase();" + "}"); // Code 3, add empty row table.addCell(""); table.addCell(""); // Code 4, add age TextField table.addCell("Age"); TextField ageComb = new TextField(writer, new Rectangle(0, 0, 30, 10), "ageField"); ageComb.setBorderColor(Color.BLACK); ageComb.setBorderWidth(1); ageComb.setBorderStyle(PdfBorderDictionary.STYLE_SOLID); ageComb.setText("12"); ageComb.setAlignment(Element.ALIGN_RIGHT); ageComb.setMaxCharacterLength(2); ageComb.setOptions(TextField.COMB | TextField.DO_NOT_SCROLL); cell = new PdfPCell(); cell.setMinimumHeight(10); cell.setCellEvent(new FieldCell(ageComb.getTextField(), 30, writer)); table.addCell(cell); // validate age javascript writer.addJavaScript("var ageField = this.getField('ageField');" + "ageField.setAction('Validate','checkAge()');" + "function checkAge(){" + "if(event.value < 12){" + "app.alert('Warning! Applicant\\'s age can not" + " be younger than 12.');" + "event.value = 12;" + "}}"); // add empty row table.addCell(""); table.addCell(""); // Code 5, add age TextField table.addCell("Comment"); TextField comment = new TextField(writer, new Rectangle(0, 0, 200, 100), "commentField"); comment.setBorderColor(Color.BLACK); comment.setBorderWidth(1); comment.setBorderStyle(PdfBorderDictionary.STYLE_SOLID); comment.setText(""); comment.setOptions(TextField.MULTILINE | TextField.DO_NOT_SCROLL); cell = new PdfPCell(); cell.setMinimumHeight(100); cell.setCellEvent(new FieldCell(comment.getTextField(), 200, writer)); table.addCell(cell); // check comment characters length javascript writer.addJavaScript("var commentField = " + "this.getField('commentField');" + "commentField" + ".setAction('Keystroke','checkLength()');" + "function checkLength(){" + "if(!event.willCommit && " + "event.value.length > 100){" + "app.alert('Warning! Comment can not " + "be more than 100 characters.');" + "event.change = '';" + "}}"); // add empty row table.addCell(""); table.addCell(""); // Code 6, add submit button PushbuttonField submitBtn = new PushbuttonField(writer, new Rectangle(0, 0, 35, 15), "submitPOST"); submitBtn.setBackgroundColor(Color.GRAY); submitBtn.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED); submitBtn.setText("POST"); submitBtn.setOptions(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT); PdfFormField submitField = submitBtn.getField(); submitField.setAction(PdfAction.createSubmitForm("http://www.geek-tutorials.com/java/itext/submit.php", null, PdfAction.SUBMIT_HTML_FORMAT)); cell = new PdfPCell(); cell.setMinimumHeight(15); cell.setCellEvent(new FieldCell(submitField, 35, writer)); table.addCell(cell); // Code 7, add reset button PushbuttonField resetBtn = new PushbuttonField(writer, new Rectangle(0, 0, 35, 15), "reset"); resetBtn.setBackgroundColor(Color.GRAY); resetBtn.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED); resetBtn.setText("RESET"); resetBtn.setOptions(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT); PdfFormField resetField = resetBtn.getField(); resetField.setAction(PdfAction.createResetForm(null, 0)); cell = new PdfPCell(); cell.setMinimumHeight(15); cell.setCellEvent(new FieldCell(resetField, 35, writer)); table.addCell(cell); document.add(table); document.close(); }
From source file:com.gtdfree.test.PDFTestFont.java
License:Open Source License
/** * Fonts and encoding.//from ww w . j a va 2s. c o m * @param args no arguments needed */ public static void main(String[] args) { System.out.println("Encodings"); String[] names = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); System.out.println(Arrays.toString(names)); /*System.out.println("---"); try { System.getProperties().store(System.out, ""); } catch (IOException e1) { e1.printStackTrace(); } System.out.println("---");*/ //System.out.println(System.getenv()); //System.out.println("---"); //String font= System.getProperty("java.home")+"/lib/fonts/LucidaBrightRegular.ttf"; //String font= "fonts/DejaVuSans.ttf"; //byte[] ttf= ApplicationHelper.loadResource(font); try { // step 1 Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2 PdfWriter.getInstance(document, new FileOutputStream("encodingfont.pdf")); // step 3 document.open(); // step 4 String all[] = { "Symbol", "ZapfDingbats" }; Font hex = new Font(Font.HELVETICA, 5); for (int z = 0; z < all.length; ++z) { String file = all[z]; document.add(new Paragraph( "Unicode equivalence for the font \"" + file + "\" with the encoding \"" + file + "\"\n")); /*char tb[]; if (z == 0) tb = SYMBOL_TABLE; else tb = DINGBATS_TABLE;*/ BaseFont bf; if (z == 2) { bf = BaseFont.createFont(file, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, true, null, null); ; } else { bf = BaseFont.createFont(file, file, true); } Font f = new Font(bf, 12); PdfPTable table = new PdfPTable(16); table.setWidthPercentage(100); table.getDefaultCell().setBorderWidth(1); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (char k = 0; k < Character.MAX_VALUE; ++k) { char c = k; if (bf.charExists(c)) { Phrase ph = new Phrase(12, new String(new char[] { c }), f); ph.add(new Phrase(12, "\n" + Integer.toString(c) + "\n" + cst(c), hex)); table.addCell(ph); } /* else { Phrase ph = new Phrase("\u00a0"); ph.add(new Phrase(12, "\n\n" + cst(c), hex)); table.addCell(ph); }*/ } document.add(table); document.newPage(); } // step 5 document.close(); FontFactory.registerDirectories(); Set<?> s = FontFactory.getRegisteredFonts(); System.out.println("Fonts: " + s); s = FontFactory.getRegisteredFamilies(); System.out.println("Families: " + s); ArrayList<Font> f = new ArrayList<Font>(s.size()); for (Object name : s) { try { f.add(FontFactory.getFont(name.toString(), "UTF-8", true, 12, Font.NORMAL, Color.BLACK, true)); } catch (Exception e) { f.add(FontFactory.getFont(name.toString(), "UTF-8", false, 12, Font.NORMAL, Color.BLACK, true)); } } Collections.sort(f, new Comparator<Font>() { @Override public int compare(Font o1, Font o2) { return o1.getFamilyname().compareTo(o2.getFamilyname()); } }); for (Font ff : f) { if (ff.getBaseFont() == null) { continue; } System.out.println(ff.getFamilyname() + " " + ff.getBaseFont().isEmbedded()); } } catch (Exception de) { de.printStackTrace(); } }