List of usage examples for com.itextpdf.text.pdf PdfPCell setHorizontalAlignment
public void setHorizontalAlignment(int horizontalAlignment)
From source file:es.clinica.veterinaria.facturas.FacturaPdf.java
public PdfPTable createTable() throws DocumentException { // a table with three columns int iva = 0, iva2 = 0; DecimalFormat df = new DecimalFormat("0.00"); PdfPTable table = new PdfPTable(6); table.setTotalWidth(new float[] { 50, 65, 150, 150, 65, 70 }); table.setLockedWidth(true);// w ww. j av a2 s . c o m // the cell object // we add a cell with colspan 3 PdfPCell cell = new PdfPCell(new Phrase("CANT.")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("FECHA")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("CONCEPTO")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("DESCRIPCIN")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("PRECIO")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("IMPORTE")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingTop(5); cell.setPaddingBottom(5); table.addCell(cell); HashSet<Venta> ventas = this.getFactura().getVentas(); for (Venta venta : ventas) { HashSet<VentaLinea> listVenta = venta.getVenta_lineas(); for (VentaLinea vlinea : listVenta) { if (vlinea.getTipo() == 1) { if (vlinea.getProducto().getIva() != null) { iva2 = vlinea.getProducto().getIva().getValor(); // System.out.println("IVA: " +iva2); } } else if (vlinea.getTipo() == 2) { if (vlinea.getServicio().getIva() != null) { iva2 = vlinea.getServicio().getIva().getValor(); // System.out.println("IVA: " +iva2); } } //Para hacer el calculo nos vamos a quedar con el IVA mayor if (iva < iva2) { iva = iva2; } cell = new PdfPCell(new Phrase(vlinea.getCantidad() + "", small)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell( new Phrase(new SimpleDateFormat("dd-MM-yyyy").format(vlinea.getFecha()), small)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPaddingBottom(5); table.addCell(cell); if (vlinea.getTipo() == 2) { //Servicio table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small))); String descripcion = vlinea.getDescripcion(); if (descripcion == null || "null".equals(descripcion)) { table.addCell(new PdfPCell(new Phrase(" ", small))); // System.out.println("null:" + descripcion); } else { table.addCell(new PdfPCell(new Phrase(descripcion, small))); // System.out.println("!null:" + descripcion); } } else if (vlinea.getTipo() == 1) { //Producto //Si el producto es Tratamiento if (vlinea.getProducto().getFamilia().isTratamiento()) { table.addCell(new PdfPCell(new Phrase("Tratamiento", small))); table.addCell(new PdfPCell(new Phrase("", small))); } else { table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small))); String descripcion = vlinea.getDescripcion(); if (descripcion == null || "null".equals(descripcion)) { table.addCell(new PdfPCell(new Phrase(" ", small))); // System.out.println("null:" + descripcion); } else { table.addCell(new PdfPCell(new Phrase(descripcion, small))); // System.out.println("!null:" + descripcion); } } } cell = new PdfPCell(new Phrase(df.format(vlinea.getPvp()) + " ", small)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(df.format(vlinea.getPreciototalNoIVA()) + " ", small)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); } } cell = new PdfPCell(new Phrase(" ")); cell.setColspan(1); cell.setBorderWidthBottom(0); cell.setBorderWidthLeft(0); cell.setBorder(0); cell.setBorderColorLeft(BaseColor.WHITE); cell.setBorderColorBottom(BaseColor.WHITE); cell.setPaddingBottom(5); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(new Phrase("SUMA")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(df.format(factura.getCoste()) + " ", smallBold)); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); /* IVA */ cell = new PdfPCell(new Phrase(" ")); cell.setColspan(1); cell.setBorderWidthBottom(0); cell.setBorderWidthLeft(0); cell.setBorder(0); cell.setBorderColorLeft(BaseColor.WHITE); cell.setBorderColorBottom(BaseColor.WHITE); cell.setPaddingBottom(5); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); float costetotal = (float) (factura.getCostetotal()); cell = new PdfPCell(new Phrase("IVA " + iva + "%")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(df.format(factura.getIvas()) + " ", smallBold)); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); /* COSTE TOTAL */ cell = new PdfPCell(new Phrase(" ")); cell.setColspan(1); cell.setBorderWidthBottom(0); cell.setBorderWidthLeft(0); cell.setBorder(0); cell.setBorderColorLeft(BaseColor.WHITE); cell.setBorderColorBottom(BaseColor.WHITE); cell.setPaddingBottom(5); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(new Phrase("TOTAL")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(df.format(costetotal) + " ", smallBold)); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); return table; }
From source file:es.sm2.openppm.front.utils.DocumentUtils.java
License:Open Source License
/** * //from w ww .j a v a 2 s . c o m * @param content * @param font * @param borderTop * @param borderRight * @param borderBottom * @param borderLeft * @return */ private static PdfPCell prepareHeaderCell(String content, Font font, Float borderTop, Float borderRight, Float borderBottom, Float borderLeft) { PdfPCell cell = new PdfPCell(new Paragraph(content, font)); cell.setBorderWidthTop(borderTop); cell.setBorderWidthRight(borderRight); cell.setBorderWidthBottom(borderBottom); cell.setBorderWidthLeft(borderLeft); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setPaddingLeft(5F); return cell; }
From source file:es.sm2.openppm.front.utils.DocumentUtils.java
License:Open Source License
/** * /*w w w . j a v a 2 s .c o m*/ * @param content * @param font * @param borderTop * @param borderRight * @param borderBottom * @param borderLeft * @return */ private static PdfPCell prepareCell(String content, Font font, Float borderTop, Float borderRight, Float borderBottom, Float borderLeft) { PdfPCell cell = new PdfPCell(new Paragraph(content, font)); cell.setBorderWidthTop(borderTop); cell.setBorderWidthRight(borderRight); cell.setBorderWidthBottom(borderBottom); cell.setBorderWidthLeft(borderLeft); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setPaddingBottom(3F); cell.setPaddingLeft(5F); return cell; }
From source file:es.sm2.openppm.front.utils.DocumentUtils.java
License:Open Source License
/** * /*from w ww. j a v a2s. c o m*/ * @param content * @param font * @return */ private static PdfPCell prepareSubCell(String content, Font font) { PdfPCell cell = new PdfPCell(new Paragraph(content, font)); cell.setBorderWidth(0F); cell.setHorizontalAlignment(Element.ALIGN_LEFT); return cell; }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java
License:Open Source License
protected void addTableCaption(PdfPTable table, String caption) { PdfPCell cell = getContentCell();// w w w . jav a2s . c o m cell.setColspan(table.getNumberOfColumns()); table.addCell(cell); PdfPCell captionCell = new PdfPCell(new Phrase(caption, TABLE_CAPTION)); captionCell.setHorizontalAlignment(Element.ALIGN_CENTER); captionCell.setPaddingBottom(5); captionCell.setBorder(Rectangle.TOP); captionCell.setBorderWidthTop(1.5f); captionCell.setPaddingBottom(7); captionCell.setPaddingTop(2); captionCell.setColspan(table.getNumberOfColumns()); table.addCell(captionCell); }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java
License:Open Source License
protected PdfPCell getHeaderCell(String[] header) { Phrase p = new Phrase(); p.setFont(TABLE_HEADER);//w w w . j a v a2s .co m for (String s : header) { p.add(new Chunk(s)); p.add(Chunk.NEWLINE); } PdfPCell cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP); cell.setBorderWidthTop(1.5f); cell.setBorderWidthBottom(1.5f); cell.setPaddingBottom(7); cell.setPaddingTop(2); return cell; }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java
License:Open Source License
protected PdfPCell getContentCell() { PdfPCell cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingBottom(5);/*from w w w .jav a 2 s . c o m*/ cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP); return cell; }
From source file:eu.geopaparazzi.plugins.pdfexport.PdfExportDialogFragment.java
License:Open Source License
public void processNote(Document document, Note note, int count) throws Exception { String name = Utilities.makeXmlSafe(note.getName()); String form = note.getForm(); DaoImages daoImages = new DaoImages(); if (form != null && form.length() > 0) { JSONObject sectionObject = new JSONObject(form); if (!sectionObject.has(FormUtilities.ATTR_SECTIONNAME)) { return; }//from w w w . j a va 2 s . co m String sectionName = sectionObject.getString(FormUtilities.ATTR_SECTIONNAME); Anchor anchor = new Anchor(sectionName); anchor.setName(sectionName); Chapter currentChapter = new Chapter(new Paragraph(anchor), count); addEmptyLine(currentChapter, 3); PdfPTable infoTable = new PdfPTable(2); infoTable.setHeaderRows(0); infoTable.setWidthPercentage(90); currentChapter.add(infoTable); addKeyValueToTableRow(infoTable, "Timestamp", new Date(note.getTimeStamp()).toString()); addKeyValueToTableRow(infoTable, "Latitude", note.getLat() + ""); addKeyValueToTableRow(infoTable, "Longitude", note.getLon() + ""); addEmptyLine(currentChapter, 3); List<String> formsNames = TagsManager.getFormNames4Section(sectionObject); for (String formName : formsNames) { Paragraph section = new Paragraph(formName); currentChapter.addSection(section); addEmptyLine(currentChapter, 3); PdfPTable currentTable = new PdfPTable(2); currentTable.setHeaderRows(1); currentTable.setWidthPercentage(90); currentChapter.add(currentTable); JSONObject form4Name = TagsManager.getForm4Name(formName, sectionObject); JSONArray formItems = TagsManager.getFormItems(form4Name); for (int i = 0; i < formItems.length(); i++) { JSONObject formItem = formItems.getJSONObject(i); if (!formItem.has(FormUtilities.TAG_KEY)) { continue; } String type = formItem.getString(FormUtilities.TAG_TYPE); String key = formItem.getString(FormUtilities.TAG_KEY); String value = formItem.getString(FormUtilities.TAG_VALUE); String label = key; if (formItem.has(FormUtilities.TAG_LABEL)) { label = formItem.getString(FormUtilities.TAG_LABEL); } if (type.equals(FormUtilities.TYPE_PICTURES)) { if (value.trim().length() == 0) { continue; } String[] imageIdsSplit = value.split(Note.IMAGES_SEPARATOR); for (String imageId : imageIdsSplit) { Image image = daoImages.getImage(Long.parseLong(imageId)); String imgName = image.getName(); byte[] imageData = daoImages.getImageData(Long.parseLong(imageId)); com.itextpdf.text.Image itextImage = com.itextpdf.text.Image.getInstance(imageData); Paragraph caption = new Paragraph(imgName); caption.setAlignment(Element.ALIGN_CENTER); PdfPCell keyCell = new PdfPCell(new Phrase(label)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10); currentTable.addCell(keyCell); PdfPCell valueCell = new PdfPCell(); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); valueCell.addElement(itextImage); valueCell.addElement(caption); currentTable.addCell(valueCell); } } else if (type.equals(FormUtilities.TYPE_MAP)) { if (value.trim().length() == 0) { continue; } String imageId = value.trim(); Image image = daoImages.getImage(Long.parseLong(imageId)); String imgName = image.getName(); byte[] imageData = daoImages.getImageData(Long.parseLong(imageId)); com.itextpdf.text.Image itextImage = com.itextpdf.text.Image.getInstance(imageData); Paragraph caption = new Paragraph(imgName); caption.setAlignment(Element.ALIGN_CENTER); PdfPCell keyCell = new PdfPCell(new Phrase(label)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10); currentTable.addCell(keyCell); PdfPCell valueCell = new PdfPCell(); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); valueCell.addElement(itextImage); valueCell.addElement(caption); currentTable.addCell(valueCell); } else if (type.equals(FormUtilities.TYPE_SKETCH)) { if (value.trim().length() == 0) { continue; } String[] imageIdsSplit = value.split(Note.IMAGES_SEPARATOR); for (String imageId : imageIdsSplit) { Image image = daoImages.getImage(Long.parseLong(imageId)); String imgName = image.getName(); byte[] imageData = daoImages.getImageData(Long.parseLong(imageId)); com.itextpdf.text.Image itextImage = com.itextpdf.text.Image.getInstance(imageData); Paragraph caption = new Paragraph(imgName); caption.setAlignment(Element.ALIGN_CENTER); PdfPCell keyCell = new PdfPCell(new Phrase(label)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10); currentTable.addCell(keyCell); PdfPCell valueCell = new PdfPCell(); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); valueCell.addElement(itextImage); valueCell.addElement(caption); currentTable.addCell(valueCell); } } else { addKeyValueToTableRow(currentTable, label, value); } } } document.add(currentChapter); document.newPage(); } }
From source file:eu.geopaparazzi.plugins.pdfexport.PdfExportDialogFragment.java
License:Open Source License
private void addKeyValueToTableRow(PdfPTable table, String key, String value) { PdfPCell keyCell = new PdfPCell(new Phrase(key)); keyCell.setHorizontalAlignment(Element.ALIGN_CENTER); keyCell.setVerticalAlignment(Element.ALIGN_MIDDLE); keyCell.setPadding(10);/*w w w. ja v a 2s .com*/ table.addCell(keyCell); PdfPCell valueCell = new PdfPCell(new Phrase(value)); valueCell.setHorizontalAlignment(Element.ALIGN_CENTER); valueCell.setVerticalAlignment(Element.ALIGN_MIDDLE); valueCell.setPadding(10); table.addCell(valueCell); }
From source file:eu.trentorise.smartcampus.citizenportal.service.PdfCreator.java
private static void createTable(Section subCatPart) throws BadElementException { PdfPTable table = new PdfPTable(5); try {/* w ww .j av a2 s. co m*/ table.setTotalWidth(new float[] { 70, 85, 250, 60, 60 }); table.setLockedWidth(true); } catch (DocumentException e) { e.printStackTrace(); } // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Posizione", smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Id Domanda", smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Richiedente", smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Comp.", smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Punti", smallBold)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (listClass != null) { for (int i = 0; i < listClass.size(); i++) { // Cell for position table.addCell(String.valueOf(listClass.get(i).getPosition())); // Cell for practice id PdfPCell cId = new PdfPCell(new Phrase(listClass.get(i).getPracticeId())); cId.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cId); // Cell for ric_name table.addCell(listClass.get(i).getRicName()); // Cell for fam_components PdfPCell cComps = new PdfPCell(new Phrase(String.valueOf(listClass.get(i).getFamComponents()))); cComps.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cComps); // Cell for score PdfPCell cScore = new PdfPCell(new Phrase(listClass.get(i).getScore())); cScore.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cScore); } } else { for (int i = 0; i < listClassFinal.size(); i++) { // Cell for position table.addCell(String.valueOf(listClassFinal.get(i).getPosition())); // Cell for practice id PdfPCell cId = new PdfPCell(new Phrase(listClassFinal.get(i).getPracticeId())); cId.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cId); // Cell for ric_name table.addCell(listClassFinal.get(i).getRicName()); // Cell for fam_components PdfPCell cComps = new PdfPCell( new Phrase(String.valueOf(listClassFinal.get(i).getFamComponents()))); cComps.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cComps); // Cell for score PdfPCell cScore = new PdfPCell(new Phrase(listClassFinal.get(i).getScore())); cScore.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cScore); } } subCatPart.add(table); }