List of usage examples for com.itextpdf.text Element ALIGN_CENTER
int ALIGN_CENTER
To view the source code for com.itextpdf.text Element ALIGN_CENTER.
Click Source Link
From source file:Almacen.Reporte2.java
public void cabecera1(PDF reporte, BaseFont bf, PdfPTable tabla, String titulo1, int op) { Session session = HibernateUtil.getSessionFactory().openSession(); try {//www .j ava 2s .c o m reporte.contenido.setLineWidth(0.5f); reporte.contenido.setColorStroke(new GrayColor(0.2f)); reporte.contenido.setColorFill(new GrayColor(0.9f)); Configuracion con = (Configuracion) session.get(Configuracion.class, 1); reporte.inicioTexto(); reporte.contenido.setFontAndSize(bf, 14); reporte.contenido.setColorFill(BaseColor.BLACK); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, con.getEmpresa(), 35, 755, 0); reporte.contenido.setFontAndSize(bf, 8); reporte.contenido.setColorFill(BaseColor.BLACK); String titulo = titulo1; reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, titulo, 35, 745, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT, "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 570, 745, 0); reporte.finTexto(); //agregamos renglones vacios para dejar un espacio reporte.agregaObjeto(new Paragraph(" ")); Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD); BaseColor cabecera = BaseColor.GRAY; BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; for (int a = 0; a < tabla.getNumberOfColumns(); a++) { tabla.addCell(reporte.celda(t_datos2.getColumnName(a), font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); } } catch (Exception e) { System.out.println(e); } if (session != null) if (session.isOpen()) session.close(); }
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 www. j a v a2 s . 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:ara.Confirmsec.java
public void myfunction() throws IOException, DocumentException { String a = preres.getText();// ww w .j a v a 2 s. c o m File file = new File(DEST); file.getParentFile().mkdirs(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(DEST)); document.open(); Image image = Image.getInstance("logo.jpg"); document.add(image); Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD); Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL); Font small = FontFactory.getFont(FontFactory.HELVETICA, 5, Font.BOLD); String date = new Date().toString(); Paragraph paragraph1 = new Paragraph(date); Paragraph paragraph2 = new Paragraph("To Whom it May Concern", chapterFont); paragraph2.setAlignment(Element.ALIGN_CENTER); paragraph1.setAlignment(Element.ALIGN_RIGHT); paragraph2.setSpacingBefore(20f); paragraph2.setSpacingAfter(10f); Paragraph paragraph3 = new Paragraph(a, paragraphFont); paragraph3.setSpacingAfter(20f); Paragraph paragraph4 = new Paragraph("Registrar"); paragraph4.setAlignment(Element.ALIGN_RIGHT); paragraph4.setSpacingAfter(100f); Paragraph paragraph5 = new Paragraph( "This is a digitally signed document. Use Ref No. " + c + " to verify.", small); document.add(paragraph1); document.add(paragraph2); document.add(paragraph3); document.add(paragraph4); document.add(paragraph5); document.close(); JOptionPane.showMessageDialog(null, "Document Generated."); }
From source file:be.kcbj.placemat.Placemat.java
License:Open Source License
private PdfPCell generateCell(Sponsor sponsor, float cellHeight) throws IOException, BadElementException { int numLines = 0; Paragraph p = new Paragraph(); if (sponsor.image != null) { Image image = Image.getInstance(SponsorManager.getImageUrl(sponsor.image)); if (sponsor.imageWidth != 0) { image.scaleToFit(sponsor.imageWidth, 1000); } else if (sponsor.imageHeight != 0) { image.scaleToFit(1000, sponsor.imageHeight); }/* www . j a va 2s. co m*/ Chunk imageChunk = new Chunk(image, 0, 0, true); p.add(imageChunk); } if (sponsor.twoColumns) { StringBuilder sb = new StringBuilder(); if (sponsor.name != null) { sb.append(sponsor.name); } if (sponsor.name2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.name2); } if (sponsor.address != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address); } if (sponsor.address2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address2); } p.add(Chunk.NEWLINE); p.add(new Chunk(sb.toString(), new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))); numLines++; } else { if (sponsor.twoRows && sponsor.image != null) { p.add(Chunk.NEWLINE); } if (sponsor.name != null) { p.add(generateFittedChunk(sponsor.name, Font.BOLD)); numLines++; } if (sponsor.name2 != null) { p.add(Chunk.NEWLINE); p.add(generateFittedChunk(sponsor.name2, Font.BOLD)); numLines++; } if (sponsor.address != null) { p.add(new Chunk("\n\n", new Font(Font.FontFamily.HELVETICA, 2, Font.NORMAL))); p.add(new Chunk(sponsor.address, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } if (sponsor.address2 != null) { p.add(Chunk.NEWLINE); p.add(new Chunk(sponsor.address2, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } } p.setPaddingTop(0); p.setSpacingBefore(0); p.setAlignment(Element.ALIGN_CENTER); p.setMultipliedLeading(numLines <= 3 ? 1.3f : 1.1f); PdfPCell cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setFixedHeight(cellHeight); if (sponsor.twoColumns) { cell.setColspan(2); } if (sponsor.twoRows) { cell.setRowspan(2); if (sponsor.image == null) { p.setMultipliedLeading(p.getMultipliedLeading() * 1.5f); } } cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(CELL_EVENT); cell.setPaddingBottom(4); cell.addElement(p); if (sponsor.isTodo()) { cell.setBackgroundColor(BaseColor.ORANGE); } return cell; }
From source file:be.rheynaerde.poolsheets.AbstractPoolSheet.java
License:Open Source License
protected PdfPTable getBout(String player1, String player2) { PdfPTable table = new PdfPTable(2); table.setTotalWidth(configuration.getSquareCellSize() * 2); PdfPCell player1Name = new PdfPCell(new Phrase(player1)); player1Name.setBorder(Rectangle.BOTTOM); player1Name.setHorizontalAlignment(Element.ALIGN_CENTER); player1Name.setFixedHeight(configuration.getSquareCellSize()); PdfPCell player2Name = new PdfPCell(new Phrase(player2)); player2Name.setBorder(Rectangle.BOTTOM); player2Name.setHorizontalAlignment(Element.ALIGN_CENTER); player2Name.setFixedHeight(configuration.getSquareCellSize()); PdfPCell player1Score = new PdfPCell(new Phrase(" ")); player1Score.setBorder(Rectangle.RIGHT); player1Score.setFixedHeight(configuration.getSquareCellSize()); PdfPCell player2Score = new PdfPCell(new Phrase(" ")); player2Score.setBorder(Rectangle.LEFT); player2Score.setFixedHeight(configuration.getSquareCellSize()); table.addCell(player1Name);/* ww w . jav a 2 s . c o m*/ table.addCell(player2Name); table.addCell(player1Score); table.addCell(player2Score); table.setSpacingBefore(10); return table; }
From source file:be.rheynaerde.poolsheets.AbstractPoolSheet.java
License:Open Source License
protected PdfPCell getHeaderCell(String text) { PdfPCell headerCell = new PdfPCell(new Phrase(text, configuration.getHeaderFont())); headerCell.setHorizontalAlignment(Element.ALIGN_CENTER); headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); headerCell.setFixedHeight(configuration.getSquareCellSize()); return headerCell; }
From source file:be.rheynaerde.poolsheets.AbstractPufPoolSheet.java
License:Open Source License
protected PdfPCell getNameCell(String text) { PdfPCell nameCell = text == null ? new PdfPCell() : new PdfPCell(new Phrase(text)); nameCell.setBorder(Rectangle.BOTTOM); nameCell.setHorizontalAlignment(Element.ALIGN_CENTER); nameCell.setVerticalAlignment(Element.ALIGN_MIDDLE); nameCell.setFixedHeight(configuration.getSquareCellSize()); return nameCell; }
From source file:be.rheynaerde.poolsheets.ClubPoolSheet.java
License:Open Source License
@Override protected void buildTable(Document document) throws DocumentException { int columnCount = configuration.getNrOfPlayers() + configuration.getSummaryColumnCount() + 3; int nameCellWidth = 5; PdfPTable table = new PdfPTable(columnCount); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setTotalWidth(//from w ww . ja v a 2 s. c om (configuration.getNrOfPlayers() + 1 + nameCellWidth + 0.1f + configuration.getSummaryColumnCount()) * configuration.getSquareCellSize()); table.setLockedWidth(true); float[] widths = new float[columnCount]; widths[0] = 1f * nameCellWidth; for (int i = 1; i < widths.length; i++) { widths[i] = 1f; } widths[widths.length - 1 - configuration.getSummaryColumnCount()] = 0.1f; table.setWidths(widths); PdfPCell cell = new PdfPCell(new Paragraph(configuration.getTitle(), configuration.getTitleFont())); cell.setColspan(columnCount); cell.setPaddingBottom(configuration.getSquareCellSize() / 2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); { table.addCell(getHeaderCell(bundle.getString("name"))); table.addCell(getSolidCell()); for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); } table.addCell(new PdfPCell()); //spacer column for (int i = 0; i < configuration.getSummaryColumnCount(); i++) { table.addCell(getHeaderCell(configuration.getSummaryColumnName(i))); } } for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(configuration.getNamePlayer(i + 1) == null ? "" : configuration.getNamePlayer(i + 1)); table.addCell(getHeaderCell(Integer.toString(i + 1))); for (int j = 0; j < i; j++) { String result = configuration.getResult(i + 1, j + 1); PdfPCell resultCell = new PdfPCell(new Phrase(result == null ? "" : result)); resultCell.setHorizontalAlignment(Element.ALIGN_CENTER); resultCell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(resultCell); } table.addCell(getSolidCell()); for (int j = i + 1; j < configuration.getNrOfPlayers(); j++) { String result = configuration.getResult(i + 1, j + 1); PdfPCell resultCell = new PdfPCell(new Phrase(result == null ? "" : result)); resultCell.setHorizontalAlignment(Element.ALIGN_CENTER); resultCell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(resultCell); } table.addCell(new PdfPCell()); //spacer column for (int j = 0; j < configuration.getSummaryColumnCount(); j++) { String result = configuration.getSummaryColumnValue(i + 1, j); PdfPCell summaryCell = new PdfPCell(new Phrase(result == null ? "" : result)); summaryCell.setHorizontalAlignment(Element.ALIGN_CENTER); summaryCell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(summaryCell); } } document.add(table); }
From source file:be.rheynaerde.poolsheets.StandardPoolSheet.java
License:Open Source License
protected void buildTable(Document document) throws DocumentException { int columnCount = 1 + 1 + configuration.getNrOfPlayers() + 1 + configuration.getSummaryColumnCount(); // name + number + scores + spacer // + summary PdfPTable table = new PdfPTable(columnCount); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setTotalWidth((configuration.getNrOfPlayers() + 7 //the name column + extra space between grid and summary //currently the name column just gets a width that is //a multiple of the width of the other cells. Better //would be to let this cell take up the remaining space. + configuration.getSummaryColumnCount()) * configuration.getSquareCellSize()); table.setLockedWidth(true);//from w w w .ja va 2 s . com float[] widths = new float[columnCount]; widths[0] = 5f; for (int i = 1; i < widths.length; i++) { widths[i] = 1f; } widths[widths.length - 1 - configuration.getSummaryColumnCount()] = 0.1f; table.setWidths(widths); { table.addCell(getHeaderCell(bundle.getString("name"))); table.addCell(getSolidCell()); for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); } table.addCell(new PdfPCell()); //spacer column for (int i = 0; i < configuration.getSummaryColumnCount(); i++) { table.addCell(getHeaderCell(configuration.getSummaryColumnName(i))); } } for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(configuration.getNamePlayer(i + 1) == null ? "" : configuration.getNamePlayer(i + 1)); table.addCell(getHeaderCell(Integer.toString(i + 1))); for (int j = 0; j < i; j++) { String result = configuration.getResult(i + 1, j + 1); PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } table.addCell(getSolidCell()); for (int j = i + 1; j < configuration.getNrOfPlayers(); j++) { String result = configuration.getResult(i + 1, j + 1); PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } table.addCell(new PdfPCell()); //spacer column for (int j = 0; j < configuration.getSummaryColumnCount(); j++) { String result = configuration.getSummaryColumnValue(i + 1, j); PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } } document.add(table); }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private byte[] createModelPages(Contact contact, List<Model> models, Toc tableOfContents) throws IOException, DocumentException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Document document = iTextUtil.createNewDocument(); PdfWriter writer = PdfWriter.getInstance(document, bos); document.open();// www . ja v a2s .c om // create a PdfPTable for every model (so we can measure the height) final List<PdfPTable> modelPageTables = new ArrayList<>(); Collections.sort(models); for (Model model : models) { if (model != null) { modelPageTables.add(createModelPage(contact, model, writer)); } } // put the PdfPTable Models tables on PDF pages (multiple per page if possible) byte[] pages = new byte[] {}; int height = 0; List<String> pageNames = new ArrayList<>(); int i = 0; for (PdfPTable modelPageTable : modelPageTables) { // create a new pdf page, if necessary if (height != 0 && (height + modelPageTable.getTotalHeight() + 20 /* for the line separator */ ) >= iTextUtil.PAGE_HEIGHT) { writer.close(); document.close(); bos.close(); byte[] page = bos.toByteArray(); tableOfContents.addEntries(2, pageNames, page, true, Toc.MODEL_SORT_PREFIX + "___" + IntUtil.format(++i)); pages = iTextUtil.merge(pages, page); height = 0; pageNames.clear(); bos = new ByteArrayOutputStream(); document = iTextUtil.createNewDocument(); writer = PdfWriter.getInstance(document, bos); document.open(); } else if (height != 0) { // if not the first model on the page, draw a separator document.add(new Paragraph( new Chunk(new LineSeparator(.25f, 80f, BaseColor.LIGHT_GRAY, Element.ALIGN_CENTER, -2)))); document.add(new Paragraph(new Chunk(" "))); } // rerender the table (with a valid pdfWriter) document.add(createModelPage(contact, models.get(modelPageTables.indexOf(modelPageTable)), writer)); height += modelPageTable.getTotalHeight(); pageNames.add(models.get(modelPageTables.indexOf(modelPageTable)).getProductNameProcessed()); } writer.close(); document.close(); byte[] page = bos.toByteArray(); tableOfContents.addEntries(2, pageNames, page, true, Toc.MODEL_SORT_PREFIX + "___" + IntUtil.format(++i)); pages = iTextUtil.merge(pages, page); return pages; }