List of usage examples for com.itextpdf.text BaseColor BaseColor
public BaseColor(final float red, final float green, final float blue)
From source file:org.apache.jmeter.visualizers.CreateReport.java
License:Apache License
public void createPdf(String filename, Document document2) throws IOException, DocumentException { // step 1/*from w ww.j a v a 2 s.com*/ Document document = new Document(); // step 2 // OutputStream outputStream = new OutputStream(new FileOutputStream(filename)); PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 document.open(); // step 4 Font titleFont = new Font(Font.FontFamily.HELVETICA, 30, Font.BOLD, clr);//BaseColor.Color.getHSBColor(258, 100, 13)); Paragraph emptyLine = new Paragraph(); addEmptyLine(emptyLine, 2); Paragraph title = new Paragraph("Test Report", titleFont); title.setAlignment(Element.ALIGN_CENTER); BaseColor BC = new BaseColor(164, 188, 196); document.add(title); document.add(emptyLine); emptyLine = new Paragraph(" "); Date dNow = new Date(); SimpleDateFormat ft = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz"); // addEmptyLine(emptyLine, 0); document.add(new Paragraph("Report created on : " + ft.format(dNow), small)); document.add(emptyLine); document.add(emptyLine); document.add(emptyLine); document.add(new Paragraph("Test Summary Report", subFont)); // document.add(emptyLine); PdfPTable table = createTable1(); PdfPTable table2 = createTable2(); document.add(new Paragraph(" ")); document.add(emptyLine); document.add(table); document.add(emptyLine); document.add(emptyLine); document.add(emptyLine); document.add(new Paragraph("Test Error Report", subFont)); document.add(emptyLine); document.add(emptyLine); document.add(table2); table.setSpacingBefore(5); table.setSpacingAfter(5); table2.setSpacingBefore(5); table2.setSpacingAfter(5); // step 5 //adding graphs //PdfWriter writer ; // writer = PdfWriter.getInstance(document, outputStream); Image[] img = new Image[5]; img[0] = createGraphs("Average Response Time of samples for each Request", "Average(ms)", 2); // df *add 90%line and no of samples to csv summary model table img[1] = createGraphs("Number of samples processed for each Request", "Number of Samples", 2); img[2] = createGraphs("Error % of samples for each Request", "Error %", 6); img[3] = createGraphs("Throughput of samples for each Request", "Throughput(ms)", 7); img[4] = createGraphs("90 % Line of samples for each Request", "90% line(ms)", 2); // document.add(image1); document.add(img[0]); // document. //release resources document.close(); document = null; }
From source file:org.apache.jmeter.visualizers.CreateReport.java
License:Apache License
/** * Creates a table; widths are set with setWidths(). * @return a PdfPTable/*from w w w . ja va2 s.c o m*/ * @throws DocumentException */ public PdfPTable createTable1() throws DocumentException { PdfPTable table = new PdfPTable(7); table.setWidthPercentage(570 / 5.23f); table.setWidths(new int[] { 4, 4, 3, 3, 3, 3, 5 }); PdfPCell cell = null; for (int k = 0; k < 10; k++) { if (k != 5 && k != 8 && k != 9) { cell = new PdfPCell(new Phrase(JMeterUtils.getResString(COLUMNS[k]), headerFont)); BaseColor BC = new BaseColor(164, 188, 196); cell.setBackgroundColor(BC); cell.setColspan(1); table.addCell(cell); } } for (int l = 0; l < model.getRowCount(); l++) //row count does not include table headers for (int k = 0; k < 10; k++) { if (k != 5 && k != 8 && k != 9) { cell = new PdfPCell(new Phrase(model.getValueAt(l, k).toString(), rowFont)); cell.setGrayFill(2); table.addCell(cell); } } return table; /* original basic statements PdfPTable table = new PdfPTable(3); table.setWidthPercentage(288 / 5.23f); table.setWidths(new int[]{2, 1, 1}); PdfPCell cell; cell = new PdfPCell(new Phrase("Table 1")); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase("Cell with rowspan 2")); cell.setRowspan(2); table.addCell(cell); table.addCell("row 1; cell 1"); table.addCell("row 1; cell 2"); table.addCell("row 2; cell 1"); table.addCell("row 2; cell 2"); return table; */ }
From source file:org.apache.jmeter.visualizers.CreateReport.java
License:Apache License
public PdfPTable createTable2() throws DocumentException { PdfPTable table = new PdfPTable(4); table.setWidthPercentage(570 / 5.23f); table.setWidths(new int[] { 1, 2, 1, 3 }); PdfPCell cell = null;// w w w . j av a2s .c o m for (int k = 0; k < 4; k++) { { cell = new PdfPCell(new Phrase(model2.getColumnName(k), headerFont)); BaseColor BC = new BaseColor(164, 188, 196); cell.setBackgroundColor(BC); cell.setColspan(1); table.addCell(cell); } } for (int l = 0; l < model2.getRowCount(); l++) //row count does not include table headers for (int k = 0; k < 4; k++) { cell = new PdfPCell(new Phrase(model2.getValueAt(l, k).toString(), rowFont)); cell.setGrayFill(2); table.addCell(cell); } return table; }
From source file:org.cidte.sii.negocio.PDFWriter.java
public void writePDF(ArrayList<Writable> list, String directorio, String nombre, java.awt.Image image) throws DocumentException, FileNotFoundException, BadElementException, IOException { Document doc = new Document(); PdfWriter docWriter;// w w w . j av a2s .co m // special font sizes Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12); // file path String path = directorio + nombre + ".pdf"; docWriter = PdfWriter.getInstance(doc, new FileOutputStream(new File(path))); // document header attributes doc.addAuthor("sii"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("sii"); doc.addTitle(nombre); doc.setPageSize(PageSize.LETTER); // open document doc.open(); Image img = Image.getInstance(image, null); img.setAlignment(Element.ALIGN_LEFT); doc.add(img); // create a paragraph Paragraph paragraph = new Paragraph("iText is a library that allows you to create and " + "manipulate PDF documents. It enables developers looking to enhance web and other " + "applications with dynamic PDF document generation and/or manipulation."); // create PDF table with the given widths PdfPTable table = new PdfPTable(list.get(0).getNames().length); // set table width a percentage of the page width table.setWidthPercentage(100); table.setSpacingBefore(10f); // Space before table table.setSpacingAfter(10f); // Space after table // insert column headings String[] headings = list.get(0).getNames(); for (String heading : headings) { insertCell(table, heading, Element.ALIGN_CENTER, 1, bfBold12); } table.setHeaderRows(1); // insert the data for (int i = 0; i < list.size(); i++) { Writable w = list.get(i); Object[] arr = w.getAsArray(); for (int j = 0; j < arr.length; j++) { // arr[j] insertCell(table, arr[j].toString(), Element.ALIGN_LEFT, 1, bf12); } } // insert an empty row // insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12); // add the PDF table to the paragraph paragraph.add(table); // add the paragraph to the document doc.add(paragraph); // close the document doc.close(); // close the writer docWriter.close(); }
From source file:org.gephi.io.exporter.preview.PDFExporter.java
License:Open Source License
public boolean execute() { Progress.start(progress);//from w ww .j a v a 2 s . c o m PreviewController controller = Lookup.getDefault().lookup(PreviewController.class); controller.getModel(workspace).getProperties().putValue(PreviewProperty.VISIBILITY_RATIO, 1.0); controller.refreshPreview(workspace); PreviewProperties props = controller.getModel(workspace).getProperties(); Rectangle size = new Rectangle(pageSize); if (landscape) { size = new Rectangle(pageSize.rotate()); } Color col = props.getColorValue(PreviewProperty.BACKGROUND_COLOR); size.setBackgroundColor(new BaseColor(col.getRed(), col.getGreen(), col.getBlue())); Document document = new Document(size); PdfWriter pdfWriter = null; try { pdfWriter = PdfWriter.getInstance(document, stream); pdfWriter.setPdfVersion(PdfWriter.PDF_VERSION_1_5); pdfWriter.setFullCompression(); } catch (DocumentException ex) { Exceptions.printStackTrace(ex); } document.open(); PdfContentByte cb = pdfWriter.getDirectContent(); cb.saveState(); props.putValue(PDFTarget.LANDSCAPE, landscape); props.putValue(PDFTarget.PAGESIZE, size); props.putValue(PDFTarget.MARGIN_TOP, new Float((float) marginTop)); props.putValue(PDFTarget.MARGIN_LEFT, new Float((float) marginLeft)); props.putValue(PDFTarget.MARGIN_BOTTOM, new Float((float) marginBottom)); props.putValue(PDFTarget.MARGIN_RIGHT, new Float((float) marginRight)); props.putValue(PDFTarget.PDF_CONTENT_BYTE, cb); target = (PDFTarget) controller.getRenderTarget(RenderTarget.PDF_TARGET, workspace); if (target instanceof LongTask) { ((LongTask) target).setProgressTicket(progress); } try { controller.render(target, workspace); } catch (Exception e) { throw new RuntimeException(e); } cb.restoreState(); document.close(); Progress.finish(progress); props.putValue(PDFTarget.PDF_CONTENT_BYTE, null); props.putValue(PDFTarget.PAGESIZE, null); return !cancel; }
From source file:org.h819.commons.file.MyPDFUtils.java
/** * ??/*from w w w.ja v a 2 s . c om*/ * * @param srcPdf ? * @param destPdf * @param waterMarkText ? * @param waterMarkImage ? */ public static void addWaterMarkFile(File srcPdf, File destPdf, String waterMarkText, File waterMarkImage) throws IOException, DocumentException { if (waterMarkText == null && waterMarkImage == null) throw new FileNotFoundException(waterMarkText + " " + waterMarkImage + " all null."); if (srcPdf == null || !srcPdf.exists() || !srcPdf.isFile()) throw new FileNotFoundException("pdf file : '" + srcPdf + "' does not exsit."); if (!FilenameUtils.getExtension(srcPdf.getAbsolutePath()).toLowerCase().equals("pdf")) return; if (waterMarkImage != null) { if (!waterMarkImage.exists() || !waterMarkImage.isFile()) throw new FileNotFoundException("img file : '" + srcPdf + "' does not exsit."); if (!FilenameUtils.getExtension(waterMarkImage.getAbsolutePath()).toLowerCase().equals("png")) throw new FileNotFoundException("image file '" + srcPdf + "' not png.(???? pdf )"); } PdfReader reader = getPdfReader(srcPdf); int n = reader.getNumberOfPages(); PdfStamper stamper = getPdfStamper(srcPdf, destPdf); // // HashMap<String, String> moreInfo = new HashMap<String, String>(); // moreInfo.put("Author", "H819 create"); // moreInfo.put("Producer", "H819 Producer"); // Key = CreationDate, Value = D:20070425182920 // Key = Producer, Value = TH-OCR 2000 (C++/Win32) // Key = Author, Value = TH-OCR 2000 // Key = Creator, Value = TH-OCR PDF Writer // stamp.setMoreInfo(moreInfo); // text Phrase text = null; if (waterMarkText != null) { // Font bfont = getPdfFont(); bfont.setSize(35); bfont.setColor(new BaseColor(192, 192, 192)); text = new Phrase(waterMarkText, bfont); } // image watermark Image img = null; float w = 0; float h = 0; if (waterMarkImage != null) { img = Image.getInstance(waterMarkImage.getAbsolutePath()); w = img.getScaledWidth(); h = img.getScaledHeight(); // img. img.setRotationDegrees(45); } // transparency PdfGState gs1 = new PdfGState(); gs1.setFillOpacity(0.5f); // properties PdfContentByte over; Rectangle pageSize; float x, y; // loop over every page for (int i = 1; i <= n; i++) { pageSize = reader.getPageSizeWithRotation(i); x = (pageSize.getLeft() + pageSize.getRight()) / 2; y = (pageSize.getTop() + pageSize.getBottom()) / 2; // pdf pdf ??? over = stamper.getOverContent(i); // ? // over = stamp.getUnderContent(i); // ?? over.beginText(); over.endText(); ? // ,?,:???? over.saveState(); //?? over.setGState(gs1); if (waterMarkText != null && waterMarkImage != null) { // if (i % 2 == 1) { ColumnText.showTextAligned(over, Element.ALIGN_CENTER, text, x, y, 45); } else over.addImage(img, w, 0, 0, h, x - (w / 2), y - (h / 2)); } else if (waterMarkText != null) { //? ColumnText.showTextAligned(over, Element.ALIGN_CENTER, text, x, y, 45); //?? ,?, :????? // ... } else { //? over.addImage(img, w, 0, 0, h, x - (w / 2), y - (h / 2)); } over.restoreState();//??? } stamper.close(); reader.close(); }
From source file:org.me.modelos.PDFHelper.java
public void tablaToPdf(JTable jTable, File pdfNewFile, String title) { try {/*ww w . j av a 2 s .co m*/ Font subCategoryFont = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD); Document document = new Document(PageSize.LETTER.rotate()); PdfWriter writer = null; try { writer = PdfWriter.getInstance(document, new FileOutputStream(pdfNewFile)); } catch (FileNotFoundException fileNotFoundException) { Message.showErrorMessage(fileNotFoundException.getMessage()); } writer.setBoxSize("art", new Rectangle(150, 10, 700, 580)); writer.setPageEvent(new HeaderFooterPageEvent()); document.open(); document.addTitle(title); document.addSubject("Reporte"); document.addKeywords("reportes, gestion, pdf"); document.addAuthor("Gestion de Proyectos de software"); document.addCreator("gestion de proyectos"); Paragraph parrafo = new Paragraph(title, subCategoryFont); PdfPTable table = new PdfPTable(jTable.getColumnCount()); table.setWidthPercentage(100); PdfPCell columnHeader; for (int column = 0; column < jTable.getColumnCount(); column++) { Font font = new Font(Font.FontFamily.HELVETICA); font.setColor(255, 255, 255); columnHeader = new PdfPCell(new Phrase(jTable.getColumnName(column), font)); columnHeader.setHorizontalAlignment(Element.ALIGN_LEFT); columnHeader.setBackgroundColor(new BaseColor(96, 125, 139)); table.addCell(columnHeader); } table.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255)); table.setHeaderRows(1); BaseColor verdad = new BaseColor(255, 255, 255); BaseColor falso = new BaseColor(214, 230, 244); boolean bandera = false; for (int row = 0; row < jTable.getRowCount(); row++) { for (int column = 0; column < jTable.getColumnCount(); column++) { if (bandera) { table.getDefaultCell().setBackgroundColor(verdad); } else { table.getDefaultCell().setBackgroundColor(falso); } table.addCell(jTable.getValueAt(row, column).toString()); bandera = !bandera; } } parrafo.add(table); document.add(parrafo); document.close(); //JOptionPane.showMessageDialog(null, "Se ha creado el pdf en " + pdfNewFile.getPath(), // "RESULTADO", JOptionPane.INFORMATION_MESSAGE); } catch (DocumentException documentException) { System.out.println("Se ha producido un error " + documentException); JOptionPane.showMessageDialog(null, "Se ha producido un error" + documentException, "ERROR", JOptionPane.ERROR_MESSAGE); } }
From source file:org.openmrs.module.laboratorymanagement.db.hibernate.LaboratoryDAOimpl.java
License:Open Source License
public void exportPatientReportToPDF(HttpServletRequest request, HttpServletResponse response, Map<ConceptName, List<Object[]>> mappedLabExam, String filename, String title, int patientId) throws DocumentException, IOException { Document document = new Document(); Patient patient = Context.getPatientService().getPatient(patientId); // List<PatientBill> patientBills = // (List<PatientBill>)request.getAttribute("reportedPatientBillsPrint"); /*/*w ww . ja v a 2 s. c om*/ * PatientBill pb = null; * * pb = Context.getService(BillingService.class).getPatientBill( * Integer.parseInt(request.getParameter("patientBills"))); */ /* * String filename = pb.getBeneficiary().getPatient().getPersonName() * .toString().replace(" ", "_"); filename = * pb.getBeneficiary().getPolicyIdNumber().replace(" ", "_") + "_" + * filename + ".pdf"; */ response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "report"); // file name PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); writer.setBoxSize("art", new Rectangle(0, 0, 2382, 3369)); writer.setBoxSize("art", PageSize.A4); HeaderFooterMgt event = new HeaderFooterMgt(); writer.setPageEvent(event); document.open(); document.setPageSize(PageSize.A4); // document.setPageSize(new Rectangle(0, 0, 2382, 3369)); document.addAuthor(Context.getAuthenticatedUser().getPersonName().toString());// the name of the author FontSelector fontTitle = new FontSelector(); fontTitle.addFont(new Font(FontFamily.COURIER, 10.0f, Font.ITALIC)); // Report title Chunk chk = new Chunk("Printed on : " + (new SimpleDateFormat("dd-MMM-yyyy").format(new Date()))); chk.setFont(new Font(FontFamily.COURIER, 10.0f, Font.BOLD)); Paragraph todayDate = new Paragraph(); todayDate.setAlignment(Element.ALIGN_RIGHT); todayDate.add(chk); document.add(todayDate); document.add(fontTitle.process("REPUBLIQUE DU RWANDA\n")); document.add(fontTitle.process("POLICE NATIONALE\n")); document.add(fontTitle.process("KACYIRU POLICE HOSPITAL\n")); document.add(fontTitle.process("B.P. 6183 KIGALI\n")); document.add(fontTitle.process("Tl : 584897\n")); document.add(fontTitle.process("E-mail : medical@police.gov.rw")); // End Report title document.add(new Paragraph("\n")); chk = new Chunk("Laboratory results"); chk.setFont(new Font(FontFamily.COURIER, 10.0f, Font.BOLD)); chk.setUnderline(0.2f, -2f); Paragraph pa = new Paragraph(); pa.add(chk); pa.setAlignment(Element.ALIGN_CENTER); document.add(pa); document.add(new Paragraph("\n")); document.add(fontTitle.process("Family Name: " + patient.getFamilyName() + "\n")); document.add(fontTitle.process("Given name: " + patient.getGivenName() + "\n")); document.add(fontTitle.process("Age: " + patient.getAge() + "\n")); // title row FontSelector fontTitleSelector = new FontSelector(); fontTitleSelector.addFont(new Font(FontFamily.COURIER, 9, Font.ITALIC)); // Table of identification; PdfPTable table = null; table = new PdfPTable(2); table.setWidthPercentage(100f); // tableHeader.addCell(table); // document.add(tableHeader); document.add(new Paragraph("\n")); // Table of lab report items; float[] colsWidth = { 6f, 3f, 6f }; table = new PdfPTable(colsWidth); table.setWidthPercentage(100f); BaseColor bckGroundTitle = new BaseColor(170, 170, 170); BaseColor bckGroundTitl = new BaseColor(Color.yellow); // table Header PdfPCell cell = new PdfPCell(fontTitleSelector.process("Exam")); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); cell = new PdfPCell(fontTitleSelector.process("Result")); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); cell = new PdfPCell(fontTitleSelector.process("Normal Range")); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); /* * cell = new PdfPCell(fontTitleSelector.process("Date ")); * cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); */ // normal row FontSelector fontselector = new FontSelector(); fontselector.addFont(new Font(FontFamily.COURIER, 8, Font.NORMAL)); // empty row FontSelector fontTotals = new FontSelector(); fontTotals.addFont(new Font(FontFamily.COURIER, 9, Font.BOLD)); // =========================================================== for (ConceptName cptName : mappedLabExam.keySet()) { cell = new PdfPCell(fontTitleSelector.process("" + cptName)); cell.setBackgroundColor(bckGroundTitl); table.addCell(cell); cell = new PdfPCell(fontTitleSelector.process("")); table.addCell(cell); cell = new PdfPCell(fontTitleSelector.process("")); table.addCell(cell); List<Object[]> labExamHistory = mappedLabExam.get(cptName); for (Object[] labExam : labExamHistory) { // table Header // Object[] labe = listOflabtest.get(i); Obs ob = (Obs) labExam[0]; cell = new PdfPCell(fontTitleSelector.process("" + ob.getConcept().getName())); table.addCell(cell); if (ob.getConcept().getDatatype().isNumeric()) { cell = new PdfPCell(fontTitleSelector.process("" + ob.getValueNumeric())); table.addCell(cell); } if (ob.getConcept().getDatatype().isCoded()) { cell = new PdfPCell(fontTitleSelector.process("" + ob.getValueCoded().getName())); table.addCell(cell); } if (ob.getConcept().getDatatype().isText()) { cell = new PdfPCell(fontTitleSelector.process("" + ob.getValueText())); table.addCell(cell); } cell = new PdfPCell(fontTitleSelector.process("" + (labExam[1] != null ? labExam[1] : "-"))); table.addCell(cell); fontselector.addFont(new Font(FontFamily.COURIER, 8, Font.NORMAL)); // empty row // FontSelector fontTotals = new FontSelector(); fontTotals.addFont(new Font(FontFamily.COURIER, 9, Font.BOLD)); } } cell = new PdfPCell(fontTitleSelector.process("Names, Signature et Stamp of Lab Chief\n" //+ Context.getAuthenticatedUser().getPersonName())); + Context.getUserService().getUser(140).getPersonName())); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // ================================================================ table.addCell(cell); document.add(table); // Table of signatures; table = new PdfPTable(2); table.setWidthPercentage(100f); cell = new PdfPCell(fontTitleSelector.process(" ")); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(fontTitleSelector.process( "Names, Signature and Stamp of Provider\n" + Context.getAuthenticatedUser().getPersonName())); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); document.add(table); document.close(); document.close(); }
From source file:org.openmrs.module.mohtracportal.util.FileExporter.java
License:Open Source License
/** * @param request/*from w w w. j a va 2 s . c o m*/ * @param response * @param res * @param filename * @param title * @param from * @param to * @param selectedUsers * @throws Exception */ public void exportToPDF(HttpServletRequest request, HttpServletResponse response, List<Object> res, String filename, String title, String from, String to, List<Integer> selectedUsers) throws Exception { SimpleDateFormat sdf = Context.getDateFormat(); Document document = new Document(); response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); // file name PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); writer.setBoxSize("art", new Rectangle(36, 54, 559, 788)); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); document.open(); document.setPageSize(PageSize.A4); document.addAuthor(Context.getAuthenticatedUser().getPersonName().getFamilyName() + " " + Context.getAuthenticatedUser().getPersonName().getGivenName());// the name of the author PersonService ps = Context.getPersonService(); String users = ""; for (Integer usrId : selectedUsers) { users += ps.getPerson(usrId).getPersonName() + "; "; } FontSelector fontTitle = new FontSelector(); fontTitle.addFont(new Font(FontFamily.COURIER, 10.0f, Font.BOLD)); title = MohTracUtil.getMessage("mohtracportal.report.title", null) + " : " + title; String underLine = ""; int count = 0; while (count < title.length()) { count += 1; underLine += "_"; } document.add(fontTitle.process(title));// Report title if (from.trim().compareTo("") != 0) document.add(fontTitle .process("\n" + MohTracUtil.getMessage("mohtracportal.from", null) + " : " + from));// from if (to.trim().compareTo("") != 0) document.add( fontTitle.process("\n" + MohTracUtil.getMessage("mohtracportal.to", null) + " : " + to));// to document.add(fontTitle.process("\n" + MohTracUtil.getMessage("mohtracportal.report.created.on", null) + " : " + sdf.format(new Date())));// Report date document.add(fontTitle.process("\n" + MohTracUtil.getMessage("mohtracportal.report.created.by", null) + " : " + Context.getAuthenticatedUser().getPersonName()));// Report // author Integer numberOfPatients = res.size(); document.add(fontTitle.process("\n" + MohTracUtil.getMessage("mohtracportal.numberOfPatients", null) + " : " + numberOfPatients.toString()));// Number of patients if (users.trim().compareTo("") != 0) document.add(fontTitle.process( "\n" + MohTracUtil.getMessage("mohtracportal.patient.enterers", null) + " : " + users));// enterer(s) document.add(fontTitle.process("\n" + underLine));// Report title document.add(new Paragraph("\n\n")); boolean hasPrivToViewPatientNames = Context.getAuthenticatedUser().hasPrivilege("View Patient Names"); // PdfLine line; PdfPTable table = null; if (hasPrivToViewPatientNames == true) { float[] colsWidth = { 1.2f, 5f, 2.7f, 2.7f, 4.2f, 2.7f }; table = new PdfPTable(colsWidth); } else { float[] colsWidth = { 1.2f, 2.7f, 2.7f, 4.2f, 2.7f }; table = new PdfPTable(colsWidth); } // column number table.setTotalWidth(540f); // title row FontSelector fontTitleSelector = new FontSelector(); fontTitleSelector.addFont(new Font(FontFamily.COURIER, 9, Font.BOLD)); BaseColor bckGroundTitle = new BaseColor(170, 170, 170); // table Header PdfPCell cell = new PdfPCell( fontTitleSelector.process(MohTracUtil.getMessage("mohtracportal.report.list.no", null))); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); if (hasPrivToViewPatientNames) { cell = new PdfPCell( fontTitleSelector.process(MohTracUtil.getMessage("mohtracportal.patient.names", null))); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); } cell = new PdfPCell(fontTitleSelector.process(MohTracPortalTag .getIdentifierTypeNameByIdAsString("" + MohTracConfigurationUtil.getTracNetIdentifierTypeId()))); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); cell = new PdfPCell(fontTitleSelector.process(MohTracPortalTag.getIdentifierTypeNameByIdAsString( "" + MohTracConfigurationUtil.getLocalHealthCenterIdentifierTypeId()))); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); cell = new PdfPCell( fontTitleSelector.process(MohTracUtil.getMessage("mohtracportal.patient.date.created", null) + "(" + Context.getDateFormat().toPattern() + ")")); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); cell = new PdfPCell( fontTitleSelector.process(MohTracUtil.getMessage("mohtracportal.numberOfEncounters", null))); cell.setBackgroundColor(bckGroundTitle); table.addCell(cell); // normal row FontSelector fontselector = new FontSelector(); fontselector.addFont(new Font(FontFamily.COURIER, 8, Font.NORMAL)); // empty row FontSelector fontEmptyCell = new FontSelector(); fontEmptyCell.addFont(new Font(FontFamily.COURIER, 8, Font.NORMAL)); int ids = 0; for (Object patient : res) { Object[] o = (Object[]) patient; ids += 1; cell = new PdfPCell(fontselector.process(ids + "")); if (o[2].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(238, 238, 238)); if (o[3].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(224, 0, 0)); table.addCell(cell); if (hasPrivToViewPatientNames) { String names = MohTracPortalTag.getPersonNames(Integer.valueOf(o[0].toString())); cell = new PdfPCell(fontselector.process(names + "")); if (names.compareTo("-") == 0) cell.setBackgroundColor(new BaseColor(224, 224, 240)); if (o[2].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(238, 238, 238)); if (o[3].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(224, 0, 0)); table.addCell(cell); } String tracnetId = MohTracPortalTag.personIdentifierByPatientIdAndIdentifierTypeId( Integer.valueOf(o[0].toString()), MohTracConfigurationUtil.getTracNetIdentifierTypeId()); cell = new PdfPCell(fontselector.process(tracnetId + "")); if (tracnetId.compareTo("-") == 0) cell.setBackgroundColor(new BaseColor(224, 224, 240)); if (o[2].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(238, 238, 238)); if (o[3].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(224, 0, 0)); table.addCell(cell); String cohortId = MohTracPortalTag.personIdentifierByPatientIdAndIdentifierTypeId( Integer.valueOf(o[0].toString()), MohTracConfigurationUtil.getLocalHealthCenterIdentifierTypeId()); cell = new PdfPCell(fontselector.process(cohortId + "")); if (cohortId.compareTo("-") == 0) cell.setBackgroundColor(new BaseColor(224, 224, 240)); if (o[2].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(238, 238, 238)); if (o[3].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(224, 0, 0)); table.addCell(cell); cell = new PdfPCell(fontselector.process(sdf.format(o[1]) + "")); if (o[2].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(238, 238, 238)); if (o[3].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(224, 0, 0)); table.addCell(cell); String numberOfEncounters = MohTracPortalTag .getNumberOfEncounterByPatient(Integer.valueOf(o[0].toString())); cell = new PdfPCell(fontselector.process(numberOfEncounters + "")); if (numberOfEncounters.compareTo("-") == 0) cell.setBackgroundColor(new BaseColor(224, 224, 240)); if (o[2].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(238, 238, 238)); if (o[3].toString().compareTo("1") == 0) cell.setBackgroundColor(new BaseColor(224, 0, 0)); table.addCell(cell); } document.add(table); document.close(); log.info("pdf file created"); }
From source file:org.opentox.ontology.components.Algorithm.java
License:Open Source License
@Override public PDFObject getPDF() { PDFObject pdf = new PDFObject(); pdf.setPdfTitle(getMeta().identifier); pdf.setPdfKeywords(getMeta().subject); Paragraph p1 = new Paragraph( new Chunk("OpenTox - Algorithm Report\n\n", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 14))); pdf.addElement(p1);/* w w w . j av a 2s . c o m*/ try { PdfPTable table = new PdfPTable(2); table.setWidths(new int[] { 10, 50 }); PdfPCell cell = new PdfPCell(new Paragraph("Algorithm Presentation - General")); cell.setColspan(2); cell.setBackgroundColor(new BaseColor(0xC0, 0xC0, 0xC0)); table.addCell(cell); table.addCell("Name"); table.addCell(getMeta().getName()); table.addCell("Title"); table.addCell(getMeta().title); table.addCell("Subject"); table.addCell(getMeta().subject); table.addCell("Description"); table.addCell(getMeta().description); table.addCell("Identifier"); table.addCell(getMeta().identifier); pdf.addElement(table); pdf.addElement(new Paragraph("\n\n\n")); table = new PdfPTable(2); table.setWidths(new int[] { 10, 50 }); cell = new PdfPCell(new Paragraph("General Meta Information")); cell.setColspan(2); cell.setBackgroundColor(new BaseColor(0xC0, 0xC0, 0xC0)); table.addCell(cell); table.addCell("Type"); table.addCell(getMeta().type); table.addCell("Creator"); table.addCell(getMeta().creator); table.addCell("Publisher"); table.addCell(getMeta().publisher); table.addCell("Relation"); table.addCell(getMeta().relation); table.addCell("Rights"); table.addCell(getMeta().rights); table.addCell("Source"); table.addCell(getMeta().source); table.addCell("Provenance"); table.addCell(getMeta().provenance); table.addCell("Contributor"); table.addCell(getMeta().contributor); table.addCell("Language"); table.addCell(getMeta().language.getDisplayLanguage()); table.addCell("Created on"); table.addCell(getMeta().date.toString()); table.addCell("Formats"); ArrayList<MediaType> listMedia = getMeta().format; String formatTableEntry = ""; for (int i = 0; i < listMedia.size(); i++) { formatTableEntry += listMedia.get(i).toString(); if (i < listMedia.size() - 1) { formatTableEntry += "\n"; } } table.addCell(formatTableEntry); table.addCell("Audience"); ArrayList<Audience> audiences = getMeta().audience; String auds = ""; for (int i = 0; i < audiences.size(); i++) { auds += audiences.get(i).getName(); if (i < audiences.size() - 1) { auds += "\n"; } } table.addCell(auds); pdf.addElement(table); pdf.addElement(new Paragraph("\n\n\n")); table = new PdfPTable(4); table.setWidths(new int[] { 30, 30, 30, 30 }); cell = new PdfPCell(new Paragraph("Algorithm Parameters")); cell.setColspan(4); cell.setBackgroundColor(new BaseColor(0xC0, 0xC0, 0xC0)); table.addCell(cell); table.addCell("Parameter Name"); table.addCell("XSD DataType"); table.addCell("Default Value"); table.addCell("Scope"); Map<String, AlgorithmParameter> algParameters = getMeta().getParameters(); Set<Entry<String, AlgorithmParameter>> entrySet = algParameters.entrySet(); for (Entry e : entrySet) { String pName = (String) e.getKey(); AlgorithmParameter ap = (AlgorithmParameter) e.getValue(); table.addCell(pName); table.addCell(ap.dataType.getURI()); table.addCell(ap.paramValue.toString()); table.addCell(ap.paramScope.toString()); } pdf.addElement(table); pdf.addElement(new Paragraph("\n\n\n")); table = new PdfPTable(1); cell = new PdfPCell(new Paragraph("Ontologies")); cell.setBackgroundColor(new BaseColor(0xC0, 0xC0, 0xC0)); table.addCell(cell); OTAlgorithmTypes type = getMeta().getAlgorithmType(); table.addCell(type.getURI()); Set<Resource> superOntologies = type.getSuperEntities(); Iterator<Resource> it = superOntologies.iterator(); while (it.hasNext()) { table.addCell(it.next().getURI()); } pdf.addElement(table); } catch (final DocumentException ex) { YaqpLogger.LOG.log(new Warning(getClass(), "XCF316 - Pdf Exception :" + ex.toString())); } return pdf; }