List of usage examples for com.lowagie.text.pdf PdfPCell setHorizontalAlignment
public void setHorizontalAlignment(int horizontalAlignment)
From source file:domain.reports.menu.PDFReportMenu.java
License:LGPL
/** * Return a report section formatted as a table * @param data//from w w w. j a v a 2 s .c o m * @return */ PdfPTable getGroupDetail(Recordset master, Recordset detail) throws Throwable { //cols PdfPTable datatable = new PdfPTable(2); //header datatable.getDefaultCell().setPadding(1); int headerwidths[] = { 50, 50 }; // percentage datatable.setWidths(headerwidths); datatable.setWidthPercentage(70); // percentage datatable.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell c = null; String v = ""; //encabezados de columnas c = new PdfPCell(new Phrase("ITEMS DEL MEN", tblHeaderFont)); c.setGrayFill(0.95f); c.setColspan(2); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Item del men", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Servicio", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); while (detail.next()) { v = detail.getString("description"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(c); v = detail.getString("path"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(c); } datatable.setSpacingBefore(20); return datatable; }
From source file:domain.reports.role.PDFReportRole.java
License:LGPL
/** * Return a report section formatted as a table * @param data/* w w w . j a v a2 s.co m*/ * @return */ PdfPTable getGroupDetail(Recordset master, Recordset detail) throws Throwable { //cols PdfPTable datatable = new PdfPTable(4); //header datatable.getDefaultCell().setPadding(1); int headerwidths[] = { 20, 20, 20, 20 }; // percentage datatable.setWidths(headerwidths); datatable.setWidthPercentage(100); // percentage datatable.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell c = null; String v = ""; //encabezados de columnas c = new PdfPCell(new Phrase("USUARIOS DEL ROL", tblHeaderFont)); c.setGrayFill(0.95f); c.setColspan(4); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Login de Usuario", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Apellido", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Nombre", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Email", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); while (detail.next()) { v = detail.getString("userlogin"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); v = detail.getString("lname"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); v = detail.getString("fname"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); v = detail.getString("email"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); } datatable.setSpacingBefore(20); return datatable; }
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 2s . 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 www . jav a2 s .co 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:ec.edu.uce.erp.web.common.util.CustomPDFExporter.java
protected void addHeaderValue(PdfPTable pdfTable, UIComponent component, Font font) { String value = component == null ? "" : exportValue(FacesContext.getCurrentInstance(), component); PdfPCell cell = new PdfPCell(new Paragraph(value, font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); pdfTable.addCell(cell);/*from w ww .j a v a 2 s. c om*/ }
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 {// www . j ava 2 s.com 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.InscriptionController.java
License:Apache License
private PdfPCell makeCellSignataire(String str, Font font) { PdfPCell cell = makeCell(str, font); cell.setHorizontalAlignment(Element.ALIGN_CENTER); return cell;//from ww w .jav a 2 s.co m }
From source file:geoportal.presentacion.beans.ReportesControlador.java
public void imprimirReporte() { //DateFormat dfDateFull = DateFormat.getDateInstance(DateFormat.FULL); try {//from w ww .ja v a 2 s. 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(); } }
From source file:gov.medicaid.services.impl.ExportServiceBean.java
License:Apache License
/** * Adds a centered cell to the given table. * //w w w .j a v a 2 s. c om * @param table * the table to add the cell to * @param value * the value text */ private static void addCenterCell(PdfPTable table, String value) { PdfPCell val = new PdfPCell( new Phrase(Util.defaultString(value), FontFactory.getFont(FontFactory.HELVETICA, 7))); val.setBorder(Rectangle.NO_BORDER); val.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(val); }
From source file:gov.medicaid.services.util.PDFHelper.java
License:Apache License
/** * Adds a cell to the given table./* w w w.j a va 2 s. c om*/ * * @param table the table to add the cell to * @param value the value text */ public static void addCell(PdfPTable table, String value) { PdfPCell val = new PdfPCell( new Phrase(": " + Util.defaultString(value), FontFactory.getFont(FontFactory.HELVETICA, 7))); val.setBorder(Rectangle.NO_BORDER); val.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); table.addCell(val); }