List of usage examples for com.itextpdf.text.pdf PdfPTable addCell
public void addCell(final Phrase phrase)
From source file:climbingcompranking.model.ranking.RankingGenerator.java
License:Open Source License
public void createRankingPDF(String competitionName, CompetitionType compType) { doTheRanking(compType);// ww w .j a v a 2 s . c om try { Document document = new Document(PageSize.A4.rotate()); // Landscape Date date = new Date(); String dateStr = ""; if (Locale.getDefault().equals(Locale.FRANCE)) { dateStr = new SimpleDateFormat("dd-MM-yyyy").format(date); } else { dateStr = new SimpleDateFormat("yyyy-MM-dd").format(date); } PdfWriter.getInstance(document, new FileOutputStream("data/pdf/" + competitionName + '-' + dateStr + ".pdf")); document.open(); // Meta data document.addTitle(competitionName); document.addSubject(competitionName + " ranking."); document.addKeywords(competitionName + ", ranking, climbingcompetition, climbcompranking"); document.addAuthor("ClimbingCompRanking - https://github.com/Yaty/ClimbingCompRanking"); document.addCreator("ClimbingCompRanking - https://github.com/Yaty/ClimbingCompRanking"); document.addCreationDate(); document.setMargins(0, 0, 0, 0); PdfPCell club = new PdfPCell(new Phrase(I18n.MODEL.getString("Club"))); PdfPCell climberName = new PdfPCell(new Phrase(I18n.MODEL.getString("ClimberName"))); PdfPCell ranking = new PdfPCell(new Phrase(I18n.MODEL.getString("Ranking"))); for (Map.Entry<Category, ArrayList<Climber>> climbersCategory : climbersMap.entrySet()) { if (climbersCategory.getValue().isEmpty()) continue; document.newPage(); // Title Paragraph title = new Paragraph( competitionName + " : " + climbersCategory.getKey().getCategoryName()); title.setAlignment(Element.ALIGN_CENTER); title.setFont(new Font(Font.FontFamily.HELVETICA, 36)); title.setSpacingAfter(20); // Table PdfPTable table = null; switch (compType) { case BOULDERING: case LEAD: case SPEED: table = new PdfPTable(3); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; case LEAD_AND_BOULDERING: table = new PdfPTable(6); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum")))); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank())))); table.addCell( new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank())))); table.addCell(new PdfPCell( new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType))))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; case SPEED_AND_BOULDERING: table = new PdfPTable(6); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum")))); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank())))); table.addCell( new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank())))); table.addCell(new PdfPCell( new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType))))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; case SPEED_AND_LEAD: table = new PdfPTable(6); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum")))); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank())))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank())))); table.addCell(new PdfPCell( new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType))))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; case COMBINED: table = new PdfPTable(7); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum")))); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank())))); table.addCell( new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank())))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank())))); table.addCell(new PdfPCell( new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType))))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; } // Alignment for (PdfPRow row : table.getRows()) { PdfPCell[] cells = row.getCells(); for (PdfPCell cellToAlign : cells) { cellToAlign.setHorizontalAlignment(Element.ALIGN_CENTER); cellToAlign.setVerticalAlignment(Element.ALIGN_CENTER); } } table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setHeaderRows(1); document.add(title); document.add(table); } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(RankingGenerator.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:cn.afterturn.easypoi.pdf.export.PdfExportServer.java
License:Apache License
private void createHeaderRow(PdfExportParams entity, PdfPTable table, int feildLength) { PdfPCell iCell = new PdfPCell(new Phrase(entity.getTitle(), styler.getFont(null, entity.getTitle()))); iCell.setHorizontalAlignment(Element.ALIGN_CENTER); iCell.setVerticalAlignment(Element.ALIGN_CENTER); iCell.setFixedHeight(entity.getTitleHeight()); iCell.setColspan(feildLength + 1);// w ww.j av a2s.c o m table.addCell(iCell); if (entity.getSecondTitle() != null) { iCell = new PdfPCell( new Phrase(entity.getSecondTitle(), styler.getFont(null, entity.getSecondTitle()))); iCell.setHorizontalAlignment(Element.ALIGN_RIGHT); iCell.setVerticalAlignment(Element.ALIGN_CENTER); iCell.setFixedHeight(entity.getSecondTitleHeight()); iCell.setColspan(feildLength + 1); table.addCell(iCell); } }
From source file:cn.afterturn.easypoi.pdf.export.PdfExportServer.java
License:Apache License
private PdfPCell createStringCell(PdfPTable table, String text, ExcelExportEntity entity, int rowHeight, int colspan, int rowspan) { PdfPCell iCell = new PdfPCell(new Phrase(text, styler.getFont(entity, text))); styler.setCellStyler(iCell, entity, text); iCell.setFixedHeight((int) (rowHeight * 2.5)); if (colspan > 1) { iCell.setColspan(colspan);/*from w w w .jav a 2 s . c o m*/ } if (rowspan > 1) { iCell.setRowspan(rowspan); } table.addCell(iCell); return iCell; }
From source file:cn.afterturn.easypoi.pdf.export.PdfExportServer.java
License:Apache License
private PdfPCell createStringCell(PdfPTable table, String text, ExcelExportEntity entity, int rowHeight) { PdfPCell iCell = new PdfPCell(new Phrase(text, styler.getFont(entity, text))); styler.setCellStyler(iCell, entity, text); iCell.setFixedHeight((int) (rowHeight * 2.5)); table.addCell(iCell); return iCell; }
From source file:cn.afterturn.easypoi.pdf.export.PdfExportServer.java
License:Apache License
private PdfPCell createImageCell(PdfPTable table, String text, ExcelExportEntity entity, int rowHeight, int rowSpan, int colSpan) { try {/*from w w w. ja va 2s . com*/ Image image = Image.getInstance(ImageCache.getImage(text)); PdfPCell iCell = new PdfPCell(image); styler.setCellStyler(iCell, entity, text); iCell.setFixedHeight((int) (rowHeight * 2.5)); table.addCell(iCell); return iCell; } catch (BadElementException e) { LOGGER.error(e.getMessage(), e); } catch (MalformedURLException e) { LOGGER.error(e.getMessage(), e); } catch (IOException e) { LOGGER.error(e.getMessage(), e); } return new PdfPCell(); }
From source file:Codigo.GenerarFactura.java
public void crearPdf(String nombreArchivo, String numeroFactura, String nombreCliente, String Nit, int strCant, String strPr, int strpreUni, int strTot) throws FileNotFoundException, DocumentException { Document documento = new Document(); FileOutputStream ficheroPdf = new FileOutputStream(nombreArchivo + ".pdf"); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(100); documento.addTitle("Primer PDF"); documento.open();// w w w. jav a 2s . c om String numFactura = "Factura N: " + numeroFactura; String fecha = ""; String Nombre = "Nombre: " + nombreCliente; String nit = "Nit/Ci: " + Nit; documento.add(new Paragraph(" IMPORTADORA TODO COMPRA", FontFactory.getFont("arial", 22, Font.ITALIC, BaseColor.DARK_GRAY))); documento .add(new Paragraph(numFactura, FontFactory.getFont("arial", 18, Font.ITALIC, BaseColor.DARK_GRAY))); documento.add(new Paragraph(" ")); documento.add(new Paragraph(Nombre + " " + nit, FontFactory.getFont("arial", 18, Font.ITALIC, BaseColor.DARK_GRAY))); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); PdfPTable tabla = new PdfPTable(4); tabla.addCell("CANTIDAD"); tabla.addCell("DESCRIPCION"); tabla.addCell("PRECIO UNITARIO"); tabla.addCell("TOTAL"); tabla.addCell("" + strCant); tabla.addCell(strPr); tabla.addCell("" + strpreUni); tabla.addCell("" + strTot); documento.add(tabla); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph("")); documento.close(); try { File path = new File(nombreArchivo + ".pdf"); Desktop.getDesktop().open(path); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:com.ainfosec.macresponse.report.PdfGenerator.java
License:Open Source License
private static void createDataSection(Paragraph paragraph, DisplayObject displayObject) { if (displayObject == null || displayObject.getObjects() == null) { return;/*from w w w . j a va 2 s. com*/ } // See if the DisplayObject has a list or a single object if (displayObject.getObjects().size() == 1) { TreeObject treeObject = displayObject.getObjects().get(0); // There's only 1 item // For each column, create/add a label with the title and the data int i = 0; for (String columnName : displayObject.getColumnNames()) { StringBuffer sb = new StringBuffer(); // Add the column title sb.append(displayObject.getColumnTitles()[i]); sb.append(": "); // Get the value of the field try { Field field = treeObject.getClass().getDeclaredField(columnName); String val = (String) field.get(treeObject); if (val == null) { val = ""; } // Add the value sb.append(val); sb.append("\n"); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Put the string into the paragraph paragraph.add(sb.toString()); i++; } } else { PdfPTable table = new PdfPTable(displayObject.getColumnTitles().length); table.setWidthPercentage(100); table.setHorizontalAlignment(Element.ALIGN_CENTER); for (String columnName : displayObject.getColumnTitles()) { table.getDefaultCell().setBackgroundColor(BaseColor.CYAN); table.addCell(columnName); table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); } for (TreeObject to1 : displayObject.getObjects()) { for (String columnName : displayObject.getColumnNames()) { try { Field field = to1.getClass().getDeclaredField(columnName); String val = (String) field.get(to1); if (val == null) { val = ""; } table.addCell(val); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } table.getDefaultCell().setColspan(displayObject.getColumnTitles().length); table.getDefaultCell().setBorder(SWT.NONE); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // TODO Paul number the tables table.addCell("Table: " + displayObject.getTitle()); paragraph.add(table); } }
From source file:com.algoboss.erp.util.report.PDFExporter.java
License:Apache License
protected void addColumnValue(PdfPTable pdfTable, UIComponent component, Font font) { String value = component == null ? "" : exportValue(FacesContext.getCurrentInstance(), component); pdfTable.addCell(new Paragraph(value, font)); }
From source file:com.algoboss.erp.util.report.PDFExporter.java
License:Apache License
protected void addColumnValue(PdfPTable pdfTable, UIComponent component, Font font, BaseColor bgColor) { String value = component == null ? "" : exportValue(FacesContext.getCurrentInstance(), component); PdfPCell cell = new PdfPCell(new Paragraph(value, font)); cell.setBackgroundColor(bgColor);/*from ww w. j a v a2s . c om*/ pdfTable.addCell(cell); }
From source file:com.algoboss.erp.util.report.PDFExporter.java
License:Apache License
protected void addColumnValue(PdfPTable pdfTable, List<UIComponent> components, Font font) { StringBuilder builder = new StringBuilder(); FacesContext context = FacesContext.getCurrentInstance(); for (UIComponent component : components) { if (component.isRendered()) { String value = exportValue(context, component); if (value != null) { builder.append(value);/*from w w w. j a v a 2 s .c o m*/ } } } pdfTable.addCell(new Paragraph(builder.toString(), font)); }