List of usage examples for com.itextpdf.text Document getJavaScript_onLoad
public String getJavaScript_onLoad()
From source file:org.openmrs.module.drugorderexport.DrugOrderExportUtil.java
License:Open Source License
/** * allows to export patient list to pdf * //from ww w . j a v a 2s. co m * @param patients * @param request * @param response * @param filename * @param title * @throws DocumentException * @throws FileNotFoundException */ public static void exportToPDF(HttpServletRequest request, HttpServletResponse response, List<Patient> patients) throws Exception, Exception { DrugOrderService service = (DrugOrderService) Context.getService(DrugOrderService.class); // // service.exportToPDF(request, response, patients, "patientDrugOrder.csv"); Document document = new Document(); response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"patientDrugOrder.pdf\""); PdfWriter.getInstance(document, response.getOutputStream()); document.open(); float[] colsWidth = { 3f, 7f, 8f, 8f, 4f, 4f, 16f }; float[] colsWidth1 = { 3f, 5f, 6f, 6f, 16f }; PdfPTable table = null; if (Context.hasPrivilege("View Patient Names")) { table = new PdfPTable(colsWidth); } else { table = new PdfPTable(colsWidth1); } document.add(new Paragraph(" ")); document.add( new Paragraph(" List of Patients And Their Regimens")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); table.addCell("#"); table.addCell("Patient Id"); if (Context.hasPrivilege("View Patient Names")) { table.addCell("FAMILY NAME"); table.addCell("GIVEN NAME"); } table.addCell("AGE"); table.addCell("SEX"); table.addCell("REGIMENS"); log.info("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiipatients " + patients.size()); for (int i = 0; i < patients.size(); i++) { table.addCell(i + 1 + ""); if (patients.get(i).getPatientIdentifier() != null) { table.addCell(patients.get(i).getPatientIdentifier() + ""); } else if (patients.get(i).getPatientIdentifier() == null) { table.addCell("-"); } if (Context.hasPrivilege("View Patient Names")) { table.addCell(patients.get(i).getFamilyName() + ""); table.addCell(patients.get(i).getGivenName() + ""); } table.addCell(patients.get(i).getAge() + ""); table.addCell(patients.get(i).getGender() + ""); RegimenHistory history = RegimenUtils.getRegimenHistory(patients.get(i)); List<Regimen> regimens = history.getRegimenList(); Set<RegimenComponent> regimenComponents = new HashSet<RegimenComponent>(); String patRegimens = ""; //Set<RegimenComponent> componentsStopped = new HashSet<RegimenComponent>(); for (Regimen r : regimens) { regimenComponents = r.getComponents(); patRegimens = service.getRegimensAsString(regimenComponents); } table.addCell(patRegimens); } document.add(table); document.getJavaScript_onLoad(); document.close(); }
From source file:org.openmrs.module.laboratorymanagement.db.hibernate.LaboratoryDAOimpl.java
License:Open Source License
public void exportToPDF(HttpServletRequest request, HttpServletResponse response, List<Object[]> listOflabtest, String filename, String title, int conceptId) throws DocumentException, IOException { // TODO Auto-generated method stub Concept cpt = Context.getConceptService().getConcept(conceptId); System.out.println(">>>>>>list to export" + listOflabtest); DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); response.setContentType("application/pdf"); Document document = new Document(); try {//from w w w . j a v a 2 s .c o m response.setHeader("Content-Disposition", "attachment; filename=\"laboratory.pdf\""); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); document.open(); writer.setBoxSize("art", PageSize.A4); float[] colsWidth = { 5f, 20f, 17f, 17f, 17f, 16f, 20f }; PdfPTable table = new PdfPTable(colsWidth); // add a title PdfPCell cell = new PdfPCell(new Paragraph("CD4 lab tests")); cell.setColspan(2); document.add(new Paragraph(" Laboratory tests:" + cpt.getName())); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); table.addCell("#"); table.addCell("GIVEN NAME"); table.addCell("FAMILY NAME"); table.addCell("TEST NAME"); table.addCell("TESTED ON"); table.addCell("LOCATION"); table.addCell("TEST RESULT"); for (int i = 0; i < listOflabtest.size(); i++) { Object[] labtest = listOflabtest.get(i); Person p = (Person) labtest[0]; Obs ob = (Obs) labtest[1]; table.addCell(i + 1 + ""); table.addCell(p.getGivenName() + ""); table.addCell(p.getFamilyName() + ""); table.addCell(ob.getConcept().getName() + ""); table.addCell(df.format(ob.getObsDatetime()) + ""); table.addCell(ob.getLocation() + ""); if (cpt.getDatatype().isNumeric()) { table.addCell(ob.getValueNumeric() + ""); } if (cpt.getDatatype().isCoded()) { table.addCell(ob.getValueCoded().getName() + ""); } if (cpt.getDatatype().isText()) { table.addCell(ob.getValueText() + ""); } if (cpt.getDatatype().isDate()) { table.addCell(df.format((ob.getValueDatetime())) + ""); } } document.add(table); document.getJavaScript_onLoad(); document.close(); // document.add(new Paragraph("Hello world")); // document.close(); } catch (DocumentException e) { } }