List of usage examples for com.itextpdf.text Element ALIGN_LEFT
int ALIGN_LEFT
To view the source code for com.itextpdf.text Element ALIGN_LEFT.
Click Source Link
From source file:Almacen.Responsiva.java
private void b_imprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_imprimirActionPerformed // TODO add your handling code here: Session session = HibernateUtil.getSessionFactory().openSession(); try {/*from ww w . j av a 2s . c o m*/ String empleado = ""; String puesto = ""; if (t_datos.getRowCount() > 0) { //consulta Query q = session.createSQLQuery( "select empleado.nombre as empleado, puestos.nombre as puesto from empleado inner join puestos on puestos.id_puestos=empleado.id_puesto where empleado.id_empleado=" + t_id_empleado.getText() + ";"); q.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); List lista = q.list(); for (int i = 0; i < lista.size(); i++) { java.util.HashMap map = (java.util.HashMap) lista.get(i); empleado = (String) map.get("empleado"); puesto = (String) map.get("puesto"); } Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String Mes[] = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }; Calendar fecha1 = new GregorianCalendar(); int anio = fecha1.get(Calendar.YEAR); int mes = fecha1.get(Calendar.MONTH); int dia = fecha1.get(Calendar.DAY_OF_MONTH); //DateFormat dateFormat1 = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); File folder = new File("reportes/Responsivas"); folder.mkdirs(); PdfReader reader = new PdfReader("imagenes/CartaResponsiva.pdf"); PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("reportes/Responsivas/" + valor + "CartaResponsiva.pdf")); PdfContentByte cb = stamp.getUnderContent(1); PdfContentByte cb2 = stamp.getUnderContent(2); AcroFields fdfDoc = stamp.getAcroFields(); // Creo una fuente BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); cb.beginText(); //dia try { if (dia < 9) fdfDoc.setField("Dia", "0" + String.valueOf(dia)); else fdfDoc.setField("Dia", String.valueOf(dia)); } catch (Exception e) { fdfDoc.setField("Dia", "error"); } //mes try { fdfDoc.setField("Mes", Mes[mes]); } catch (Exception e) { fdfDoc.setField("Mes", ""); } //ao try { fdfDoc.setField("Anio", String.valueOf(anio)); } catch (Exception e) { fdfDoc.setField("Anio", ""); } //nombre try { fdfDoc.setField("Nombre", empleado); } catch (Exception e) { fdfDoc.setField("Nombre", ""); } //puesto try { fdfDoc.setField("Puesto", puesto); } catch (Exception e) { fdfDoc.setField("Puesto", ""); } //tabla de herramientas float tam[] = new float[] { 250, 50, 180 }; Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD); PDF reporte = new PDF(); PdfPTable tabla = reporte.crearTabla(3, tam, 100, Element.ALIGN_LEFT); tabla.setTotalWidth(tam); BaseColor cabecera = BaseColor.GRAY; BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; tabla.addCell(reporte.celda("HERRAMIENTA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("CANTIDAD", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("NOTAS", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); for (int i = 0; i < t_datos.getRowCount(); i++) { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 1).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(String.valueOf((double) t_datos.getValueAt(i, 2)), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); if (t_datos.getValueAt(i, 3) != null) tabla.addCell(reporte.celda(t_datos.getValueAt(i, 3).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } tabla.completeRow(); tabla.writeSelectedRows(0, -1, 70, 720, cb2); cb.endText(); stamp.close(); reporte.cerrar(); reporte.visualizar("reportes/Responsivas/" + valor + "CartaResponsiva.pdf"); } else { JOptionPane.showMessageDialog(this, "No Existe Ninguna Responsiva"); } } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto"); } if (session != null) { if (session.isOpen()) { session.close(); } } }
From source file:app.App.java
private void setLink(int pageId, PdfStamper stamper) throws ClassNotFoundException, IOException { // load the sqlite-JDBC driver using the current class loader Class.forName("org.sqlite.JDBC"); Connection connection = null; try {//from www . ja va 2 s.co m // create a database connection connection = DriverManager.getConnection("jdbc:sqlite:" + DATABASE); Statement statement = connection.createStatement(); statement.setQueryTimeout(30); // set timeout to 30 sec. ResultSet rs = statement.executeQuery( "select * from page_annotations " + "where annotation_type = 'goto' and page_id = " + pageId); float spendX = 0; float spendY = 0; float coordX = 0; float coordY = 0; int pageDest = 0; Rectangle rect; PdfAnnotation annotation; while (rs.next()) { spendX = rs.getFloat("pdf_width"); spendY = rs.getFloat("pdf_height"); coordX = rs.getFloat("pdf_x");// + rs.getFloat("pdf_width"); coordY = rs.getFloat("pdf_y"); pageDest = rs.getInt("annotation_target"); Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.UNDERLINE); // Blue font.setColor(0, 0, 255); Chunk chunk = new Chunk("GOTO", font); Anchor anchor = new Anchor(chunk); ColumnText.showTextAligned(stamper.getUnderContent(pageId), Element.ALIGN_LEFT, anchor, coordX + spendX, coordY, 0); rect = new Rectangle(coordX, coordY, spendX, spendY); annotation = PdfAnnotation.createLink(stamper.getWriter(), rect, PdfAnnotation.HIGHLIGHT_INVERT, new PdfAction("#" + pageDest)); stamper.addAnnotation(annotation, pageId); } } catch (SQLException e) { // if the error message is "out of memory", // it probably means no database file is found System.err.println(e.getMessage()); } finally { try { if (connection != null) connection.close(); } catch (SQLException e) { // connection close failed. System.err.println(e); } } }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private byte[] personalize(byte[] pdf, Contact contact, Toc tableOfContents) throws IOException, DocumentException { try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) { final PdfReader reader = new PdfReader(pdf); final PdfStamper stamper = new PdfStamper(reader, bos); // stamp some text on first page PdfContentByte text = stamper.getOverContent(1); text.beginText();/* w w w . j av a 2s. com*/ text.setColorFill(iTextUtil.getFontCoverText().getColor()); text.setFontAndSize(iTextUtil.getFontCoverText().getBaseFont(), iTextUtil.getFontCoverText().getSize()); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle1, text.getPdfDocument().getPageSize().getWidth() - 15, 195, 0); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle2, text.getPdfDocument().getPageSize().getWidth() - 15, 175, 0); text.showTextAligned(Element.ALIGN_RIGHT, contact.getCurrency().getTitlePageDescription(), text.getPdfDocument().getPageSize().getWidth() - 15, 80, 0); text.setColorFill(iTextUtil.getFontCoverPricingguide().getColor()); text.setFontAndSize(iTextUtil.getFontCoverPricingguide().getBaseFont(), iTextUtil.getFontCoverPricingguide().getSize()); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle3, text.getPdfDocument().getPageSize().getWidth() - 15, 145, 0); text.setColorFill(iTextUtil.getFontCoverYear().getColor()); text.setFontAndSize(iTextUtil.getFontCoverYear().getBaseFont(), iTextUtil.getFontCoverYear().getSize()); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle4, text.getPdfDocument().getPageSize().getWidth() - 15, 105, 0); text.endText(); // stamp some text on first page of the table of contents page final Image logoImage = iTextUtil.getImageFromByteArray(HttpUtil.readByteArray( pdfTemplate.getLogo().getUrl(), defaultService.getUserName(), defaultService.getPassword())); final PdfContentByte tocContent = stamper.getOverContent(tableOfContents.getFirstPageOfToc()); final float resizeRatio = logoImage.getHeight() / 85; // define the desired height of the log tocContent.addImage(logoImage, logoImage.getWidth() / resizeRatio, 0, 0, logoImage.getHeight() / resizeRatio, 59, 615); text = stamper.getOverContent(tableOfContents.getFirstPageOfToc()); text.beginText(); text.setColorFill(iTextUtil.getFontPersonalization().getColor()); text.setFontAndSize(iTextUtil.getFontPersonalization().getBaseFont(), iTextUtil.getFontPersonalization().getSize()); text.showTextAligned(Element.ALIGN_LEFT, "Prepared for:", 355, 681, 0); text.showTextAligned(Element.ALIGN_LEFT, contact.getFullName(), 355, 662, 0); // set company name if (!StringUtils.isEmpty(contact.getCompany())) { text.showTextAligned(Element.ALIGN_LEFT, contact.getCompany(), 355, 643, 0); text.showTextAligned(Element.ALIGN_LEFT, new SimpleDateFormat("MM-dd-yyyy").format(new Date()), 355, 624, 0); } else { text.showTextAligned(Element.ALIGN_LEFT, new SimpleDateFormat("MM-dd-yyyy").format(new Date()), 355, 643, 0); } text.endText(); final ColumnText ct = new ColumnText(tocContent); ct.setSimpleColumn(new Rectangle(55, 517, iTextUtil.PAGE_SIZE.getWidth() - 45, 575)); final List<Element> elements = HTMLWorker.parseToList(new StringReader(disclaimer), null); final Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_JUSTIFIED); for (Element element : elements) { for (Chunk chunk : element.getChunks()) { chunk.setFont(iTextUtil.getFontDisclaimer()); } p.add(element); } ct.addElement(p); ct.go(); stamper.close(); reader.close(); return bos.toByteArray(); } }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private byte[] stampTableOfContents(byte[] pdf, Toc tableOfContents) throws IOException, DocumentException { try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) { final PdfReader reader = new PdfReader(pdf); final PdfStamper stamper = new PdfStamper(reader, bos); // stamp the named destinations for (int pageNumber = 1; pageNumber <= reader.getNumberOfPages(); pageNumber++) { stamper.addNamedDestination("page" + pageNumber, pageNumber, new PdfDestination(PdfDestination.XYZ, 80f, 800f, 0)); }/* ww w .j a v a 2s . c om*/ // create the table of contents final Chunk tocTitle = new Chunk("TABLE OF CONTENTS", iTextUtil.getFontTocTitle()); int currentTocPage = tableOfContents.getFirstPageOfToc(); int firstTocPage = currentTocPage; PdfContentByte canvas = stamper.getOverContent(currentTocPage); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(tocTitle), 55, 470, 0); final List<TocEntry> entriesSorted = tableOfContents.getEntriesSorted(); int tocEntryNumber = 0; for (TocEntry tocEntry : entriesSorted) { if (tocEntry.isIncludedInToc()) { tocEntryNumber++; // take the right TOC page to stamp the TOC entry on (needed for TOC's with multiple pages) if (tocEntryNumber == getNumberOfItemsPerTocPage(0) || (tocEntryNumber > getNumberOfItemsPerTocPage(0) && (tocEntryNumber - getNumberOfItemsPerTocPage(0)) % getNumberOfItemsPerTocPage(currentTocPage - firstTocPage) == 0)) { currentTocPage++; canvas = stamper.getOverContent(currentTocPage); } Font font = iTextUtil.getFontToc(); if (tocEntry.getLevel() == 1) { font = iTextUtil.getFontTocBold(); } final Phrase p = processHtmlCodes(tocEntry.getLevelString() + tocEntry.getName(), font, iTextUtil.getFontTocSymbol()); p.add(new Chunk("", iTextUtil.getFontToc())); if (tocEntry.isShowingPageNumber()) { p.add(new Chunk(new DottedLineSeparator())); p.add(new Chunk(" " + String.valueOf(tocEntry.getFinalPageNumber()), iTextUtil.getFontToc())); } for (Chunk chunk : p.getChunks()) { chunk.setAction(PdfAction.gotoLocalPage("page" + tocEntry.getFinalPageNumber(), false)); } int y; if (tocEntryNumber < getNumberOfItemsPerTocPage(0)) { y = 460 - (16 * (tocEntryNumber % getNumberOfItemsPerTocPage(0))); } else { y = 680 - (16 * ((tocEntryNumber - getNumberOfItemsPerTocPage(0)) % getNumberOfItemsPerTocPage(currentTocPage - firstTocPage))); } final ColumnText ct = new ColumnText(canvas); ct.setSimpleColumn(p, 52, y, 555, 70, 0, Element.ALIGN_JUSTIFIED); ct.go(); } } stamper.close(); reader.close(); return bos.toByteArray(); } }
From source file:billerfx.FXMLBillController.java
File generatePDF() { File fi = null;/*from ww w.ja v a 2s .c om*/ try { Stage gg = ((Stage) imv.getParent().getScene().getWindow()); fi = File.createTempFile("billerfx_" + gg.getTitle(), ".pdf"); fi.deleteOnExit(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(fi)); Rectangle r = new RectangleReadOnly(207, 575); document.setPageSize(r); document.setMargins(15, 15, 0, 0); document.open(); Font fontbold = FontFactory.getFont("Times-Roman", 10, Font.NORMAL); Font fontbold2 = FontFactory.getFont("Times-Roman", 9, Font.NORMAL); String[] ll = Database.getCurrentSettings(); String ss = "-----------------------------------------------------\n"; ss += ll[0] + "\nAddress: " + ll[1] + "\nPhone: " + ll[2] + "\n"; String kk = Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM ? "AM" : (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.PM ? "PM" : ""); ss += Calendar.getInstance().get(Calendar.DATE) + "/" + (1 + Calendar.getInstance().get(Calendar.MONTH)) + "/" + Calendar.getInstance().get(Calendar.YEAR) + " at " + Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE) + " " + kk + "\n"; ss += "Table No. " + c.getText() + " Bill No. " + a.getText() + "\n"; ss += "-----------------------------------------------------\n"; Paragraph para = new Paragraph(ss, fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); float[] columnWidths = { 3f, 1f }; table.setWidths(columnWidths); PdfPCell defaultCell = table.getDefaultCell(); defaultCell.setBorder(PdfPCell.NO_BORDER); ObservableList ob = map.get(Integer.parseInt(gg.getTitle())); for (int i = 0; i < ob.size(); i++) { Item2 ii = (Item2) ob.get(i); String s1 = ii.getQuantity() + " x " + ii.getName(); String s2 = "Rs. " + ii.getTotal(); Paragraph para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); Paragraph para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); PdfPCell cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } document.add(table); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(columnWidths); defaultCell = table.getDefaultCell(); defaultCell.setBorder(PdfPCell.NO_BORDER); String s1 = "Total:"; String s2 = "Rs. " + h.getText(); Paragraph para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); Paragraph para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); PdfPCell cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); if (Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()) > 0.0) { s1 = "Discount:"; s2 = "Rs. " + BillerFX.df.format(Double.parseDouble(h.getText()) - Double.parseDouble(i.getText())); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } if (ll[7].equals("1")) { s1 = ll[3]; s2 = "Rs. " + k.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } if (ll[8].equals("1")) { s1 = ll[4]; s2 = "Rs. " + l.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } s1 = "Grand Total:"; s2 = "Rs. " + m.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); document.add(table); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); fontbold2 = FontFactory.getFont("Times-Roman", 8, Font.NORMAL); para = new Paragraph( "Thank You.\nThis invoice was created using BillerFX.\n (BillerFX Contact: ayushmaanbhav1008@gmail.com)\n", fontbold2); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); document.close(); } catch (Exception mm) { } return fi; }
From source file:bl.pdf.PDFFile.java
public void createRechnung(Rechnung r) throws DocumentException, DALException { document.open();// w w w . j a va 2 s . c o m Paragraph preface = new Paragraph(); preface.add(newLine(new Date().toString(), small, Element.ALIGN_RIGHT)); // Lets write a big header preface.add(newLine("Rechnung", catFont, -1)); preface.add(newLine(r.getValues(), small, Element.ALIGN_LEFT)); // Will create: Report generated by: _name, _date String to = ""; if (r instanceof Ausgangsrechnung) { Kunde k = BL.getKunde(((Ausgangsrechnung) r).getKundeID()); to += k.getValues(); } else if (r instanceof Eingangsrechnung) { Kontakt k = BL.getKontakt(((Eingangsrechnung) r).getKontaktID()); to += k.getValues(); } preface.add(newLine(to, smallBold, Element.ALIGN_RIGHT)); // We add one empty line addEmptyLine(preface, 2); // add table preface.add(getRechnungszeileTable(r)); document.add(preface); // Start a new page document.newPage(); document.close(); }
From source file:book.pdftemplates.FillTemplateHelper.java
@Override public void onCloseDocument(PdfWriter writer, Document document) { // we only know the total number of pages at the moment the document is closed. String s = "/" + (writer.getPageNumber() - 1); Phrase p = new Phrase(12, s, font); ColumnText.showTextAligned(total, Element.ALIGN_LEFT, p, 0.5f, 0, 0); }
From source file:bouttime.report.award.AwardInventoryReport.java
License:Open Source License
private static PdfPTable getDataTable(int[] awardCounts, int maxAward) throws DocumentException { Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10); // create and add the table PdfPTable datatable = new PdfPTable(2); int colWidths[] = { 90, 10 }; // percentage datatable.setWidths(colWidths);//from ww w. ja va2 s.co m datatable.setWidthPercentage(100); datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); for (int i = 0; i < maxAward; i++) { if ((i % 2) == 0) { datatable.getDefaultCell().setGrayFill(0.9f); } else { datatable.getDefaultCell().setGrayFill(1); } String place = null; switch (i) { case 0: place = "1st Place"; break; case 1: place = "2nd Place"; break; case 2: place = "3rd Place"; break; case 3: place = "4th Place"; break; case 4: place = "5th Place"; break; case 5: place = "6th Place"; break; case 6: place = "7th Place"; break; default: logger.warn("unexpected place value : " + i); place = "???"; break; } datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(new Phrase(place, detailFont)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(new Phrase(Integer.toString(awardCounts[i]), detailFont)); } datatable.setSpacingBefore(5f); datatable.setSpacingAfter(15f); return datatable; }
From source file:bouttime.report.award.AwardReport.java
License:Open Source License
/** * Generate an award report.// w ww.j av a 2s. c o m * @param dao Dao object to use to retrieve data. * @param session Session to generate the report for. * @param group Group to generate report for. This takes precedence, so * if not null, then the report will be generated for this group. * @return True if the report was generated. */ private static boolean doReport(Dao dao, String session, Group group) { if (!dao.isOpen()) { return false; } // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: create and add content // create and add the header Paragraph p1 = new Paragraph(new Paragraph( String.format("%s %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()), FontFactory.getFont(FontFactory.HELVETICA, 10))); document.add(p1); Paragraph p2 = new Paragraph( new Paragraph("Award Report", FontFactory.getFont(FontFactory.HELVETICA, 14))); p2.setAlignment(Paragraph.ALIGN_CENTER); document.add(p2); Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12); Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10); PdfPCell headerCell = new PdfPCell(); headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); headerCell.setPadding(3); headerCell.setBorderWidth(2); List<Group> groups; if (group != null) { groups = new ArrayList<Group>(); groups.add(group); } else if (session != null) { groups = dao.getGroupsBySession(session); } else { groups = dao.getAllGroups(); } for (Group g : groups) { // create and add the table PdfPTable datatable = new PdfPTable(4); int colWidths[] = { 30, 30, 30, 10 }; // percentage datatable.setWidths(colWidths); datatable.setWidthPercentage(100); datatable.getDefaultCell().setPadding(3); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // The header has the group name headerCell.setPhrase(new Phrase(g.toString(), headerFont)); headerCell.setColspan(4); datatable.addCell(headerCell); datatable.setHeaderRows(1); // this is the end of the table header datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); List<Wrestler> wList = getSortedAwardList(g); int i = 0; for (Wrestler w : wList) { if ((i++ % 2) == 0) { datatable.getDefaultCell().setGrayFill(0.9f); } else { datatable.getDefaultCell().setGrayFill(1); } datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(new Phrase(w.getFirstName(), detailFont)); datatable.addCell(new Phrase(w.getLastName(), detailFont)); datatable.addCell(new Phrase(w.getTeamName(), detailFont)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); Integer place = w.getPlace(); String placeStr = (place == null) ? "" : place.toString(); datatable.addCell(new Phrase(placeStr, detailFont)); } datatable.setSpacingBefore(5f); datatable.setSpacingAfter(15f); document.add(datatable); } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.boutsequence.BoutSequenceReport.java
License:Open Source License
private static PdfPTable addBoutSequences(List<Wrestler> wList, String session) throws DocumentException { // create and add the table Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12); Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10); PdfPCell headerCell = new PdfPCell(); headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); headerCell.setPadding(3);//from w w w . j a v a 2 s. com headerCell.setBorderWidth(2); PdfPTable datatable = new PdfPTable(3); int colWidths[] = { 5, 25, 70 }; // percentage datatable.setWidths(colWidths); datatable.setWidthPercentage(100); datatable.getDefaultCell().setPadding(3); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); headerCell.setPhrase(new Phrase("Mat", headerFont)); datatable.addCell(headerCell); headerCell.setPhrase(new Phrase("Name", headerFont)); datatable.addCell(headerCell); headerCell.setPhrase(new Phrase("Bout Sequence", headerFont)); datatable.addCell(headerCell); datatable.setHeaderRows(1); // this is the end of the table header datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); Collections.sort(wList, new WrestlerMatNameSort()); int i = 0; for (Wrestler w : wList) { if (w.getGroup() == null) { logger.debug(String.format("Wrestler [%s] is not in a group, skipping.", w.getShortName())); continue; } if ((session != null) && !session.equalsIgnoreCase(w.getGroup().getSession())) { logger.debug(String.format("Wrestler [%s] is in a group but not in session %s, skipping.", w.getShortName(), session)); continue; } if ((i++ % 2) == 0) { datatable.getDefaultCell().setGrayFill(0.9f); } else { datatable.getDefaultCell().setGrayFill(1); } List<Bout> bList = BoutSequence.calculate(w); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(new Phrase(w.getGroup().getMat(), detailFont)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(new Phrase(String.format("%s %s", w.getFirstName(), w.getLastName()), detailFont)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); String boutSequenceString = getBoutSequenceString(bList); datatable.addCell(new Phrase(boutSequenceString, detailFont)); } datatable.setSpacingBefore(5f); datatable.setSpacingAfter(15f); return (i > 0 ? datatable : null); }