List of usage examples for com.lowagie.text.pdf PdfPCell setBackgroundColor
public void setBackgroundColor(Color backgroundColor)
From source file:com.slamd.report.PDFReportGenerator.java
License:Open Source License
/** * Performs the appropriate action necessary when starting a new page. In * this case, we will write the SLAMD header to the top of the page. * * @param writer The writer used to write the PDF document. * @param document The PDF document being written. *//* ww w .j a va2s .c om*/ public void onStartPage(PdfWriter writer, Document document) { try { PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); PdfPCell blueCell = new PdfPCell(new Phrase(" \n ")); blueCell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); blueCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); blueCell.setBackgroundColor(new Color(0x59, 0x4F, 0xBF)); blueCell.setBorderWidth(inchesToPoints(1.0 / 16)); blueCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF)); blueCell.setPadding(inchesToPoints(1.0 / 16)); table.addCell(blueCell); Phrase titlePhrase = new Phrase("SLAMD Generated Report", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0x59, 0x4F, 0xBF))); PdfPCell yellowCell = new PdfPCell(titlePhrase); yellowCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); yellowCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); yellowCell.setBackgroundColor(new Color(0xFB, 0xE2, 0x49)); yellowCell.setBorderWidth(inchesToPoints(1.0 / 16)); yellowCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF)); yellowCell.setPadding(inchesToPoints(1.0 / 16)); table.addCell(yellowCell); Phrase versionPhrase = new Phrase("Version " + DynamicConstants.SLAMD_VERSION, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0xFF, 0xFF, 0xFF))); PdfPCell redCell = new PdfPCell(versionPhrase); redCell.setHorizontalAlignment(Cell.ALIGN_RIGHT); redCell.setVerticalAlignment(Cell.ALIGN_MIDDLE); redCell.setBackgroundColor(new Color(0xD1, 0x21, 0x24)); redCell.setBorderWidth(inchesToPoints(1.0 / 16)); redCell.setBorderColor(new Color(0xFF, 0xFF, 0xFF)); redCell.setPadding(inchesToPoints(1.0 / 16)); table.addCell(redCell); document.add(table); } catch (Exception e) { e.printStackTrace(); } }
From source file:Cotizacion.ExportarPDF.java
private static void acomodarDatosTablaProductos(Paragraph subCatPart) throws BadElementException { numeroFilas = LogicaCotizacion.numero; cantidadTabla = new String[numeroFilas]; productoTabla = new String[numeroFilas]; precioTabla = new String[numeroFilas]; totalTabla = new String[numeroFilas]; descripcionTabla = new String[numeroFilas]; PdfPTable tabla = new PdfPTable(5); tabla.setWidthPercentage(100);//from ww w . java 2 s . co m PdfPCell celda = new PdfPCell(new Paragraph("Producto")); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBackgroundColor(new Color(0, 175, 239)); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Descripcin")); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBackgroundColor(new Color(0, 175, 239)); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("P/U")); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBackgroundColor(new Color(0, 175, 239)); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Cantidad")); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBackgroundColor(new Color(0, 175, 239)); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Total")); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBackgroundColor(new Color(0, 175, 239)); tabla.addCell(celda); for (int i = 0; i < numeroFilas; i++) { productoTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 0); tabla.addCell(" " + productoTabla[i]); descripcionTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 1); tabla.addCell("" + descripcionTabla[i]); precioTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 2); tabla.addCell("$ " + precioTabla[i]); cantidadTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 3); tabla.addCell(" " + cantidadTabla[i]); totalTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 4); tabla.addCell("$ " + totalTabla[i]); } agregarLineasEnBlanco(subCatPart, 1); subCatPart.add(tabla); }
From source file:de.jdufner.sudoku.generator.pdf.PdfCellHandler.java
License:Open Source License
private void formatZelle(final int zeile, final int spalte, final PdfPCell cell) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorderColor(new Color(// Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.red")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.green")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.blue")))); if (isEvenBlockIndex(zeile, spalte)) { cell.setBackgroundColor(new Color(// Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.red")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.green")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.blue")))); } else {//from w ww. ja v a2 s . co m cell.setBackgroundColor(new Color(// Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.red")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.green")), // Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.blue")))); } cell.setBorderWidth(PdfConstants.RAHMEN_DUENN); if (BoxUtils.isFirstRowInBlock(zeile, getSudokuSize())) { cell.setBorderWidthTop(PdfConstants.RAHMEN_DICK); } else { cell.setBorderWidthTop(PdfConstants.RAHMEN_DUENN); } if (BoxUtils.isLastColumnInRow(spalte, getSudokuSize())) { cell.setBorderWidthRight(PdfConstants.RAHMEN_DICK); } else { cell.setBorderWidthRight(PdfConstants.RAHMEN_DUENN); } if (BoxUtils.isLastRowInColumn(zeile, getSudokuSize())) { cell.setBorderWidthBottom(PdfConstants.RAHMEN_DICK); } else { cell.setBorderWidthBottom(PdfConstants.RAHMEN_DUENN); } if (BoxUtils.isFirstColumnInBlock(spalte, getSudokuSize())) { cell.setBorderWidthLeft(PdfConstants.RAHMEN_DICK); } else { cell.setBorderWidthLeft(PdfConstants.RAHMEN_DUENN); } cell.setFixedHeight(27f); }
From source file:ec.edu.chyc.manejopersonal.managebean.PDFCustomExporter.java
License:Apache License
protected void tableColumnGroup(PdfPTable pdfTable, DataTable table, String facetType) { ColumnGroup cg = table.getColumnGroup(facetType); List<UIComponent> headerComponentList = null; if (cg != null) { headerComponentList = cg.getChildren(); }//from w ww.j a va 2 s . c om if (headerComponentList != null) { for (UIComponent component : headerComponentList) { if (component instanceof Row) { Row row = (Row) component; for (UIComponent rowComponent : row.getChildren()) { UIColumn column = (UIColumn) rowComponent; String value = null; if (column.isRendered() && column.isExportable()) { if (facetType.equalsIgnoreCase("header")) { value = column.getHeaderText(); } else { value = column.getFooterText(); } int rowSpan = column.getRowspan(); int colSpan = column.getColspan(); PdfPCell cell = new PdfPCell(new Paragraph(value, this.facetFont)); if (facetBackground != null) { cell.setBackgroundColor(facetBackground); } if (rowSpan > 1) { cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setRowspan(rowSpan); } if (colSpan > 1) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(colSpan); } // addColumnAlignments(component,cell); if (facetType.equalsIgnoreCase("header")) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); } pdfTable.addCell(cell); } } } } } pdfTable.completeRow(); }
From source file:ec.edu.chyc.manejopersonal.managebean.PDFCustomExporter.java
License:Apache License
protected void tableColumnGroup(PdfPTable pdfTable, SubTable table, String facetType) { ColumnGroup cg = table.getColumnGroup(facetType); List<UIComponent> headerComponentList = null; if (cg != null) { headerComponentList = cg.getChildren(); }//from w w w . j a va 2 s . c o m if (headerComponentList != null) { for (UIComponent component : headerComponentList) { if (component instanceof Row) { Row row = (Row) component; for (UIComponent rowComponent : row.getChildren()) { UIColumn column = (UIColumn) rowComponent; String value = null; if (facetType.equalsIgnoreCase("header")) { value = column.getHeaderText(); } else { value = column.getFooterText(); } int rowSpan = column.getRowspan(); int colSpan = column.getColspan(); PdfPCell cell = new PdfPCell(new Paragraph(value, this.facetFont)); if (facetBackground != null) { cell.setBackgroundColor(facetBackground); } if (rowSpan > 1) { cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setRowspan(rowSpan); } if (colSpan > 1) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(colSpan); } // addColumnAlignments(component,cell); if (facetType.equalsIgnoreCase("header")) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); } pdfTable.addCell(cell); } } } } pdfTable.completeRow(); }
From source file:fr.opensagres.xdocreport.itext.extension.SimpleTable.java
License:Open Source License
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10); try {//from www .j a va2 s . c om PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("SimpleTable.pdf")); document.open(); PdfPTable table = new PdfPTable(2); PdfPCell cell; Paragraph p = new Paragraph("Text Text Text "); table.addCell("cell"); table.addCell(p); table.addCell("cell"); cell = new PdfPCell(p); p = new Paragraph("Text Text Text "); //Chunk c = new Chunk( "zzzzzzzzzz" ); //cell.setPadding( 0f ); //cell.getColumn().setAdjustFirstLine( false ); // make a room for borders //cell.setUseBorderPadding( false ); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(Color.red); cell.addElement(p); cell.setUseAscender(true); //cell.addElement(c ); // cell.setPaddingTop( 0f ); // cell.setPaddingLeft( 20f ); table.addCell(cell); //table.addCell( "cell" ); document.add(table); } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:fr.univlorraine.mondossierweb.controllers.CalendrierController.java
License:Apache License
/** * //from ww w.j a v a 2 s. c o m * @param document pdf */ public void creerPdfCalendrier(final Document document, Etudiant etudiant) { //configuration des fonts Font normal = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL); Font normalbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLD); Font legerita = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.ITALIC); Font headerbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD); Font header = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD); //pieds de pages: Date d = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); String date = dateFormat.format(d); //alignement des libells du pied de page: String partie1 = applicationContext.getMessage("pdf.calendrier.title", null, Locale.getDefault()); String partie2 = applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : " + date; if (partie1.length() < ECARTEMENT_PIED_PAGE_PDF) { int diff = ECARTEMENT_PIED_PAGE_PDF - partie1.length(); for (int i = 0; i < diff; i++) { partie1 = partie1 + " "; } } if (partie2.length() < ECARTEMENT_PIED_PAGE_PDF) { int diff = ECARTEMENT_PIED_PAGE_PDF - partie2.length(); for (int i = 0; i < diff; i++) { partie2 = " " + partie2; } } //cration du pied de page: Phrase phra = new Phrase( partie1 + " -" + applicationContext.getMessage("pdf.page", null, Locale.getDefault()), legerita); Phrase phra2 = new Phrase("- " + partie2, legerita); HeaderFooter hf = new HeaderFooter(phra, phra2); hf.setAlignment(HeaderFooter.ALIGN_CENTER); document.setFooter(hf); //ouverte du document. document.open(); try { //ajout image test if (configController.getLogoUniversitePdf() != null && !configController.getLogoUniversitePdf().equals("")) { Image image1 = Image.getInstance(configController.getLogoUniversitePdf()); float scaleRatio = 40 / image1.getHeight(); float newWidth = scaleRatio * image1.getWidth(); image1.scaleAbsolute(newWidth, 40); image1.setAbsolutePosition(800 - newWidth, 528); document.add(image1); } //nouveau paragraphe Paragraph p = new Paragraph( applicationContext.getMessage("pdf.calendrier.title", null, Locale.getDefault()).toUpperCase() + "\n\n", headerbig); p.setIndentationLeft(15); document.add(p); if (etudiant.getNom() != null) { Paragraph p0 = new Paragraph(etudiant.getNom(), normal); p0.setIndentationLeft(15); document.add(p0); } if (etudiant.getCod_etu() != null) { Paragraph p01 = new Paragraph(applicationContext.getMessage("pdf.folder", null, Locale.getDefault()) + " : " + etudiant.getCod_etu(), normal); p01.setIndentationLeft(15); document.add(p01); } if (etudiant.getCod_nne() != null) { Paragraph p02 = new Paragraph(applicationContext.getMessage("pdf.nne", null, Locale.getDefault()) + " : " + etudiant.getCod_nne(), normal); p02.setIndentationLeft(15); document.add(p02); } if (etudiant.getEmail() != null) { Paragraph p03 = new Paragraph(applicationContext.getMessage("pdf.mail", null, Locale.getDefault()) + " : " + etudiant.getEmail(), normal); p03.setIndentationLeft(15); document.add(p03); } Paragraph p03 = new Paragraph( applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : " + date, normal); p03.setIndentationLeft(15); document.add(p03); document.add(new Paragraph("\n")); //Partie Calendrier PdfPTable table = new PdfPTable(1); table.setWidthPercentage(98); PdfPCell cell = new PdfPCell(new Paragraph(applicationContext .getMessage("pdf.calendrier.subtitle", null, Locale.getDefault()).toUpperCase() + " ", header)); cell.setBorder(Rectangle.NO_BORDER); cell.setBackgroundColor(new Color(153, 153, 255)); table.addCell(cell); PdfPTable table2; boolean affNumPlaceExamen = configController.isAffNumPlaceExamen(); if (affNumPlaceExamen) { table2 = new PdfPTable(7); table2.setWidthPercentage(98); int[] tabWidth = { 15, 10, 10, 40, 30, 10, 60 }; table2.setWidths(tabWidth); } else { table2 = new PdfPTable(6); table2.setWidthPercentage(98); int[] tabWidth = { 15, 10, 10, 45, 30, 65 }; table2.setWidths(tabWidth); } Paragraph p1 = new Paragraph(applicationContext.getMessage("pdf.date", null, Locale.getDefault()), normalbig); Paragraph p2 = new Paragraph(applicationContext.getMessage("pdf.heure", null, Locale.getDefault()), normalbig); Paragraph p3 = new Paragraph(applicationContext.getMessage("pdf.duree", null, Locale.getDefault()), normalbig); Paragraph p4 = new Paragraph(applicationContext.getMessage("pdf.batiment", null, Locale.getDefault()), normalbig); Paragraph p5 = new Paragraph(applicationContext.getMessage("pdf.salle", null, Locale.getDefault()), normalbig); Paragraph p6 = new Paragraph(applicationContext.getMessage("pdf.place", null, Locale.getDefault()), normalbig); Paragraph p7 = new Paragraph(applicationContext.getMessage("pdf.examen", null, Locale.getDefault()), normalbig); PdfPCell ct1 = new PdfPCell(p1); PdfPCell ct2 = new PdfPCell(p2); PdfPCell ct3 = new PdfPCell(p3); PdfPCell ct4 = new PdfPCell(p4); PdfPCell ct5 = new PdfPCell(p5); PdfPCell ct6 = new PdfPCell(p6); PdfPCell ct7 = new PdfPCell(p7); ct1.setBorder(Rectangle.BOTTOM); ct1.setBorderColorBottom(Color.black); ct2.setBorder(Rectangle.BOTTOM); ct2.setBorderColorBottom(Color.black); ct3.setBorder(Rectangle.BOTTOM); ct2.setBorderColorBottom(Color.black); ct4.setBorder(Rectangle.BOTTOM); ct1.setBorderColorBottom(Color.black); ct5.setBorder(Rectangle.BOTTOM); ct2.setBorderColorBottom(Color.black); ct6.setBorder(Rectangle.BOTTOM); ct2.setBorderColorBottom(Color.black); ct7.setBorder(Rectangle.BOTTOM); ct2.setBorderColorBottom(Color.black); table2.addCell(ct1); table2.addCell(ct2); table2.addCell(ct3); table2.addCell(ct4); table2.addCell(ct5); if (affNumPlaceExamen) table2.addCell(ct6); table2.addCell(ct7); for (int i = 0; i < etudiant.getCalendrier().size(); i++) { Paragraph pa = new Paragraph(etudiant.getCalendrier().get(i).getDatedeb(), normal); PdfPCell celltext = new PdfPCell(pa); celltext.setBorder(Rectangle.NO_BORDER); Paragraph pa2 = new Paragraph(etudiant.getCalendrier().get(i).getHeure(), normal); PdfPCell celltext2 = new PdfPCell(pa2); celltext2.setBorder(Rectangle.NO_BORDER); Paragraph pa3 = new Paragraph(etudiant.getCalendrier().get(i).getDuree(), normal); PdfPCell celltext3 = new PdfPCell(pa3); celltext3.setBorder(Rectangle.NO_BORDER); Paragraph pa4 = new Paragraph(etudiant.getCalendrier().get(i).getBatiment(), normal); PdfPCell celltext4 = new PdfPCell(pa4); celltext4.setBorder(Rectangle.NO_BORDER); Paragraph pa5 = new Paragraph(etudiant.getCalendrier().get(i).getSalle(), normal); PdfPCell celltext5 = new PdfPCell(pa5); celltext5.setBorder(Rectangle.NO_BORDER); Paragraph pa6 = new Paragraph(etudiant.getCalendrier().get(i).getPlace(), normal); PdfPCell celltext6 = new PdfPCell(pa6); celltext6.setBorder(Rectangle.NO_BORDER); Paragraph pa7 = new Paragraph(etudiant.getCalendrier().get(i).getEpreuve(), normal); PdfPCell celltext7 = new PdfPCell(pa7); celltext7.setBorder(Rectangle.NO_BORDER); table2.addCell(celltext); table2.addCell(celltext2); table2.addCell(celltext3); table2.addCell(celltext4); table2.addCell(celltext5); if (affNumPlaceExamen) table2.addCell(celltext6); table2.addCell(celltext7); /*PdfPCell celltext4 = new PdfPCell(table3); celltext4.setBorder(Rectangle.NO_BORDER); table2.addCell(celltext4);*/ } document.add(table); document.add(table2); document.add(new Paragraph("\n")); } catch (BadElementException e) { LOG.error("Erreur la gnration du calendrier des examens : BadElementException ", e); } catch (MalformedURLException e) { LOG.error("Erreur la gnration du calendrier des examens : MalformedURLException ", e); } catch (IOException e) { LOG.error("Erreur la gnration du calendrier des examens : IOException ", e); } catch (DocumentException e) { LOG.error("Erreur la gnration du calendrier des examens : DocumentException ", e); } // step 6: fermeture du document. document.close(); }
From source file:fr.univlorraine.mondossierweb.controllers.NoteController.java
License:Apache License
/** * //from w w w . j a v a2 s . co m * @param document pdf */ public void creerPdfResume(final Document document, Etudiant etudiant) { //configuration des fonts Font normal = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL); Font normalbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLD); Font legerita = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.ITALIC); Font headerbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD); Font header = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD); //pieds de pages: Date d = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); String date = dateFormat.format(d); //alignement des libell du pied de page: String partie1 = applicationContext.getMessage("pdf.notes.title", null, Locale.getDefault()); String partie2 = applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : " + date; if (partie1.length() < ECARTEMENT_PIED_PAGE_PDF) { int diff = ECARTEMENT_PIED_PAGE_PDF - partie1.length(); for (int i = 0; i < diff; i++) { partie1 = partie1 + " "; } } if (partie2.length() < ECARTEMENT_PIED_PAGE_PDF) { int diff = ECARTEMENT_PIED_PAGE_PDF - partie2.length(); for (int i = 0; i < diff; i++) { partie2 = " " + partie2; } } //creation du pied de page: Phrase phra = new Phrase( partie1 + " -" + applicationContext.getMessage("pdf.page", null, Locale.getDefault()), legerita); Phrase phra2 = new Phrase("- " + partie2, legerita); HeaderFooter hf = new HeaderFooter(phra, phra2); hf.setAlignment(HeaderFooter.ALIGN_CENTER); document.setFooter(hf); //ouverte du document. document.open(); try { //ajout image test if (configController.getLogoUniversitePdf() != null && !configController.getLogoUniversitePdf().equals("")) { Image image1 = Image.getInstance(configController.getLogoUniversitePdf()); float scaleRatio = 40 / image1.getHeight(); float newWidth = scaleRatio * image1.getWidth(); image1.scaleAbsolute(newWidth, 40); image1.setAbsolutePosition(800 - newWidth, 528); document.add(image1); } boolean affMentionEtudiant = configController.isAffMentionEtudiant(); //nouveau paragraphe Paragraph p = new Paragraph(applicationContext.getMessage("pdf.notes.title", null, Locale.getDefault()) .toUpperCase(Locale.getDefault()) + "\n\n", headerbig); p.setIndentationLeft(15); document.add(p); if (etudiant.getNom() != null) { Paragraph p0 = new Paragraph(etudiant.getNom(), normal); p0.setIndentationLeft(15); document.add(p0); } if (etudiant.getCod_etu() != null) { Paragraph p01 = new Paragraph(applicationContext.getMessage("pdf.folder", null, Locale.getDefault()) + " : " + etudiant.getCod_etu(), normal); p01.setIndentationLeft(15); document.add(p01); } if (etudiant.getCod_nne() != null) { Paragraph p02 = new Paragraph(applicationContext.getMessage("pdf.nne", null, Locale.getDefault()) + " : " + etudiant.getCod_nne(), normal); p02.setIndentationLeft(15); document.add(p02); } if (etudiant.getEmail() != null) { Paragraph p03 = new Paragraph(applicationContext.getMessage("pdf.mail", null, Locale.getDefault()) + " : " + etudiant.getEmail(), normal); p03.setIndentationLeft(15); document.add(p03); } Paragraph p03 = new Paragraph( applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : " + date, normal); p03.setIndentationLeft(15); document.add(p03); document.add(new Paragraph("\n")); //Partie DIPLOMES PdfPTable table = new PdfPTable(1); table.setWidthPercentage(98); PdfPCell cell = new PdfPCell( new Paragraph(applicationContext.getMessage("pdf.diplomes", null, Locale.getDefault()) .toUpperCase(Locale.getDefault()) + " ", header)); cell.setBorder(Rectangle.NO_BORDER); cell.setBackgroundColor(new Color(153, 153, 255)); table.addCell(cell); PdfPTable table2; //if(!config.isAffRangEtudiant()){ if (!etudiant.isAfficherRang()) { table2 = new PdfPTable(4); } else { table2 = new PdfPTable(5); } table2.setWidthPercentage(98); int tailleColonneLib = 110; if (affMentionEtudiant) tailleColonneLib = 90; //if(!config.isAffRangEtudiant()){ if (!etudiant.isAfficherRang()) { int[] tabWidth = { 26, 35, tailleColonneLib, 70 }; table2.setWidths(tabWidth); } else { int[] tabWidth = { 26, 35, tailleColonneLib - 5, 70, 15 }; table2.setWidths(tabWidth); } Paragraph p1 = new Paragraph(applicationContext.getMessage("pdf.year", null, Locale.getDefault()), normalbig); Paragraph p2 = new Paragraph(applicationContext.getMessage("pdf.code.vers", null, Locale.getDefault()), normalbig); Paragraph p3 = new Paragraph(applicationContext.getMessage("pdf.diplome", null, Locale.getDefault()), normalbig); PdfPCell ct1 = new PdfPCell(p1); PdfPCell ct2 = new PdfPCell(p2); PdfPCell ct3 = new PdfPCell(p3); ct1.setBorder(Rectangle.BOTTOM); ct1.setBorderColorBottom(Color.black); ct2.setBorder(Rectangle.BOTTOM); ct2.setBorderColorBottom(Color.black); ct3.setBorder(Rectangle.BOTTOM); ct3.setBorderColorBottom(Color.black); table2.addCell(ct1); table2.addCell(ct2); table2.addCell(ct3); PdfPTable table21; if (!affMentionEtudiant) { table21 = new PdfPTable(3); int[] tabWidth21 = { 25, 20, 25 }; table21.setWidths(tabWidth21); } else { table21 = new PdfPTable(4); int[] tabWidth21 = { 25, 20, 25, 20 }; table21.setWidths(tabWidth21); } PdfPCell ct4 = new PdfPCell(new Paragraph( applicationContext.getMessage("pdf.session", null, Locale.getDefault()), normalbig)); PdfPCell ct5 = new PdfPCell( new Paragraph(applicationContext.getMessage("pdf.note", null, Locale.getDefault()), normalbig)); PdfPCell ct6 = new PdfPCell(new Paragraph( applicationContext.getMessage("pdf.resultat", null, Locale.getDefault()), normalbig)); PdfPCell ctmention = new PdfPCell(new Paragraph( applicationContext.getMessage("pdf.mention", null, Locale.getDefault()), normalbig)); ct4.setBorder(Rectangle.BOTTOM); ct4.setBorderColorBottom(Color.black); ct5.setBorder(Rectangle.BOTTOM); ct5.setBorderColorBottom(Color.black); ct6.setBorder(Rectangle.BOTTOM); ct6.setBorderColorBottom(Color.black); ctmention.setBorder(Rectangle.BOTTOM); ctmention.setBorderColorBottom(Color.black); table21.addCell(ct4); table21.addCell(ct5); table21.addCell(ct6); if (affMentionEtudiant) { table21.addCell(ctmention); } PdfPCell ct7 = new PdfPCell(table21); ct7.setBorder(Rectangle.BOTTOM); table2.addCell(ct7); PdfPCell ctrang = new PdfPCell( new Paragraph(applicationContext.getMessage("pdf.rank", null, Locale.getDefault()), normalbig)); ctrang.setBorder(Rectangle.BOTTOM); ctrang.setBorderColorBottom(Color.black); //if(config.isAffRangEtudiant()){ if (etudiant.isAfficherRang()) { table2.addCell(ctrang); } for (int i = 0; i < etudiant.getDiplomes().size(); i++) { Paragraph pa = new Paragraph(etudiant.getDiplomes().get(i).getAnnee(), normal); PdfPCell celltext = new PdfPCell(pa); celltext.setBorder(Rectangle.NO_BORDER); Paragraph pa2 = new Paragraph(etudiant.getDiplomes().get(i).getCod_dip() + "/" + etudiant.getDiplomes().get(i).getCod_vrs_vdi(), normal); PdfPCell celltext2 = new PdfPCell(pa2); celltext2.setBorder(Rectangle.NO_BORDER); Paragraph pa3 = new Paragraph(etudiant.getDiplomes().get(i).getLib_web_vdi(), normal); PdfPCell celltext3 = new PdfPCell(pa3); celltext3.setBorder(Rectangle.NO_BORDER); Paragraph parang = new Paragraph(etudiant.getDiplomes().get(i).getRang(), normal); PdfPCell cellrang = new PdfPCell(parang); cellrang.setBorder(Rectangle.NO_BORDER); PdfPCell cellvide = new PdfPCell(); cellvide.setBorder(Rectangle.NO_BORDER); table2.addCell(celltext); table2.addCell(celltext2); table2.addCell(celltext3); PdfPTable table3; if (!affMentionEtudiant) { table3 = new PdfPTable(3); int[] tabWidth2 = { 25, 20, 25 }; table3.setWidths(tabWidth2); } else { table3 = new PdfPTable(4); int[] tabWidth2 = { 25, 20, 25, 8 }; table3.setWidths(tabWidth2); } int j = 0; List<Resultat> lres = etudiant.getDiplomes().get(i).getResultats(); while (j < lres.size()) { Paragraph pa5 = new Paragraph(lres.get(j).getSession(), normal); PdfPCell celltext5 = new PdfPCell(pa5); celltext5.setBorder(Rectangle.NO_BORDER); table3.addCell(celltext5); if (lres.get(j).getNote() != null) { Paragraph pa6 = new Paragraph(lres.get(j).getNote().toString(), normal); PdfPCell celltext6 = new PdfPCell(pa6); celltext6.setBorder(Rectangle.NO_BORDER); table3.addCell(celltext6); } else { Paragraph pa6 = new Paragraph("", normal); PdfPCell celltext6 = new PdfPCell(pa6); celltext6.setBorder(Rectangle.NO_BORDER); table3.addCell(celltext6); } Paragraph pa7 = new Paragraph(lres.get(j).getAdmission(), normal); PdfPCell celltext7 = new PdfPCell(pa7); celltext7.setBorder(Rectangle.NO_BORDER); table3.addCell(celltext7); if (affMentionEtudiant) { Paragraph pa8 = new Paragraph(lres.get(j).getCodMention(), normal); PdfPCell celltext8 = new PdfPCell(pa8); celltext8.setBorder(Rectangle.NO_BORDER); table3.addCell(celltext8); } j++; } PdfPCell celltext4 = new PdfPCell(table3); celltext4.setBorder(Rectangle.NO_BORDER); table2.addCell(celltext4); //if(config.isAffRangEtudiant()){ if (etudiant.getDiplomes().get(i).isAfficherRang()) { table2.addCell(cellrang); } else { //On insere une cellule vide si on affiche pas ce rang, alors que la colonne rang fait partie de la table if (etudiant.isAfficherRang()) { table2.addCell(cellvide); } } } document.add(table); document.add(table2); document.add(new Paragraph("\n")); //Partie ETAPES PdfPTable tabletape = new PdfPTable(1); tabletape.setWidthPercentage(98); PdfPCell celletape = new PdfPCell(new Paragraph(applicationContext .getMessage("pdf.etapes", null, Locale.getDefault()).toUpperCase(Locale.getDefault()), header)); celletape.setBorder(Rectangle.NO_BORDER); celletape.setBackgroundColor(new Color(153, 153, 255)); tabletape.addCell(celletape); PdfPTable tabletape2; //if(!config.isAffRangEtudiant()){ if (!etudiant.isAfficherRang()) { tabletape2 = new PdfPTable(4); tabletape2.setWidthPercentage(98); int[] tabWidthetape = { 26, 35, tailleColonneLib, 70 }; tabletape2.setWidths(tabWidthetape); } else { tabletape2 = new PdfPTable(5); tabletape2.setWidthPercentage(98); int[] tabWidthetape = { 26, 35, tailleColonneLib - 5, 70, 15 }; tabletape2.setWidths(tabWidthetape); } PdfPCell ct3etape = new PdfPCell(new Paragraph( applicationContext.getMessage("pdf.etape", null, Locale.getDefault()), normalbig)); ct3etape.setBorder(Rectangle.BOTTOM); ct3etape.setBorderColorBottom(Color.black); tabletape2.addCell(ct1); tabletape2.addCell(ct2); tabletape2.addCell(ct3etape); tabletape2.addCell(ct7); //if(!config.isAffRangEtudiant()){ if (etudiant.isAfficherRang()) { tabletape2.addCell(ctrang); } for (int i = 0; i < etudiant.getEtapes().size(); i++) { Paragraph pa = new Paragraph(etudiant.getEtapes().get(i).getAnnee(), normal); PdfPCell celltext = new PdfPCell(pa); celltext.setBorder(Rectangle.NO_BORDER); tabletape2.addCell(celltext); Paragraph pa2 = new Paragraph( etudiant.getEtapes().get(i).getCode() + "/" + etudiant.getEtapes().get(i).getVersion(), normal); PdfPCell celltext2 = new PdfPCell(pa2); celltext2.setBorder(Rectangle.NO_BORDER); tabletape2.addCell(celltext2); Paragraph pa3 = new Paragraph(etudiant.getEtapes().get(i).getLibelle(), normal); PdfPCell celltext3 = new PdfPCell(pa3); celltext3.setBorder(Rectangle.NO_BORDER); tabletape2.addCell(celltext3); Paragraph parEtapeRang = new Paragraph(etudiant.getEtapes().get(i).getRang(), normal); PdfPCell cellEtapeRang = new PdfPCell(parEtapeRang); cellEtapeRang.setBorder(Rectangle.NO_BORDER); PdfPCell cellvide = new PdfPCell(); cellvide.setBorder(Rectangle.NO_BORDER); PdfPTable table3; if (!affMentionEtudiant) { table3 = new PdfPTable(3); int[] tabWidth2 = { 25, 20, 25 }; table3.setWidths(tabWidth2); } else { table3 = new PdfPTable(4); int[] tabWidth2 = { 25, 20, 25, 8 }; table3.setWidths(tabWidth2); } int j = 0; List<Resultat> lres = etudiant.getEtapes().get(i).getResultats(); while (j < lres.size()) { Paragraph pa5 = new Paragraph(lres.get(j).getSession(), normal); PdfPCell celltext5 = new PdfPCell(pa5); celltext5.setBorder(Rectangle.NO_BORDER); table3.addCell(celltext5); if (lres.get(j).getNote() != null) { Paragraph pa6 = new Paragraph(lres.get(j).getNote().toString(), normal); PdfPCell celltext6 = new PdfPCell(pa6); celltext6.setBorder(Rectangle.NO_BORDER); table3.addCell(celltext6); } else { Paragraph pa6 = new Paragraph("", normal); PdfPCell celltext6 = new PdfPCell(pa6); celltext6.setBorder(Rectangle.NO_BORDER); table3.addCell(celltext6); } Paragraph pa7 = new Paragraph(lres.get(j).getAdmission(), normal); PdfPCell celltext7 = new PdfPCell(pa7); celltext7.setBorder(Rectangle.NO_BORDER); table3.addCell(celltext7); if (affMentionEtudiant) { Paragraph pa8 = new Paragraph(lres.get(j).getCodMention(), normal); PdfPCell celltext8 = new PdfPCell(pa8); celltext8.setBorder(Rectangle.NO_BORDER); table3.addCell(celltext8); } j++; } PdfPCell celltext4 = new PdfPCell(table3); celltext4.setBorder(Rectangle.NO_BORDER); tabletape2.addCell(celltext4); //if(config.isAffRangEtudiant()){ if (etudiant.getEtapes().get(i).isAfficherRang()) { tabletape2.addCell(cellEtapeRang); } else { if (etudiant.isAfficherRang()) { tabletape2.addCell(cellvide); } } } document.add(tabletape); document.add(tabletape2); document.add(new Paragraph("\n")); //Partie Informations if (etudiant.isSignificationResultatsUtilisee()) { PdfPTable tablequestions = new PdfPTable(1); tablequestions.setWidthPercentage(98); PdfPCell cellquestions = new PdfPCell(new Paragraph( applicationContext.getMessage("pdf.questions", null, Locale.getDefault()) + " ", header)); cellquestions.setBorder(Rectangle.NO_BORDER); cellquestions.setBackgroundColor(new Color(153, 153, 255)); tablequestions.addCell(cellquestions); String grilleSignficationResultats = ""; Set<String> ss = etudiant.getSignificationResultats().keySet(); for (String k : ss) { if (k != null && !k.equals("") && !k.equals(" ")) { grilleSignficationResultats = grilleSignficationResultats + k + " : " + etudiant.getSignificationResultats().get(k); grilleSignficationResultats = grilleSignficationResultats + " "; } } PdfPTable tablequestions2 = new PdfPTable(1); tablequestions2.setWidthPercentage(98); PdfPCell cellquestions2 = new PdfPCell(new Paragraph( applicationContext.getMessage("pdf.code.resultat.signification", null, Locale.getDefault()) + " : \n" + grilleSignficationResultats, normal)); cellquestions2.setBorder(Rectangle.NO_BORDER); tablequestions2.addCell(cellquestions2); document.add(tablequestions); document.add(tablequestions2); } } catch (BadElementException e) { LOG.error("Erreur la gnration du rsum des notes : BadElementException ", e); } catch (MalformedURLException e) { LOG.error("Erreur la gnration du rsum des notes : MalformedURLException ", e); } catch (IOException e) { LOG.error("Erreur la gnration du rsum des notes : IOException ", e); } catch (DocumentException e) { LOG.error("Erreur la gnration du rsum des notes : DocumentException ", e); } // step 6: fermeture du document. document.close(); }
From source file:fr.univlorraine.mondossierweb.controllers.NoteController.java
License:Apache License
/** * /*from w w w . ja v a2s. c o m*/ * @param document pdf */ public void creerPdfDetail(final Document document, Etudiant etudiant, Etape etape) { //configuration des fonts Font normal = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL); Font normalbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLD); Font legerita = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.ITALIC); Font headerbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD); Font header = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD); //pieds de pages: Date d = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); String date = dateFormat.format(d); //alignement des libells du pied de page: String partie1 = applicationContext.getMessage("pdf.notes.detail", null, Locale.getDefault()); String partie2 = applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : " + date; if (partie1.length() < ECARTEMENT_PIED_PAGE_PDF) { int diff = ECARTEMENT_PIED_PAGE_PDF - partie1.length(); for (int i = 0; i < diff; i++) { partie1 = partie1 + " "; } } if (partie2.length() < ECARTEMENT_PIED_PAGE_PDF) { int diff = ECARTEMENT_PIED_PAGE_PDF - partie2.length(); for (int i = 0; i < diff; i++) { partie2 = " " + partie2; } } //creation du pied de page: Phrase phra = new Phrase( partie1 + " -" + applicationContext.getMessage("pdf.page", null, Locale.getDefault()), legerita); Phrase phra2 = new Phrase("- " + partie2, legerita); HeaderFooter hf = new HeaderFooter(phra, phra2); hf.setAlignment(HeaderFooter.ALIGN_CENTER); document.setFooter(hf); document.setFooter(hf); //ouverte du document. document.open(); try { //ajout image test if (configController.getLogoUniversitePdf() != null && !configController.getLogoUniversitePdf().equals("")) { Image image1 = Image.getInstance(configController.getLogoUniversitePdf()); float scaleRatio = 40 / image1.getHeight(); float newWidth = scaleRatio * image1.getWidth(); image1.scaleAbsolute(newWidth, 40); image1.setAbsolutePosition(800 - newWidth, 528); document.add(image1); } //nouveau paragraphe Paragraph p = new Paragraph(applicationContext.getMessage("pdf.notes.title", null, Locale.getDefault()) .toUpperCase(Locale.getDefault()) + "\n\n", headerbig); p.setIndentationLeft(15); document.add(p); if (etudiant.getNom() != null) { Paragraph p0 = new Paragraph(etudiant.getNom(), normal); p0.setIndentationLeft(15); document.add(p0); } if (etudiant.getCod_etu() != null) { Paragraph p01 = new Paragraph(applicationContext.getMessage("pdf.folder", null, Locale.getDefault()) + " : " + etudiant.getCod_etu(), normal); p01.setIndentationLeft(15); document.add(p01); } if (etudiant.getCod_nne() != null) { Paragraph p02 = new Paragraph(applicationContext.getMessage("pdf.nne", null, Locale.getDefault()) + " : " + etudiant.getCod_nne(), normal); p02.setIndentationLeft(15); document.add(p02); } if (etudiant.getEmail() != null) { Paragraph p03 = new Paragraph(applicationContext.getMessage("pdf.mail", null, Locale.getDefault()) + " : " + etudiant.getEmail(), normal); p03.setIndentationLeft(15); document.add(p03); } Paragraph p03 = new Paragraph( applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : " + date, normal); p03.setIndentationLeft(15); document.add(p03); document.add(new Paragraph("\n")); //Partie des notes PdfPTable table = new PdfPTable(1); table.setWidthPercentage(98); //PdfPCell cell = new PdfPCell(new Paragraph(applicationContext.getMessage("pdf.elements.epreuves", null, Locale.getDefault()).toUpperCase(Locale.getDefault()) + " - "+applicationContext.getMessage("pdf.annee.universitaire", null, Locale.getDefault()) + " : " + etape.getAnnee(), header)); PdfPCell cell = new PdfPCell(new Paragraph(etape.getLibelle() + " - " + applicationContext.getMessage("pdf.annee.universitaire", null, Locale.getDefault()) + " : " + etape.getAnnee(), header)); cell.setBorder(Rectangle.NO_BORDER); cell.setBackgroundColor(new Color(153, 153, 255)); table.addCell(cell); PdfPTable table2; boolean afficherRangElpEpr = etudiantController.isAfficherRangElpEpr(); boolean affRangEtudiant = configController.isAffRangEtudiant(); boolean affECTSEtudiant = configController.isAffECTSEtudiant(); if ((!affRangEtudiant && !afficherRangElpEpr) && !affECTSEtudiant) { //NI isAffRangEtudiant NI isAffECTSEtudiant table2 = new PdfPTable(6); table2.setWidthPercentage(98); int[] tabWidth = { 35, 110, 25, 25, 25, 25 }; table2.setWidths(tabWidth); } else { if (((affRangEtudiant || afficherRangElpEpr) && !affECTSEtudiant) || ((!affRangEtudiant && !afficherRangElpEpr) && affECTSEtudiant)) { //isAffRangEtudiant OU isAffECTSEtudiant table2 = new PdfPTable(7); table2.setWidthPercentage(98); int[] tabWidth = { 33, 110, 22, 22, 22, 22, 15 }; table2.setWidths(tabWidth); } else { //isAffRangEtudiant ET isAffECTSEtudiant table2 = new PdfPTable(8); table2.setWidthPercentage(98); int[] tabWidth = { 33, 110, 22, 22, 22, 22, 15, 15 }; table2.setWidths(tabWidth); } } //Paragraph p1 = new Paragraph(applicationContext.getMessage("pdf.year", null, Locale.getDefault()),normalbig); Paragraph p2 = new Paragraph(applicationContext.getMessage("pdf.code", null, Locale.getDefault()), normalbig); Paragraph p3 = new Paragraph(applicationContext.getMessage("pdf.label", null, Locale.getDefault()), normalbig); Paragraph parRang = new Paragraph(applicationContext.getMessage("pdf.rank", null, Locale.getDefault()), normalbig); Paragraph parEcts = new Paragraph(applicationContext.getMessage("pdf.ects", null, Locale.getDefault()), normalbig); PdfPCell ct4 = new PdfPCell(new Paragraph( applicationContext.getMessage("pdf.session", null, Locale.getDefault()) + " 1", normalbig)); PdfPCell ct5 = new PdfPCell(new Paragraph( applicationContext.getMessage("pdf.resultat", null, Locale.getDefault()), normalbig)); PdfPCell ct6 = new PdfPCell(new Paragraph( applicationContext.getMessage("pdf.session", null, Locale.getDefault()) + " 2", normalbig)); PdfPCell ct7 = new PdfPCell(new Paragraph( applicationContext.getMessage("pdf.resultat", null, Locale.getDefault()), normalbig)); //PdfPCell ct1 = new PdfPCell(p1); PdfPCell ct2 = new PdfPCell(p2); PdfPCell ct3 = new PdfPCell(p3); PdfPCell cellRang = new PdfPCell(parRang); PdfPCell cellEcts = new PdfPCell(parEcts); //ct1.setBorder(Rectangle.BOTTOM); ct1.setBorderColorBottom(Color.black); ct2.setBorder(Rectangle.BOTTOM); ct2.setBorderColorBottom(Color.black); ct3.setBorder(Rectangle.BOTTOM); ct3.setBorderColorBottom(Color.black); ct4.setBorder(Rectangle.BOTTOM); ct4.setBorderColorBottom(Color.black); ct5.setBorder(Rectangle.BOTTOM); ct5.setBorderColorBottom(Color.black); ct6.setBorder(Rectangle.BOTTOM); ct6.setBorderColorBottom(Color.black); ct7.setBorder(Rectangle.BOTTOM); ct7.setBorderColorBottom(Color.black); cellRang.setBorder(Rectangle.BOTTOM); cellRang.setBorderColorBottom(Color.black); cellEcts.setBorder(Rectangle.BOTTOM); cellEcts.setBorderColorBottom(Color.black); //table2.addCell(ct1); table2.addCell(ct2); table2.addCell(ct3); table2.addCell(ct4); table2.addCell(ct5); table2.addCell(ct6); table2.addCell(ct7); if ((affRangEtudiant || afficherRangElpEpr)) { table2.addCell(cellRang); } if (affRangEtudiant) { table2.addCell(cellEcts); } for (int i = 0; i < etudiant.getElementsPedagogiques().size(); i++) { /*String annee = etudiant.getElementsPedagogiques().get(i).getAnnee().replaceAll(applicationContext.getMessage("pdf.replace.ficm", null, Locale.getDefault()), ""); Paragraph pa = new Paragraph(annee, normal); PdfPCell celltext = new PdfPCell(pa); celltext.setBorder(Rectangle.NO_BORDER); table2.addCell(celltext);*/ Paragraph pa2 = new Paragraph(etudiant.getElementsPedagogiques().get(i).getCode(), normal); PdfPCell celltext2 = new PdfPCell(pa2); celltext2.setBorder(Rectangle.NO_BORDER); table2.addCell(celltext2); String indentation = ""; for (int j = 0; j < etudiant.getElementsPedagogiques().get(i).getLevel(); j++) { indentation = indentation + " "; } Paragraph pa3 = new Paragraph(indentation + etudiant.getElementsPedagogiques().get(i).getLibelle(), normal); PdfPCell celltext3 = new PdfPCell(pa3); celltext3.setBorder(Rectangle.NO_BORDER); table2.addCell(celltext3); Paragraph pa5 = new Paragraph(getNote1(etudiant.getElementsPedagogiques().get(i)), normal); PdfPCell celltext5 = new PdfPCell(pa5); celltext5.setBorder(Rectangle.NO_BORDER); table2.addCell(celltext5); Paragraph pa6 = new Paragraph(etudiant.getElementsPedagogiques().get(i).getRes1(), normal); PdfPCell celltext6 = new PdfPCell(pa6); celltext6.setBorder(Rectangle.NO_BORDER); table2.addCell(celltext6); Paragraph pa7 = new Paragraph(getNote2(etudiant.getElementsPedagogiques().get(i)), normal); PdfPCell celltext7 = new PdfPCell(pa7); celltext7.setBorder(Rectangle.NO_BORDER); table2.addCell(celltext7); Paragraph pa8 = new Paragraph(etudiant.getElementsPedagogiques().get(i).getRes2(), normal); PdfPCell celltext8 = new PdfPCell(pa8); celltext8.setBorder(Rectangle.NO_BORDER); table2.addCell(celltext8); if ((affRangEtudiant || afficherRangElpEpr)) { Paragraph parRang2 = new Paragraph(etudiant.getElementsPedagogiques().get(i).getRang(), normal); PdfPCell cellRang2 = new PdfPCell(parRang2); cellRang2.setBorder(Rectangle.NO_BORDER); table2.addCell(cellRang2); } if (affECTSEtudiant) { Paragraph parEcts2 = new Paragraph(etudiant.getElementsPedagogiques().get(i).getEcts(), normal); PdfPCell cellEcts2 = new PdfPCell(parEcts2); cellEcts2.setBorder(Rectangle.NO_BORDER); table2.addCell(cellEcts2); } } document.add(table); document.add(table2); document.add(new Paragraph("\n")); //Partie QUESTIONS if (etudiant.isSignificationResultatsUtilisee()) { PdfPTable tablequestions = new PdfPTable(1); tablequestions.setWidthPercentage(98); PdfPCell cellquestions = new PdfPCell( new Paragraph(applicationContext.getMessage("pdf.questions", null, Locale.getDefault()) .toUpperCase(Locale.getDefault()) + " ", header)); cellquestions.setBorder(Rectangle.NO_BORDER); cellquestions.setBackgroundColor(new Color(153, 153, 255)); tablequestions.addCell(cellquestions); PdfPTable tablequestions2 = new PdfPTable(1); tablequestions2.setWidthPercentage(98); String grilleSignficationResultats = ""; Set<String> ss = etudiant.getSignificationResultats().keySet(); for (String k : ss) { if (k != null && !k.equals("") && !k.equals(" ")) { grilleSignficationResultats = grilleSignficationResultats + k + " : " + etudiant.getSignificationResultats().get(k); grilleSignficationResultats = grilleSignficationResultats + " "; } } PdfPCell cellquestions2 = new PdfPCell(new Paragraph( applicationContext.getMessage("pdf.code.resultat.signification", null, Locale.getDefault()) + " : \n" + grilleSignficationResultats, normal)); cellquestions2.setBorder(Rectangle.NO_BORDER); tablequestions2.addCell(cellquestions2); document.add(tablequestions); document.add(tablequestions2); } } catch (BadElementException e) { LOG.error("Erreur la gnration du detail des notes : BadElementException ", e); } catch (MalformedURLException e) { LOG.error("Erreur la gnration du detail des notes : MalformedURLException ", e); } catch (IOException e) { LOG.error("Erreur la gnration du detail des notes : IOException ", e); } catch (DocumentException e) { LOG.error("Erreur la gnration du detail des notes : DocumentException ", e); } // step 6: fermeture du document. document.close(); }
From source file:geoportal.presentacion.beans.ReportesControlador.java
public void imprimirReporte() { //DateFormat dfDateFull = DateFormat.getDateInstance(DateFormat.FULL); try {//from w w w .ja va 2s. c o m //Generamos el archivo PDF String directorioArchivos; ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); directorioArchivos = ctx.getRealPath("/") + "reportes"; String name = directorioArchivos + "/document-reporte.pdf"; Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(name)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(name)); //PdfWriter writer = PdfWriter.getInstance(document, //new FileOutputStream("C:")); Paragraph paragraph = new Paragraph(); Paragraph paragraph1 = new Paragraph(); Paragraph paragraph2 = new Paragraph(); //PdfPTable table = new PdfPTable(4); PdfPTable table1 = new PdfPTable(1); PdfPTable table2 = new PdfPTable(4); PdfPTable table3 = new PdfPTable(4); PdfPTable table5 = new PdfPTable(1); paragraph.add("\n\n\n\n\n\n\n"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); paragraph1.add("\n"); paragraph1.setAlignment(Paragraph.ALIGN_CENTER); paragraph2.add("Total Denuncias:" + totalDenuncias); paragraph2.setAlignment(Paragraph.ALIGN_LEFT); // Obtenemos una instancia de nuestro manejador de eventos MembreteHeaderiText header = new MembreteHeaderiText(); //Asignamos el manejador de eventos al escritor. writer.setPageEvent(header); document.open(); // Chunk titulo = new Chunk(CHUNK, FontFactory.getFont(FontFactory.COURIER, 20, Font.UNDERLINE, BaseColor.BLACK)); // // titulo = new Chunk(IMAGE, FontFactory.getFont(FontFactory.COURIER, 20, Font.UNDERLINE, BaseColor.BLACK)); // document.add(titulo); // Image foto = Image.getInstance(resources / ferrari.jpg?); //foto.scaleToFit(100, 100); foto.setAlignment(Chunk.ALIGN_MIDDLE); //primera linea PdfPCell cell5 = new PdfPCell(new Paragraph("VIOLENCIA INTRAFAMILIAR ")); //segunda linea PdfPCell cell12 = new PdfPCell(new Paragraph("AO")); PdfPCell cell6 = new PdfPCell(new Paragraph("2010")); PdfPCell cell7 = new PdfPCell(new Paragraph("2011")); PdfPCell cell8 = new PdfPCell(new Paragraph("2012")); //tercera fila PdfPCell cell13 = new PdfPCell(new Paragraph("# DENUNCIAS")); PdfPCell cell9 = new PdfPCell(new Paragraph("" + lstVif2010.size())); PdfPCell cell10 = new PdfPCell(new Paragraph("" + lstVif2011.size())); PdfPCell cell11 = new PdfPCell(new Paragraph("" + lstVif_2012.size())); PdfPCell cell15 = new PdfPCell(new Paragraph("TOTAL DENUNCIAS:" + totalDenuncias)); cell5.setHorizontalAlignment(Element.ALIGN_CENTER); cell6.setHorizontalAlignment(Element.ALIGN_CENTER); cell7.setHorizontalAlignment(Element.ALIGN_CENTER); cell8.setHorizontalAlignment(Element.ALIGN_CENTER); cell9.setHorizontalAlignment(Element.ALIGN_CENTER); cell10.setHorizontalAlignment(Element.ALIGN_CENTER); cell11.setHorizontalAlignment(Element.ALIGN_CENTER); cell12.setHorizontalAlignment(Element.ALIGN_CENTER); cell13.setHorizontalAlignment(Element.ALIGN_CENTER); cell15.setHorizontalAlignment(Element.ALIGN_LEFT); cell12.setBackgroundColor(Color.cyan); cell13.setBackgroundColor(Color.cyan); cell5.setBorder(Rectangle.NO_BORDER); cell15.setBorder(Rectangle.NO_BORDER); table1.addCell(cell5); //aadir segunda fila table2.addCell(cell12); table2.addCell(cell6); table2.addCell(cell7); table2.addCell(cell8); //aadir tercera fila table3.addCell(cell13); table3.addCell(cell9); table3.addCell(cell10); table3.addCell(cell11); //aadir cuarta fila table5.addCell(cell15); document.add(paragraph); document.add(table1); document.add(paragraph1); document.add(table2); document.add(table3); document.add(table5); //document.add(paragraph2); //document.add(table); //document.setFooter(event); document.close(); //---------------------------- //Abrimos el archivo PDF FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.setContentType("application/pdf"); response.setHeader("Content-disposition", "inline=filename=" + name); try { response.getOutputStream().write(Util.getBytesFromFile(new File(name))); response.getOutputStream().flush(); response.getOutputStream().close(); context.responseComplete(); } catch (IOException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }