List of usage examples for com.lowagie.text Document setFooter
public void setFooter(HeaderFooter footer)
From source file:ambit2.db.reporters.PDFReporter.java
public void header(Document output, Q query) { output.addCreationDate();//from ww w . ja v a 2s . c o m output.addCreator(getClass().getName()); output.addSubject(""); output.addAuthor("http://ambit.sourceforge.net"); output.addHeader("License", getLicenseURI()); output.addTitle(query.toString()); output.addKeywords(query.toString()); if (getLicenseURI() != null) { HeaderFooter footer = new HeaderFooter(new Phrase(String.format("License %s", getLicenseURI())), false); footer.setAlignment(Element.ALIGN_CENTER); output.setFooter(footer); } output.open(); font = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL); table = new PdfPTable(new float[] { 3f, 5f }); table.setWidthPercentage(100); try { writeHeader(output); } catch (Exception x) { } }
From source file:be.fedict.eid.tsl.Tsl2PdfExporter.java
License:Open Source License
/** * Produce a human readable export of the given tsl to the given file. * /* w ww .j av a 2 s. c o m*/ * @param tsl * the TrustServiceList to export * @param pdfFile * the file to generate * @return * @throws IOException */ public void humanReadableExport(final TrustServiceList tsl, final File pdfFile) { Document document = new Document(); OutputStream outputStream; try { outputStream = new FileOutputStream(pdfFile); } catch (FileNotFoundException e) { throw new RuntimeException("file not found: " + pdfFile.getAbsolutePath(), e); } try { final PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream); pdfWriter.setPDFXConformance(PdfWriter.PDFA1B); // title final EUCountry country = EUCountry.valueOf(tsl.getSchemeTerritory()); final String title = country.getShortSrcLangName() + " (" + country.getShortEnglishName() + "): Trusted List"; Phrase footerPhrase = new Phrase("PDF document generated on " + new Date().toString() + ", page ", headerFooterFont); HeaderFooter footer = new HeaderFooter(footerPhrase, true); document.setFooter(footer); Phrase headerPhrase = new Phrase(title, headerFooterFont); HeaderFooter header = new HeaderFooter(headerPhrase, false); document.setHeader(header); document.open(); addTitle(title, title0Font, Paragraph.ALIGN_CENTER, 0, 20, document); addLongItem("Scheme name", tsl.getSchemeName(), document); addLongItem("Legal Notice", tsl.getLegalNotice(), document); // information table PdfPTable informationTable = createInfoTable(); addItemRow("Scheme territory", tsl.getSchemeTerritory(), informationTable); addItemRow("Scheme status determination approach", substringAfter(tsl.getStatusDeterminationApproach(), "StatusDetn/"), informationTable); /* final List<String> schemeTypes = new ArrayList<String>(); for (final String schemeType : tsl.getSchemeTypes()) { schemeTypes.add(schemeType); } */ final List<String> schemeTypes = new ArrayList<String>(); List<NonEmptyMultiLangURIType> uris = tsl.getSchemeTypes(); for (NonEmptyMultiLangURIType uri : uris) { schemeTypes.add(uri.getValue()); } addItemRow("Scheme type community rules", schemeTypes, informationTable); addItemRow("Issue date", tsl.getListIssueDateTime().toString(), informationTable); addItemRow("Next update", tsl.getNextUpdate().toString(), informationTable); addItemRow("Historical information period", tsl.getHistoricalInformationPeriod().toString() + " days", informationTable); addItemRow("Sequence number", tsl.getSequenceNumber().toString(), informationTable); addItemRow("Scheme information URIs", tsl.getSchemeInformationUris(), informationTable); document.add(informationTable); addTitle("Scheme Operator", title1Font, Paragraph.ALIGN_CENTER, 0, 10, document); informationTable = createInfoTable(); addItemRow("Scheme operator name", tsl.getSchemeOperatorName(), informationTable); PostalAddressType schemeOperatorPostalAddress = tsl.getSchemeOperatorPostalAddress(Locale.ENGLISH); addItemRow("Scheme operator street address", schemeOperatorPostalAddress.getStreetAddress(), informationTable); addItemRow("Scheme operator postal code", schemeOperatorPostalAddress.getPostalCode(), informationTable); addItemRow("Scheme operator locality", schemeOperatorPostalAddress.getLocality(), informationTable); addItemRow("Scheme operator state", schemeOperatorPostalAddress.getStateOrProvince(), informationTable); addItemRow("Scheme operator country", schemeOperatorPostalAddress.getCountryName(), informationTable); List<String> schemeOperatorElectronicAddressess = tsl.getSchemeOperatorElectronicAddresses(); addItemRow("Scheme operator contact", schemeOperatorElectronicAddressess, informationTable); document.add(informationTable); addTitle("Trust Service Providers", title1Font, Paragraph.ALIGN_CENTER, 10, 2, document); List<TrustServiceProvider> trustServiceProviders = tsl.getTrustServiceProviders(); for (TrustServiceProvider trustServiceProvider : trustServiceProviders) { addTitle(trustServiceProvider.getName(), title1Font, Paragraph.ALIGN_LEFT, 10, 2, document); PdfPTable providerTable = createInfoTable(); addItemRow("Service provider trade name", trustServiceProvider.getTradeNames(), providerTable); addItemRow("Information URI", trustServiceProvider.getInformationUris(), providerTable); PostalAddressType postalAddress = trustServiceProvider.getPostalAddress(); addItemRow("Service provider street address", postalAddress.getStreetAddress(), providerTable); addItemRow("Service provider postal code", postalAddress.getPostalCode(), providerTable); addItemRow("Service provider locality", postalAddress.getLocality(), providerTable); addItemRow("Service provider state", postalAddress.getStateOrProvince(), providerTable); addItemRow("Service provider country", postalAddress.getCountryName(), providerTable); document.add(providerTable); List<TrustService> trustServices = trustServiceProvider.getTrustServices(); for (TrustService trustService : trustServices) { addTitle(trustService.getName(), title2Font, Paragraph.ALIGN_LEFT, 10, 2, document); PdfPTable serviceTable = createInfoTable(); addItemRow("Type", substringAfter(trustService.getType(), "Svctype/"), serviceTable); addItemRow("Status", substringAfter(trustService.getStatus(), "Svcstatus/"), serviceTable); addItemRow("Status starting time", trustService.getStatusStartingTime().toString(), serviceTable); document.add(serviceTable); addTitle("Service digital identity (X509)", title3Font, Paragraph.ALIGN_LEFT, 2, 0, document); final X509Certificate certificate = trustService.getServiceDigitalIdentity(); final PdfPTable serviceIdentityTable = createInfoTable(); addItemRow("Version", Integer.toString(certificate.getVersion()), serviceIdentityTable); addItemRow("Serial number", certificate.getSerialNumber().toString(), serviceIdentityTable); addItemRow("Signature algorithm", certificate.getSigAlgName(), serviceIdentityTable); addItemRow("Issuer", certificate.getIssuerX500Principal().toString(), serviceIdentityTable); addItemRow("Valid from", certificate.getNotBefore().toString(), serviceIdentityTable); addItemRow("Valid to", certificate.getNotAfter().toString(), serviceIdentityTable); addItemRow("Subject", certificate.getSubjectX500Principal().toString(), serviceIdentityTable); addItemRow("Public key", certificate.getPublicKey().toString(), serviceIdentityTable); // TODO certificate policies addItemRow("Subject key identifier", toHex(getSKId(certificate)), serviceIdentityTable); addItemRow("CRL distribution points", getCrlDistributionPoints(certificate), serviceIdentityTable); addItemRow("Authority key identifier", toHex(getAKId(certificate)), serviceIdentityTable); addItemRow("Key usage", getKeyUsage(certificate), serviceIdentityTable); addItemRow("Basic constraints", getBasicConstraints(certificate), serviceIdentityTable); byte[] encodedCertificate; try { encodedCertificate = certificate.getEncoded(); } catch (CertificateEncodingException e) { throw new RuntimeException("cert: " + e.getMessage(), e); } addItemRow("SHA1 Thumbprint", DigestUtils.shaHex(encodedCertificate), serviceIdentityTable); addItemRow("SHA256 Thumbprint", DigestUtils.sha256Hex(encodedCertificate), serviceIdentityTable); document.add(serviceIdentityTable); //add Scheme service definition if (null != trustService.getSchemeServiceDefinitionURI()) { addTitle("Scheme Service Definition URI", title3Font, Paragraph.ALIGN_LEFT, 2, 0, document); final PdfPTable schemeServiceDefinitionURITabel = createInfoTable(); for (NonEmptyMultiLangURIType uri : trustService.getSchemeServiceDefinitionURI().getURI()) { addItemRow(uri.getLang(), uri.getValue(), schemeServiceDefinitionURITabel); } document.add(schemeServiceDefinitionURITabel); } List<ExtensionType> extensions = trustService.getExtensions(); for (ExtensionType extension : extensions) { printExtension(extension, document); } addLongMonoItem("The decoded certificate:", certificate.toString(), document); addLongMonoItem("The certificate in PEM format:", toPem(certificate), document); ServiceHistoryType serviceHistoryType = trustService.getServiceHistoryInstanceType(); if (null != serviceHistoryType) { for (ServiceHistoryInstanceType serviceHistoryInstanceType : serviceHistoryType .getServiceHistoryInstance()) { PdfPTable serviceHistoryTable = createInfoTable(); //Service approval history information addTitle("Service approval history information", title3Font, Paragraph.ALIGN_LEFT, 10, 2, document); // service type identifier //5.6.2 Service name InternationalNamesType i18nServiceName = serviceHistoryInstanceType.getServiceName(); String servName = TrustServiceListUtils.getValue(i18nServiceName, Locale.ENGLISH); addItemRow("Name", servName, serviceHistoryTable); //5.6.1 Service type identifier addItemRow("Type", substringAfter(serviceHistoryInstanceType.getServiceTypeIdentifier(), "Svctype/"), serviceHistoryTable); addItemRow("Status", serviceHistoryInstanceType.getServiceStatus(), serviceHistoryTable); //5.6.4 Service previous status addItemRow("Previous status", serviceHistoryInstanceType.getServiceStatus(), serviceHistoryTable); //5.6.5 Previous status starting date and time addItemRow( "Previous starting time", new DateTime(serviceHistoryInstanceType .getStatusStartingTime().toGregorianCalendar()).toString(), serviceHistoryTable); //5.6.3 Service digital identity final X509Certificate previousCertificate = trustService.getServiceDigitalIdentity( serviceHistoryInstanceType.getServiceDigitalIdentity()); document.add(serviceHistoryTable); addTitle("Service digital identity (X509)", title4Font, Paragraph.ALIGN_LEFT, 2, 0, document); final PdfPTable serviceIdentityTableHistory = createInfoTable(); addItemRow("Version", Integer.toString(previousCertificate.getVersion()), serviceIdentityTableHistory); addItemRow("Serial number", previousCertificate.getSerialNumber().toString(), serviceIdentityTableHistory); addItemRow("Signature algorithm", previousCertificate.getSigAlgName(), serviceIdentityTableHistory); addItemRow("Issuer", previousCertificate.getIssuerX500Principal().toString(), serviceIdentityTableHistory); addItemRow("Valid from", previousCertificate.getNotBefore().toString(), serviceIdentityTableHistory); addItemRow("Valid to", previousCertificate.getNotAfter().toString(), serviceIdentityTableHistory); addItemRow("Subject", previousCertificate.getSubjectX500Principal().toString(), serviceIdentityTableHistory); addItemRow("Public key", previousCertificate.getPublicKey().toString(), serviceIdentityTableHistory); // TODO certificate policies addItemRow("Subject key identifier", toHex(getSKId(previousCertificate)), serviceIdentityTableHistory); addItemRow("CRL distribution points", getCrlDistributionPoints(previousCertificate), serviceIdentityTableHistory); addItemRow("Authority key identifier", toHex(getAKId(previousCertificate)), serviceIdentityTableHistory); addItemRow("Key usage", getKeyUsage(previousCertificate), serviceIdentityTableHistory); addItemRow("Basic constraints", getBasicConstraints(previousCertificate), serviceIdentityTableHistory); byte[] encodedHistoryCertificate; try { encodedHistoryCertificate = previousCertificate.getEncoded(); } catch (CertificateEncodingException e) { throw new RuntimeException("cert: " + e.getMessage(), e); } addItemRow("SHA1 Thumbprint", DigestUtils.shaHex(encodedHistoryCertificate), serviceIdentityTableHistory); addItemRow("SHA256 Thumbprint", DigestUtils.sha256Hex(encodedHistoryCertificate), serviceIdentityTableHistory); document.add(serviceIdentityTableHistory); ExtensionsListType previousExtensions = serviceHistoryInstanceType .getServiceInformationExtensions(); if (null != previousExtensions) { for (ExtensionType extension : previousExtensions.getExtension()) { printExtension(extension, document); } } addLongMonoItem("The decoded certificate:", previousCertificate.toString(), document); addLongMonoItem("The certificate in PEM format:", toPem(previousCertificate), document); } } } } X509Certificate signerCertificate = tsl.verifySignature(); if (null != signerCertificate) { Paragraph tslSignerTitle = new Paragraph("Trusted List Signer", title1Font); tslSignerTitle.setAlignment(Paragraph.ALIGN_CENTER); document.add(tslSignerTitle); final PdfPTable signerTable = createInfoTable(); addItemRow("Subject", signerCertificate.getSubjectX500Principal().toString(), signerTable); addItemRow("Issuer", signerCertificate.getIssuerX500Principal().toString(), signerTable); addItemRow("Not before", signerCertificate.getNotBefore().toString(), signerTable); addItemRow("Not after", signerCertificate.getNotAfter().toString(), signerTable); addItemRow("Serial number", signerCertificate.getSerialNumber().toString(), signerTable); addItemRow("Version", Integer.toString(signerCertificate.getVersion()), signerTable); byte[] encodedPublicKey = signerCertificate.getPublicKey().getEncoded(); addItemRow("Public key SHA1 Thumbprint", DigestUtils.shaHex(encodedPublicKey), signerTable); addItemRow("Public key SHA256 Thumbprint", DigestUtils.sha256Hex(encodedPublicKey), signerTable); document.add(signerTable); addLongMonoItem("The decoded certificate:", signerCertificate.toString(), document); addLongMonoItem("The certificate in PEM format:", toPem(signerCertificate), document); addLongMonoItem("The public key in PEM format:", toPem(signerCertificate.getPublicKey()), document); } document.close(); } catch (DocumentException e) { throw new RuntimeException("PDF document error: " + e.getMessage(), e); } catch (Exception e) { throw new RuntimeException("Exception: " + e.getMessage(), e); } }
From source file:ch.gpb.elexis.cst.view.CstResultPart.java
License:Open Source License
private void makeActions(final Control viewer) { actionScreenshot = new Action() { public void run() { if (profile == null) { SWTHelper.alert("No profile", "Ohne Profil kann kein Resultat erzeugt werden"); return; }//from w w w . j av a 2s . c o m GC gc = null; Image image = null; try { String latestPath = CoreHub.userCfg.get(CstPreference.CST_IDENTIFIER_LATESTPATH, null); if (latestPath == null) { latestPath = System.getProperty("user.home"); } FileDialog fd = new FileDialog(baseComposite.getShell(), SWT.SAVE); fd.setText("Save"); fd.setFilterPath(latestPath); String[] filterExt = { "*.png", "*.*" }; fd.setFilterExtensions(filterExt); fd.setFileName(CstService.generateFilename(patient)); String selected = fd.open(); if (selected == null) { return; } File selFile = new File(selected); CoreHub.userCfg.set(CstPreference.CST_IDENTIFIER_LATESTPATH, selFile.getParentFile().getAbsolutePath()); //if (profile.getAnzeigeTyp().toLowerCase().equals("effektiv")) { if (profile.getAnzeigeTyp().toLowerCase().equals(CstProfile.ANZEIGETYP_EFFEKTIV)) { if (profile.getAusgabeRichtung()) { image = new Image(viewer.getDisplay(), 1123, viewer.getBounds().height); } else { image = new Image(viewer.getDisplay(), 794, viewer.getBounds().height); } } else { image = new Image(viewer.getDisplay(), 794, viewer.getBounds().height); } ImageLoader loader = new ImageLoader(); gc = new GC(image); viewer.print(gc); gc.dispose(); loader.data = new ImageData[] { image.getImageData() }; loader.save(selected, SWT.IMAGE_PNG); } catch (Exception e) { log.error("Error saving png: " + e.toString()); showMessage("Error while saving PNG", e.getMessage()); } finally { if (image != null) { image.dispose(); } if (gc != null) { gc.dispose(); } } } }; actionScreenshot.setText(Messages.Cst_Text_Save_as_png); actionScreenshot.setToolTipText(Messages.Cst_Text_Save_as_png); actionScreenshot.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ELEMENT)); actionScreenshot.setImageDescriptor(Activator.getImageDescriptor(Activator.IMG_PNG_PATH)); // TODO: die pdf ausgabe ist eine ziemliche Baustelle - berarbeiten actionPdf = new Action() { public void run() { ////////////////////////// if (profile == null) { SWTHelper.alert("No profile", "Ohne Profil kann kein Resultat erzeugt werden"); return; } GC gc = null; Image image = null; try { String latestPath = CoreHub.userCfg.get(CstPreference.CST_IDENTIFIER_LATESTPATH, null); if (latestPath == null) { latestPath = System.getProperty("user.home"); } FileDialog fd = new FileDialog(baseComposite.getShell(), SWT.SAVE); fd.setText("Save"); fd.setFilterPath(latestPath); String[] filterExt = { "*.pdf", "*.*" }; fd.setFilterExtensions(filterExt); fd.setFileName(CstService.generateFilename(patient)); String selected = fd.open(); if (selected == null) { return; } File selFile = new File(selected); CoreHub.userCfg.set(CstPreference.CST_IDENTIFIER_LATESTPATH, selFile.getParentFile().getAbsolutePath()); int printHeigth = 1123; int printWidth = 794; if (profile.getAusgabeRichtung()) { printHeigth = 794; printWidth = 1123; } // get the image from the viewport image = new Image(viewer.getDisplay(), printWidth, viewer.getBounds().height); ImageLoader loader = new ImageLoader(); gc = new GC(image); viewer.print(gc); gc.dispose(); // prepare title data //Date date = new Date(); //SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm"); Patient patient = Patient.load(profile.getKontaktId()); //String sTitle = "Gemeinschaftspraxis Brunnmatt Dr. Beat Knzi "; String sTitle; sTitle = profile.getOutputHeader() == null ? "No header configured!" : profile.getOutputHeader(); if (sTitle == null || sTitle.length() == 0) { sTitle = "No header configured!"; } sTitle = sTitle + " Datum: " + CstService.getReadableDateAndTime(); // get option (paging to A4/ in one piece) int pdfOutputOption = 0; boolean onePage = true; PdfOptionsDialog dialog = new PdfOptionsDialog(baseComposite.getShell()); dialog.create(); if (dialog.open() == Window.OK) { pdfOutputOption = dialog.getPdfOutputOption(); if (pdfOutputOption == PdfOptionsDialog.OPTION_ONE_PAGE) { onePage = true; } else { onePage = false; } } float docHeight = viewer.getBounds().height; docHeight = docHeight / 7.5f; float fontSize = 12f; if (docHeight < 360f) { docHeight = 360f; } BufferedImage bimage = ImageUtils.convertToAWT(image.getImageData()); // create an Itextt Image from AWT BufferedImage com.lowagie.text.Image itextImage = null; java.awt.Image awtImage = null; try { awtImage = Toolkit.getDefaultToolkit().createImage(bimage.getSource()); itextImage = com.lowagie.text.Image.getInstance(awtImage, null); } catch (Exception e) { log.error("Error on image loading: " + e.toString()); e.printStackTrace(); } // only for debugging //loader.data = new ImageData[] { image.getImageData() }; //loader.save("C:\\Users\\daniel\\tmp\\debug.png", SWT.IMAGE_PNG); Rectangle pagesize = new Rectangle(595f, itextImage.getHeight() * 0.75f); // is it a4 quer? if (profile.getAusgabeRichtung()) { pagesize = new Rectangle(842f, itextImage.getHeight() * 0.75f); } //System.out.println("pagesize: " + pagesize.toString()); Document document; if (onePage) { document = new Document(pagesize); } else { document = new Document(PageSize.A4); if (profile.getAusgabeRichtung()) { document = new Document(PageSize.A4.rotate()); } } document.addCreationDate(); try { // creation of the different writers PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(selected)); // various fonts BaseFont bf_helv = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", true); BaseFont bf_times = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", true); BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", true); com.lowagie.text.Font fontHelv12 = new com.lowagie.text.Font(bf_helv, fontSize); com.lowagie.text.Font fontTimes = new com.lowagie.text.Font(bf_times, fontSize); fontTimes.setSize(fontSize); fontTimes.setStyle(com.lowagie.text.Font.ITALIC); Chunk chunkHeader = new Chunk(sTitle, FontFactory.getFont(FontFactory.HELVETICA, fontSize, com.lowagie.text.Font.NORMAL, new java.awt.Color(255, 0, 0))); com.lowagie.text.Phrase phraseHeader = new com.lowagie.text.Phrase(chunkHeader); // headers and footers must be added before the document // is opened Chunk chunkFooter = new Chunk("Seite: ", FontFactory.getFont(FontFactory.HELVETICA, fontSize, com.lowagie.text.Font.BOLD, new java.awt.Color(0, 0, 0))); Phrase phraseFooter = new Phrase(chunkFooter); phraseFooter.setFont(fontHelv12); HeaderFooter footer = new HeaderFooter(phraseFooter, true); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); document.setFooter(footer); Phrase headerPhrase = new Phrase(sTitle); headerPhrase.setFont(fontTimes); HeaderFooter header = new HeaderFooter(phraseHeader, false); header.setBorder(Rectangle.BOTTOM); header.setBorderWidth(0.5f); header.setAlignment(Element.ALIGN_LEFT); document.setHeader(header); document.open(); //System.out.println("itext image w: " + itextImage.getWidth() + " h:" + itextImage.getHeight()); if (onePage) { int scale = 66; itextImage.scalePercent(scale); document.add(itextImage); } else { BufferedImage[] imageChunks = ImageUtils.splitImageByHeigth(bimage, printHeigth); for (int i = 0; i < imageChunks.length; i++) { com.lowagie.text.Image itextImage2 = com.lowagie.text.Image.getInstance( Toolkit.getDefaultToolkit().createImage(imageChunks[i].getSource()), null); // width becomes typically 523 (595 - 72) for a4Hoch or 770 (842 - 72) for A4Quer float imgWidth = document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(); float imgHeigth = itextImage.getHeight() * 0.75f; itextImage2.setAbsolutePosition(30, 20); int scale = 66; itextImage2.scalePercent(scale); document.add(itextImage2); document.newPage(); } } // we're done! document.close(); /////////////////////////////// } catch (Exception ex) { log.error(ex.getMessage()); showMessage("Error while generating PDF", ex.getMessage()); } } finally { if (image != null) { image.dispose(); } if (gc != null) { gc.dispose(); } /* image.dispose(); gc.dispose(); */ } } }; actionPdf.setText(Messages.Cst_Text_Save_as_pdf); actionPdf.setToolTipText(Messages.Cst_Text_Save_as_pdf); /* * actionPdf.setImageDescriptor(PlatformUI.getWorkbench() .getSharedImages() * .getImageDescriptor(ISharedImages.IMG_OBJ_FILE)); */ actionPdf.setImageDescriptor(Activator.getImageDescriptor(Activator.IMG_PDF_PATH)); }
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 ww w.ja va 2s.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 www . j a v a 2 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.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
License:Open Source License
public static boolean exportToFile(WikiPDFContext context, Connection db) throws Exception { LOG.debug("exportToFile-> begin"); // Context Objects Wiki wiki = context.getWiki();//from w w w . ja va2 s .c o m Project project = context.getProject(); File file = context.getFile(); WikiExportBean exportBean = context.getExportBean(); // Determine the content to parse String content = wiki.getContent(); if (content == null) { return false; } // Create a pdf Document document = new Document(PageSize.LETTER); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); // Meta data document.addTitle(project.getTitle()); document.addSubject(wiki.getSubject()); document.addCreator("Concursive ConcourseConnect"); document.addAuthor("Wiki Contributor"); //writer.setPageEvent(new PageNumbersWatermark()); if (!exportBean.getIncludeTitle()) { boolean hasTitle = StringUtils.hasText(wiki.getSubject()); HeaderFooter pageFooter = new HeaderFooter( new Phrase(project.getTitle() + (hasTitle ? ": " + wiki.getSubject() : "") + " - page "), new Phrase("")); pageFooter.setAlignment(Element.ALIGN_CENTER); document.setFooter(pageFooter); } document.open(); if (exportBean.getIncludeTitle()) { //HeaderFooter pageHeader = new HeaderFooter(new Phrase(project.getTitle()), false); //document.setHeader(pageHeader); boolean hasTitle = (StringUtils.hasText(wiki.getSubject())); HeaderFooter pageFooter = new HeaderFooter( new Phrase(project.getTitle() + (hasTitle ? ": " + wiki.getSubject() : "") + " - page "), new Phrase("")); pageFooter.setAlignment(Element.ALIGN_CENTER); document.setFooter(pageFooter); // Draw a title page Rectangle rectangle = new Rectangle(600, 30); rectangle.setBackgroundColor(new Color(100, 100, 100)); LOG.debug("document.add(rectangle)"); document.add(rectangle); document.add(new Paragraph(project.getTitle(), titleFont)); if (!"".equals(wiki.getSubject())) { document.add(new Paragraph(wiki.getSubject(), titleFont)); } document.add(Chunk.NEWLINE); document.add(new Paragraph("Last Modified: " + wiki.getModified(), titleSmallFont)); document.newPage(); } ArrayList<Integer> wikiListDone = new ArrayList<Integer>(); appendWiki(context, context.getWiki(), document, db, wikiListDone); // Close everything document.close(); writer.close(); LOG.debug("exportToFile-> finished"); return true; }
From source file:com.googlecode.openmpis.action.CaseAction.java
License:Open Source License
/** * Writes the cases to a PDF file./*ww w . j ava 2s . c o m*/ * * @param mapping the ActionMapping used to select this instance * @param form the optional ActionForm bean for this request * @param request the HTTP Request we are processing * @param response the HTTP Response we are processing * @return the forwarding instance * @throws java.lang.Exception */ public ActionForward printCases(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { User currentUser = null; // Check if there exists a session if (request.getSession().getAttribute("currentuser") != null) { currentUser = (User) request.getSession().getAttribute("currentuser"); } // Set the paper size and margins Document document = new Document(PageSize.LETTER.rotate(), 50, 50, 50, 50); // Create the PDF writer ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // Add some meta information to the document document.addTitle("Case Statistics"); document.addAuthor("OpenMPIS"); document.addSubject("Statistics for All Cases"); document.addKeywords("OpenMPIS, missing, found, unidentified"); document.addProducer(); document.addCreationDate(); document.addCreator("OpenMPIS version " + Constants.VERSION); // Set the header String date = simpleDateFormat.format(System.currentTimeMillis()); document.setHeader(new HeaderFooter(new Phrase("Statistics for cases as of " + date), false)); // Set the footer HeaderFooter footer = new HeaderFooter(new Phrase("Page : "), true); footer.setAlignment(Element.ALIGN_CENTER); document.setFooter(footer); // Open the document for writing document.open(); Table table = new Table(2); table.setBorderWidth(1); table.setBorderColor(new Color(0, 0, 0)); table.setPadding(2); table.setSpacing(0); Paragraph paragraph = new Paragraph("Cases", FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLD, new Color(0, 0, 0))); paragraph.setAlignment(Paragraph.ALIGN_CENTER); Cell cell = new Cell(paragraph); cell.setHeader(true); cell.setColspan(2); table.addCell(cell); table.endHeaders(); table.addCell("Total On-going Cases"); table.addCell("" + personService.countOngoing()); table.addCell("\t\t\t\t\tMissing Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countMissing()); table.addCell("\t\t\t\t\tFamily Abductions"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countFamilyAbduction()); table.addCell("\t\t\t\t\tNon-Family Abductions"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countNonFamilyAbduction()); table.addCell("\t\t\t\t\tRunaway Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countRunaway()); table.addCell("\t\t\t\t\tUnknown"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countUnknown()); table.addCell("\t\t\t\t\tFound Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countFound()); table.addCell("\t\t\t\t\tAbandoned Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countAbandoned()); table.addCell("\t\t\t\t\tThrowaway Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countThrowaway()); table.addCell("\t\t\t\t\tUnidentified"); table.addCell( "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countUnidentified()); table.addCell("Total Solved Cases"); table.addCell("" + personService.countSolved()); table.addCell("\t\t\t\t\tMissing Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedMissing()); table.addCell("\t\t\t\t\tFamily Abductions"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedFamilyAbduction()); table.addCell("\t\t\t\t\tNon-Family Abductions"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedNonFamilyAbduction()); table.addCell("\t\t\t\t\tRunaway Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedRunaway()); table.addCell("\t\t\t\t\tUnknown"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedUnknown()); table.addCell("\t\t\t\t\tFound Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedFound()); table.addCell("\t\t\t\t\tAbandoned Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedAbandoned()); table.addCell("\t\t\t\t\tThrowaway Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedThrowaway()); table.addCell("\t\t\t\t\tUnidentified"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countSolvedUnidentified()); table.addCell("Total Unsolved Cases"); table.addCell("" + personService.countUnsolved()); table.addCell("\t\t\t\t\tMissing Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedMissing()); table.addCell("\t\t\t\t\tFamily Abductions"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedFamilyAbduction()); table.addCell("\t\t\t\t\tNon-Family Abductions"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedNonFamilyAbduction()); table.addCell("\t\t\t\t\tRunaway Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedRunaway()); table.addCell("\t\t\t\t\tUnknown"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedUnknown()); table.addCell("\t\t\t\t\tFound Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedFound()); table.addCell("\t\t\t\t\tAbandoned Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedAbandoned()); table.addCell("\t\t\t\t\tThrowaway Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedThrowaway()); table.addCell("\t\t\t\t\tUnidentified"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countUnsolvedUnidentified()); table.addCell("Total Cases"); table.addCell("" + personService.countAllPersons()); table.addCell("\t\t\t\t\tTotal Missing Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + personService.countAllMissing()); table.addCell("\t\t\t\t\tTotal Found Persons"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countAllFound()); table.addCell("\t\t\t\t\tTotal Unidentified Persons"); table.addCell( "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + personService.countUnidentified()); table.addCell("Total Relatives"); table.addCell("" + relativeService.countAllRelatives()); table.addCell("Total Abductors"); table.addCell("" + abductorService.countAllAbductors()); document.add(table); if (currentUser != null) { // List ongoing cases document.setHeader(new HeaderFooter(new Phrase("List of ongoing cases as of " + date), false)); document.newPage(); float[] widths = { 0.05f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.05f, 0.15f, 0.1f, 0.1f, 0.05f }; PdfPTable pdfptable = new PdfPTable(widths); pdfptable.setWidthPercentage(100); pdfptable.addCell(new Phrase("ID", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Last Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("First Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Nickname", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Middle Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Case Type", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Status", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Photo", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Relative", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Abductor", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Investigator", FontFactory.getFont(FontFactory.HELVETICA, 12))); List<Person> personList = personService.listOngoing(); if (personList != null) { for (Person person : personList) { // Process the photo String tokens[] = person.getPhoto().split("\\/"); String defaultPhotoBasename = ""; for (int i = 0; i < tokens.length - 1; i++) { defaultPhotoBasename += tokens[i] + File.separator; } defaultPhotoBasename += tokens[tokens.length - 1]; String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/") + defaultPhotoBasename; Image image = Image.getInstance(absoluteDefaultPhotoFilename); image.scaleAbsolute(50, 75); image.setAlignment(Image.ALIGN_CENTER); pdfptable.addCell( new Phrase("" + person.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(person.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(person.getNickname(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(person.getMiddleName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell(new Phrase(getResources(request).getMessage("type." + person.getType()), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(getResources(request).getMessage("status.case." + person.getStatus()), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell(image); String relativeName = ""; if (person.getRelativeId() != null) { Relative relative = relativeService.getRelativeById(person.getRelativeId()); relativeName = relative.getFirstName() + " " + relative.getLastName(); } pdfptable.addCell(new Phrase(relativeName, FontFactory.getFont(FontFactory.HELVETICA, 8))); String abductorName = ""; if (person.getAbductorId() != null) { Abductor abductor = abductorService.getAbductorById(person.getAbductorId()); abductorName = abductor.getFirstName() + " " + abductor.getLastName(); } pdfptable.addCell(new Phrase(abductorName, FontFactory.getFont(FontFactory.HELVETICA, 8))); String investigatorUsername = ""; if (person.getInvestigatorId() != null) { User investigator = userService.getUserById(person.getInvestigatorId()); investigatorUsername = investigator.getUsername(); } pdfptable.addCell( new Phrase(investigatorUsername, FontFactory.getFont(FontFactory.HELVETICA, 8))); } } document.add(pdfptable); // List solved cases document.setHeader(new HeaderFooter(new Phrase("List of solved cases as of " + date), false)); document.newPage(); pdfptable = new PdfPTable(widths); pdfptable.setWidthPercentage(100); pdfptable.addCell(new Phrase("ID", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Last Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("First Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Nickname", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Middle Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Case Type", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Status", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Photo", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Relative", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Abductor", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Investigator", FontFactory.getFont(FontFactory.HELVETICA, 12))); personList = personService.listSolved(); if (personList != null) { for (Person person : personList) { // Process the photo String tokens[] = person.getPhoto().split("\\/"); String defaultPhotoBasename = ""; for (int i = 0; i < tokens.length - 1; i++) { defaultPhotoBasename += tokens[i] + File.separator; } defaultPhotoBasename += tokens[tokens.length - 1]; String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/") + defaultPhotoBasename; Image image = Image.getInstance(absoluteDefaultPhotoFilename); image.scaleAbsolute(50, 75); image.setAlignment(Image.ALIGN_CENTER); pdfptable.addCell( new Phrase("" + person.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(person.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(person.getNickname(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(person.getMiddleName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell(new Phrase(getResources(request).getMessage("type." + person.getType()), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(getResources(request).getMessage("status.case." + person.getStatus()), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell(image); String relativeName = ""; if (person.getRelativeId() != null) { Relative relative = relativeService.getRelativeById(person.getRelativeId()); relativeName = relative.getFirstName() + " " + relative.getLastName(); } pdfptable.addCell(new Phrase(relativeName, FontFactory.getFont(FontFactory.HELVETICA, 8))); String abductorName = ""; if (person.getAbductorId() != null) { Abductor abductor = abductorService.getAbductorById(person.getAbductorId()); abductorName = abductor.getFirstName() + " " + abductor.getLastName(); } pdfptable.addCell(new Phrase(abductorName, FontFactory.getFont(FontFactory.HELVETICA, 8))); String investigatorUsername = ""; if (person.getInvestigatorId() != null) { User investigator = userService.getUserById(person.getInvestigatorId()); investigatorUsername = investigator.getUsername(); } pdfptable.addCell( new Phrase(investigatorUsername, FontFactory.getFont(FontFactory.HELVETICA, 8))); } } document.add(pdfptable); // List unsolved cases document.setHeader(new HeaderFooter(new Phrase("List of unsolved cases as of " + date), false)); document.newPage(); pdfptable = new PdfPTable(widths); pdfptable.setWidthPercentage(100); pdfptable.addCell(new Phrase("ID", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Last Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("First Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Nickname", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Middle Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Case Type", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Status", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Photo", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Relative", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Abductor", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Investigator", FontFactory.getFont(FontFactory.HELVETICA, 12))); personList = personService.listUnsolved(); if (personList != null) { for (Person person : personList) { // Process the photo String tokens[] = person.getPhoto().split("\\/"); String defaultPhotoBasename = ""; for (int i = 0; i < tokens.length - 1; i++) { defaultPhotoBasename += tokens[i] + File.separator; } defaultPhotoBasename += tokens[tokens.length - 1]; String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/") + defaultPhotoBasename; Image image = Image.getInstance(absoluteDefaultPhotoFilename); image.scaleAbsolute(50, 75); image.setAlignment(Image.ALIGN_CENTER); pdfptable.addCell( new Phrase("" + person.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(person.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(person.getNickname(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(person.getMiddleName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell(new Phrase(getResources(request).getMessage("type." + person.getType()), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(getResources(request).getMessage("status.case." + person.getStatus()), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell(image); String relativeName = ""; if (person.getRelativeId() != null) { Relative relative = relativeService.getRelativeById(person.getRelativeId()); relativeName = relative.getFirstName() + " " + relative.getLastName(); } pdfptable.addCell(new Phrase(relativeName, FontFactory.getFont(FontFactory.HELVETICA, 8))); String abductorName = ""; if (person.getAbductorId() != null) { Abductor abductor = abductorService.getAbductorById(person.getAbductorId()); abductorName = abductor.getFirstName() + " " + abductor.getLastName(); } pdfptable.addCell(new Phrase(abductorName, FontFactory.getFont(FontFactory.HELVETICA, 8))); String investigatorUsername = ""; if (person.getInvestigatorId() != null) { User investigator = userService.getUserById(person.getInvestigatorId()); investigatorUsername = investigator.getUsername(); } pdfptable.addCell( new Phrase(investigatorUsername, FontFactory.getFont(FontFactory.HELVETICA, 8))); } } document.add(pdfptable); } document.close(); // Set the response to return the poster (PDF file) response.setContentType("application/pdf"); response.setContentLength(baos.size()); response.setHeader("Content-disposition", "attachment; filename=Case_Statistics.pdf"); // Close the output stream baos.writeTo(response.getOutputStream()); response.getOutputStream().flush(); return null; }
From source file:com.googlecode.openmpis.action.ReportAction.java
License:Open Source License
/** * Prints the reports.//w w w. ja va 2s. c o m * This is the print report action called from the Struts framework. * * @param mapping the ActionMapping used to select this instance * @param form the optional ActionForm bean for this request * @param request the HTTP Request we are processing * @param response the HTTP Response we are processing * @return the forwarding instance * @throws java.lang.Exception */ public ActionForward printReport(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { User currentUser = null; // Check if there exists a session if (request.getSession().getAttribute("currentuser") == null) { return mapping.findForward(Constants.EXPIRED); } else { currentUser = (User) request.getSession().getAttribute("currentuser"); } // Check if current user is authorized if ((currentUser.getGroupId() == 1) || (currentUser.getGroupId() == 2)) { // Retrieve person ID try { int personId = Integer.parseInt(request.getParameter("personid")); Person person = personService.getPersonById(personId); // Process the photo String tokens[] = person.getPhoto().split("\\/"); String defaultPhotoBasename = ""; for (int i = 0; i < tokens.length - 1; i++) { defaultPhotoBasename += tokens[i] + File.separator; } defaultPhotoBasename += tokens[tokens.length - 1]; String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/") + defaultPhotoBasename; // Set the paper size and margins Document document = new Document(PageSize.LETTER, 50, 50, 50, 50); // Create the PDF writer ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // Add some meta information to the document document.addTitle("Progress Report"); document.addAuthor("OpenMPIS"); document.addSubject("Progress Report"); document.addKeywords("OpenMPIS, missing, found, unidentified"); document.addProducer(); document.addCreationDate(); document.addCreator("OpenMPIS version " + Constants.VERSION); // Set the header String date = simpleDateFormat.format(System.currentTimeMillis()); document.setHeader(new HeaderFooter(new Phrase("Report for " + person.getFirstName() + " \"" + person.getNickname() + "\" " + person.getLastName() + " as of " + date), false)); // Set the footer HeaderFooter footer = new HeaderFooter(new Phrase("Page : "), true); footer.setAlignment(Element.ALIGN_CENTER); document.setFooter(footer); // Open the document for writing document.open(); // Print the information on person // Add the banner if (person.getType() > 4) { Paragraph foundParagraph = new Paragraph("F O U N D", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0))); foundParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(foundParagraph); } else { Paragraph missingParagraph = new Paragraph("M I S S I N G", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0))); missingParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(missingParagraph); } // Add date missing or found Paragraph blackParagraph = new Paragraph( getResources(request).getMessage("month." + person.getMonthMissingOrFound()) + " " + person.getDayMissingOrFound() + ", " + person.getYearMissingOrFound(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add missing from location if (person.getType() < 5) { blackParagraph = new Paragraph( person.getMissingFromCity() + ", " + person.getMissingFromProvince(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); } // Add name Paragraph redParagraph; if (!person.getNickname().isEmpty()) { redParagraph = new Paragraph( person.getFirstName() + " \"" + person.getNickname() + "\" " + person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); } else { redParagraph = new Paragraph(person.getFirstName() + " " + person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); } redParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(redParagraph); // Add the photo Image image = Image.getInstance(absoluteDefaultPhotoFilename); image.scaleAbsolute(200, 300); image.setAlignment(Image.ALIGN_CENTER); document.add(image); // Add description redParagraph = new Paragraph("Description", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); redParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(redParagraph); float[] widths = { 0.5f, 0.5f }; PdfPTable pdfptable = new PdfPTable(widths); pdfptable.setWidthPercentage(100); if (person.getType() < 5) { pdfptable .addCell( new Phrase( getResources(request).getMessage("label.date.birth") + ": " + getResources(request) .getMessage("month." + person.getBirthMonth()) + " " + person.getBirthDay() + ", " + person.getBirthYear(), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase( getResources(request).getMessage("label.address.city") + ": " + person.getCity(), FontFactory.getFont(FontFactory.HELVETICA, 12))); } pdfptable.addCell(new Phrase( getResources(request).getMessage("label.sex") + ": " + getResources(request).getMessage("sex." + person.getSex()), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable .addCell( new Phrase( getResources(request).getMessage("label.color.hair") + ": " + getResources(request) .getMessage("color.hair." + person.getHairColor()), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable .addCell(new Phrase( getResources(request).getMessage("label.height") + ": " + person.getFeet() + "' " + person.getInches() + "\"", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable .addCell( new Phrase( getResources(request).getMessage("label.color.eye") + ": " + getResources(request) .getMessage("color.eye." + person.getEyeColor()), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase( getResources(request).getMessage("label.weight") + ": " + person.getWeight() + " " + getResources(request).getMessage("label.weight.lbs"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase( getResources(request).getMessage("label.race") + ": " + getResources(request).getMessage("race." + person.getRace()), FontFactory.getFont(FontFactory.HELVETICA, 12))); document.add(pdfptable); // Print information on relative Relative relative = relativeService.getRelativeById(person.getRelativeId()); document.newPage(); document.add(new Paragraph(getResources(request).getMessage("label.relative.name") + ": " + relative.getFirstName() + " " + relative.getLastName())); document.add(new Paragraph(getResources(request).getMessage("label.relation") + ": " + getResources(request).getMessage("relation." + person.getRelationToRelative()))); document.add(new Paragraph(getResources(request).getMessage("label.address") + ": " + relative.getStreet() + ", " + relative.getCity() + ", " + relative.getProvince())); document.add(new Paragraph( getResources(request).getMessage("label.number") + ": " + relative.getNumber())); document.add(new Paragraph( getResources(request).getMessage("label.email") + ": " + relative.getEmail())); // Print information on abductor if (person.getAbductorId() != null) { Abductor abductor = abductorService.getAbductorById(person.getAbductorId()); document.newPage(); document.add(new Paragraph(getResources(request).getMessage("label.abductor.name") + ": " + abductor.getFirstName() + " " + abductor.getLastName())); } // Print sightings if ((currentUser.getGroupId() == 1) || (currentUser.getGroupId() == 2)) { document.setHeader(new HeaderFooter(new Phrase("List of sightings as of " + date), false)); document.newPage(); float sightingsWidths[] = { 0.1f, 0.1f, 0.1f, 0.3f, 0.1f, 0.1f, 0.1f, 0.1f }; pdfptable = new PdfPTable(sightingsWidths); pdfptable.setWidthPercentage(100); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.id"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.date.sent"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.subject"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.message"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.lastname"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.firstname"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.email"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.ipaddress"), FontFactory.getFont(FontFactory.HELVETICA, 12))); List<Message> sightingList = messageService.listAllSightingsForPerson(personId); for (Message sighting : sightingList) { pdfptable.addCell( new Phrase("" + sighting.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getDate(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getSubject(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getMessage(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getEmail(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(sighting.getIpAddress(), FontFactory.getFont(FontFactory.HELVETICA, 8))); } document.add(pdfptable); } // Print progress reports if ((currentUser.getGroupId() == 1) || (currentUser.getGroupId() == 2)) { document.setHeader( new HeaderFooter(new Phrase("List of progress reports as of " + date), false)); document.newPage(); float reportsWidths[] = { 0.1f, 0.1f, 0.3f }; pdfptable = new PdfPTable(reportsWidths); pdfptable.setWidthPercentage(100); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.id"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.date.reported"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.report"), FontFactory.getFont(FontFactory.HELVETICA, 12))); List<Report> reportList = reportService.listAllReportsForPerson(personId); for (Report report : reportList) { pdfptable.addCell( new Phrase("" + report.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(report.getDate(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(report.getReport(), FontFactory.getFont(FontFactory.HELVETICA, 8))); } document.add(pdfptable); } document.close(); // Set the response to return the poster (PDF file) response.setContentType("application/pdf"); response.setContentLength(baos.size()); response.setHeader("Content-disposition", "attachment; filename=Report.pdf"); // Close the output stream baos.writeTo(response.getOutputStream()); response.getOutputStream().flush(); return null; } catch (NumberFormatException nfe) { return mapping.findForward(Constants.LIST_PERSON); } catch (NullPointerException npe) { return mapping.findForward(Constants.LIST_PERSON); } } else { return mapping.findForward(Constants.UNAUTHORIZED); } }
From source file:com.googlecode.openmpis.action.UserAction.java
License:Open Source License
/** * Writes the users to a PDF file./*from w w w . j a va2s . c o m*/ * * @param mapping the ActionMapping used to select this instance * @param form the optional ActionForm bean for this request * @param request the HTTP Request we are processing * @param response the HTTP Response we are processing * @return the forwarding instance * @throws java.lang.Exception */ public ActionForward printUsers(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { User currentUser = null; // Check if there exists a session if (request.getSession().getAttribute("currentuser") != null) { currentUser = (User) request.getSession().getAttribute("currentuser"); } // Set the paper size and margins Document document = new Document(PageSize.LETTER.rotate(), 50, 50, 50, 50); // Create the PDF writer ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // Add some meta information to the document document.addTitle("Case Statistics"); document.addAuthor("OpenMPIS"); document.addSubject("Statistics for All Cases"); document.addKeywords("OpenMPIS, missing, found, unidentified"); document.addProducer(); document.addCreationDate(); document.addCreator("OpenMPIS version " + Constants.VERSION); // Set the header String date = simpleDateFormat.format(System.currentTimeMillis()); document.setHeader(new HeaderFooter(new Phrase("List of users as of " + date), false)); // Set the footer HeaderFooter footer = new HeaderFooter(new Phrase("Page : "), true); footer.setAlignment(Element.ALIGN_CENTER); document.setFooter(footer); // Open the document for writing document.open(); Table table = new Table(2); table.setBorderWidth(1); table.setPadding(2); table.setSpacing(0); Paragraph paragraph = new Paragraph("Users", FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLD)); paragraph.setAlignment(Paragraph.ALIGN_CENTER); Cell cell = new Cell(paragraph); cell.setHeader(true); cell.setColspan(2); table.addCell(cell); table.endHeaders(); table.addCell("Total Administrators"); table.addCell("" + userService.countAdministrators()); table.addCell("\t\t\t\t\tActive Administrators"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + userService.countActiveAdministrators()); table.addCell("\t\t\t\t\tSuspended Administrators"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + userService.countSuspendedAdministrators()); table.addCell("Total Encoders"); table.addCell("" + userService.countEncoders()); table.addCell("\t\t\t\t\tActive Encoders"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + userService.countActiveEncoders()); table.addCell("\t\t\t\t\tSuspended Encoders"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + userService.countSuspendedEncoders()); table.addCell("Total Investigators"); table.addCell("" + userService.countInvestigators()); table.addCell("\t\t\t\t\tActive Investigators"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + userService.countActiveInvestigators()); table.addCell("\t\t\t\t\tSuspended Investigators"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + userService.countSuspendedInvestigators()); table.addCell("Total Users"); table.addCell("" + userService.countAllUsers()); table.addCell("\t\t\t\t\tTotal Active Users"); table.addCell("\t\t\t\t\t\t\t\t\t\t" + userService.countActiveUsers()); table.addCell("\t\t\t\t\tTotal Suspended Users"); table.addCell("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + userService.countSuspendedUsers()); document.add(table); if (currentUser != null) { if ((currentUser.getGroupId() == 0) || (currentUser.getGroupId() == 1)) { // List administrators document.setHeader(new HeaderFooter(new Phrase("List of administrators as of " + date), false)); document.newPage(); float[] widths = { 0.03f, 0.07f, 0.1f, 0.1f, 0.1f, 0.1f, 0.2f, 0.05f }; PdfPTable pdfptable = new PdfPTable(widths); pdfptable.setWidthPercentage(100); pdfptable.addCell(new Phrase("ID", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Group", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Last Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("First Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Agency", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Designation", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("E-mail Address", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Status", FontFactory.getFont(FontFactory.HELVETICA, 12))); List<User> administratorList = userService.listAdministrators(); for (User administrator : administratorList) { pdfptable.addCell( new Phrase("" + administrator.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(getResources(request).getMessage("group." + administrator.getGroupId()), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(administrator.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell(new Phrase(administrator.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(administrator.getAgency(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell(new Phrase(administrator.getDesignation(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(administrator.getEmail(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(getResources(request).getMessage("status.user." + administrator.getStatus()), FontFactory.getFont(FontFactory.HELVETICA, 8))); } document.add(pdfptable); // List encoders document.setHeader(new HeaderFooter(new Phrase("List of encoders as of " + date), false)); document.newPage(); pdfptable = new PdfPTable(widths); pdfptable.setWidthPercentage(100); pdfptable.addCell(new Phrase("ID", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Group", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Last Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("First Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Agency", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Designation", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("E-mail Address", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Status", FontFactory.getFont(FontFactory.HELVETICA, 12))); List<User> encoderList = userService.listEncoders(); for (User encoder : encoderList) { pdfptable.addCell( new Phrase("" + encoder.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell(new Phrase(getResources(request).getMessage("group." + encoder.getGroupId()), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(encoder.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(encoder.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(encoder.getAgency(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(encoder.getDesignation(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable .addCell(new Phrase(encoder.getEmail(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(getResources(request).getMessage("status.user." + encoder.getStatus()), FontFactory.getFont(FontFactory.HELVETICA, 8))); } document.add(pdfptable); // List investigators document.setHeader(new HeaderFooter(new Phrase("List of investigators as of " + date), false)); document.newPage(); pdfptable = new PdfPTable(widths); pdfptable.setWidthPercentage(100); pdfptable.addCell(new Phrase("ID", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Group", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Last Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("First Name", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Agency", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Designation", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("E-mail Address", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase("Status", FontFactory.getFont(FontFactory.HELVETICA, 12))); List<User> investigatorList = userService.listInvestigators(); for (User investigator : investigatorList) { pdfptable.addCell( new Phrase("" + investigator.getId(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(getResources(request).getMessage("group." + investigator.getGroupId()), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(investigator.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(investigator.getFirstName(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(investigator.getAgency(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell(new Phrase(investigator.getDesignation(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(investigator.getEmail(), FontFactory.getFont(FontFactory.HELVETICA, 8))); pdfptable.addCell( new Phrase(getResources(request).getMessage("status.user." + investigator.getStatus()), FontFactory.getFont(FontFactory.HELVETICA, 8))); } document.add(pdfptable); } } document.close(); // Set the response to return the poster (PDF file) response.setContentType("application/pdf"); response.setContentLength(baos.size()); response.setHeader("Content-disposition", "attachment; filename=User_Statistics.pdf"); // Close the output stream baos.writeTo(response.getOutputStream()); response.getOutputStream().flush(); return null; }
From source file:com.kahlon.guard.controller.DocumentManager.java
/** * * @param document//from www . ja v a2s . c o m */ public void preProcessPDF(Object document) { try { BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", false); Document pdf = (Document) document; pdf.setPageSize(PageSize.A4); pdf.setMargins(5f, 5f, 10f, 5f); // headers and footers must be added before the document is opened HeaderFooter footer = new HeaderFooter(new Phrase("page: ", new Font(bf_courier)), true); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); pdf.setFooter(footer); // HeaderFooter header = new HeaderFooter( // new Phrase("This is a header without a page number", new Font(bf_courier)), false); // header.setAlignment(Element.ALIGN_CENTER); // pdf.setHeader(header); pdf.open(); String logoPath = "/resources/image/logo.png"; ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String logo = servletContext.getRealPath(logoPath); pdf.add(Image.getInstance(logo)); Person person = context.getSelectedPerson().getDisplayPerson(); String name = FacesMessageUtil.getMessage("person.name") + " : " + person.getName(); String age = FacesMessageUtil.getMessage("person.age") + " : " + Integer.toString(person.getAge()); String gender = FacesMessageUtil.getMessage("person.gender") + " : " + person.getGender().getDescription(); String race = FacesMessageUtil.getMessage("person.ethnicity") + " : " + person.getEthnicity().getDescription(); Person rootPerson = person.getRootPerson(); PersonImage imgp = imageService.getLastestPersonImage(rootPerson.getId()); Image imgb = Image.getInstance(imgp.getContent()); imgb.scaleToFit(100, 120); PdfPTable headerTable = new PdfPTable(2); PdfPTable personTable = new PdfPTable(1); personTable.setWidthPercentage(100); PdfPCell cell; cell = new PdfPCell(new Phrase(name)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(age)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(gender)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(race)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); BarcodePDF417 pdf417 = new BarcodePDF417(); pdf417.setText(Integer.toString(person.getId())); Image img = pdf417.getImage(); img.scalePercent(150, 60 * pdf417.getYHeight()); cell = new PdfPCell(img); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(15); personTable.addCell(cell); cell.addElement(personTable); headerTable.addCell(cell); cell = new PdfPCell(imgb); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); headerTable.addCell(cell); headerTable.setSpacingAfter(15); pdf.add(headerTable); LineSeparator lineSeparator = new LineSeparator(); lineSeparator.setPercentage(82); pdf.add(lineSeparator); Paragraph space = new Paragraph(); space.add(""); space.setSpacingAfter(15); pdf.add(space); } catch (IOException e) { logger.log(Level.INFO, e.getMessage()); } catch (BadElementException e) { logger.log(Level.INFO, e.getMessage()); } catch (DocumentException e) { logger.log(Level.INFO, e.getMessage()); } catch (Exception e) { logger.log(Level.INFO, e.getMessage()); } }