List of usage examples for com.itextpdf.text Element ALIGN_RIGHT
int ALIGN_RIGHT
To view the source code for com.itextpdf.text Element ALIGN_RIGHT.
Click Source Link
From source file:de.jost_net.JVerein.io.MitgliederStatistik.java
License:Open Source License
public MitgliederStatistik(final File file, Date stichtag) throws ApplicationException { try {/*from ww w.j ava2 s . c o m*/ if (stichtag == null) { throw new ApplicationException("Stichtag ist leer"); } FileOutputStream fos = new FileOutputStream(file); String subtitle = ""; if (stichtag != null) { subtitle = "Stichtag: " + new JVDateFormatTTMMJJJJ().format(stichtag); } Reporter reporter = new Reporter(fos, "Mitgliederstatistik", subtitle, 3); Paragraph pAltersgruppen = new Paragraph("\n" + "Altersgruppen", Reporter.getFreeSans(11)); reporter.add(pAltersgruppen); reporter.addHeaderColumn("Altersgruppe", Element.ALIGN_CENTER, 100, BaseColor.LIGHT_GRAY); reporter.addHeaderColumn("Insgesamt", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY); reporter.addHeaderColumn("mnnlich", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY); reporter.addHeaderColumn("weiblich", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY); reporter.addHeaderColumn("ohne Angabe", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY); reporter.createHeader(70f, Element.ALIGN_LEFT); AltersgruppenParser ap = new AltersgruppenParser(Einstellungen.getEinstellung().getAltersgruppen()); while (ap.hasNext()) { VonBis vb = ap.getNext(); addAltersgruppe(reporter, vb, stichtag); } addAltersgruppe(reporter, new VonBis(-1, -1), stichtag); addAltersgruppe(reporter, new VonBis(0, 199), stichtag); reporter.closeTable(); Paragraph pBeitragsgruppen = new Paragraph("\n" + "Beitragsgruppen", Reporter.getFreeSans(11)); reporter.add(pBeitragsgruppen); reporter.addHeaderColumn("Beitragsgruppe", Element.ALIGN_CENTER, 100, BaseColor.LIGHT_GRAY); reporter.addHeaderColumn("Insgesamt", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY); reporter.addHeaderColumn("mnnlich", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY); reporter.addHeaderColumn("weiblich", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY); reporter.addHeaderColumn("ohne Angabe", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY); reporter.createHeader(70f, Element.ALIGN_LEFT); DBIterator<Beitragsgruppe> beitragsgruppen = Einstellungen.getDBService() .createList(Beitragsgruppe.class); beitragsgruppen.setOrder("order by bezeichnung"); while (beitragsgruppen.hasNext()) { Beitragsgruppe bg = (Beitragsgruppe) beitragsgruppen.next(); addBeitragsgruppe(reporter, bg, stichtag); } addBeitragsgruppe(reporter, null, stichtag); reporter.closeTable(); try { JVDateFormatTTMMJJJJ ttmmjj = new JVDateFormatTTMMJJJJ(); Geschaeftsjahr gj = new Geschaeftsjahr(stichtag); Paragraph pGuV = new Paragraph("\n" + String.format("Anmeldungen/Abmeldungen (%s - %s)", ttmmjj.format(gj.getBeginnGeschaeftsjahr()), ttmmjj.format(gj.getEndeGeschaeftsjahr())), Reporter.getFreeSans(11)); reporter.add(pGuV); reporter.addHeaderColumn("Text", Element.ALIGN_CENTER, 100, BaseColor.LIGHT_GRAY); reporter.addHeaderColumn("Anzahl", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY); reporter.createHeader(70f, Element.ALIGN_LEFT); reporter.addColumn("Anmeldungen", Element.ALIGN_LEFT); reporter.addColumn(getAnmeldungen(gj) + "", Element.ALIGN_RIGHT); reporter.addColumn("Abmeldungen", Element.ALIGN_LEFT); reporter.addColumn(getAbmeldungen(gj) + "", Element.ALIGN_RIGHT); reporter.closeTable(); } catch (ParseException e) { Logger.error("Fehler", e); throw new ApplicationException(e); } reporter.close(); fos.close(); FileViewer.show(file); } catch (Exception e) { Logger.error("Fehler", e); throw new ApplicationException("Fehler", e); } }
From source file:de.jost_net.JVerein.io.MitgliederStatistik.java
License:Open Source License
private void addAltersgruppe(Reporter reporter, VonBis vb, Date stichtag) throws RemoteException { if (vb.getVon() == -1) { reporter.addColumn("ohne Geburtsdatum", Element.ALIGN_LEFT); } else if (vb.getVon() == 0 && vb.getBis() == 199) { reporter.addColumn("Insgesamt", Element.ALIGN_LEFT); } else {/*from ww w .j a v a 2s . c om*/ reporter.addColumn(String.format("Altersgruppe %d - %d", vb.getVon(), vb.getBis()), Element.ALIGN_LEFT); } reporter.addColumn(getAltersgruppe(vb, null, stichtag) + "", Element.ALIGN_RIGHT); reporter.addColumn(getAltersgruppe(vb, GeschlechtInput.MAENNLICH, stichtag) + "", Element.ALIGN_RIGHT); reporter.addColumn(getAltersgruppe(vb, GeschlechtInput.WEIBLICH, stichtag) + "", Element.ALIGN_RIGHT); reporter.addColumn(getAltersgruppe(vb, GeschlechtInput.OHNEANGABE, stichtag) + "", Element.ALIGN_RIGHT); }
From source file:de.jost_net.JVerein.io.MitgliederStatistik.java
License:Open Source License
private void addBeitragsgruppe(Reporter reporter, Beitragsgruppe bg, Date stichtag) throws RemoteException { if (bg == null) { reporter.addColumn("Insgesamt", Element.ALIGN_LEFT); } else {/*from www .j a v a 2 s. c om*/ reporter.addColumn(bg.getBezeichnung(), Element.ALIGN_LEFT); } reporter.addColumn(getBeitragsgruppe(bg, null, stichtag) + "", Element.ALIGN_RIGHT); reporter.addColumn(getBeitragsgruppe(bg, GeschlechtInput.MAENNLICH, stichtag) + "", Element.ALIGN_RIGHT); reporter.addColumn(getBeitragsgruppe(bg, GeschlechtInput.WEIBLICH, stichtag) + "", Element.ALIGN_RIGHT); reporter.addColumn(getBeitragsgruppe(bg, GeschlechtInput.OHNEANGABE, stichtag) + "", Element.ALIGN_RIGHT); }
From source file:de.jost_net.JVerein.io.ProjektSaldoPDF.java
License:Open Source License
public ProjektSaldoPDF(ArrayList<ProjektSaldoZeile> zeile, final File file, Date datumvon, Date datumbis) throws ApplicationException { try {// www . j a va 2 s . c om FileOutputStream fos = new FileOutputStream(file); String subtitle = new JVDateFormatTTMMJJJJ().format(datumvon) + " - " + new JVDateFormatTTMMJJJJ().format(datumbis); Reporter reporter = new Reporter(fos, "Projekte-Saldo", subtitle, zeile.size()); makeHeader(reporter); for (ProjektSaldoZeile pz : zeile) { switch (pz.getStatus()) { case ProjektSaldoZeile.HEADER: { reporter.addColumn((String) pz.getAttribute("projektbezeichnung"), Element.ALIGN_LEFT, new BaseColor(220, 220, 220), 4); break; } case ProjektSaldoZeile.DETAIL: { reporter.addColumn((String) pz.getAttribute("buchungsartbezeichnung"), Element.ALIGN_LEFT); reporter.addColumn((Double) pz.getAttribute("einnahmen")); reporter.addColumn((Double) pz.getAttribute("ausgaben")); reporter.addColumn((Double) pz.getAttribute("umbuchungen")); break; } case ProjektSaldoZeile.SALDOFOOTER: { reporter.addColumn((String) pz.getAttribute("projektbezeichnung"), Element.ALIGN_RIGHT); reporter.addColumn((Double) pz.getAttribute("einnahmen")); reporter.addColumn((Double) pz.getAttribute("ausgaben")); reporter.addColumn((Double) pz.getAttribute("umbuchungen")); break; } case ProjektSaldoZeile.SALDOGEWINNVERLUST: { reporter.addColumn((String) pz.getAttribute("projektbezeichnung"), Element.ALIGN_RIGHT); reporter.addColumn((Double) pz.getAttribute("einnahmen")); reporter.addColumn("", Element.ALIGN_LEFT, 2); break; } case ProjektSaldoZeile.GESAMTSALDOFOOTER: { reporter.addColumn((String) pz.getAttribute("projektbezeichnung"), Element.ALIGN_LEFT); reporter.addColumn((Double) pz.getAttribute("einnahmen")); reporter.addColumn((Double) pz.getAttribute("ausgaben")); reporter.addColumn((Double) pz.getAttribute("umbuchungen")); break; } case ProjektSaldoZeile.GESAMTSALDOGEWINNVERLUST: { reporter.addColumn((String) pz.getAttribute("projektbezeichnung"), Element.ALIGN_LEFT); reporter.addColumn((Double) pz.getAttribute("einnahmen")); reporter.addColumn("", Element.ALIGN_LEFT, 2); break; } case ProjektSaldoZeile.NICHTZUGEORDNETEBUCHUNGEN: { reporter.addColumn((String) pz.getAttribute("projektbezeichnung"), Element.ALIGN_RIGHT, 4); break; } } } GUI.getStatusBar().setSuccessText("Auswertung fertig."); reporter.closeTable(); reporter.close(); fos.close(); FileViewer.show(file); } catch (Exception e) { Logger.error("error while creating report", e); throw new ApplicationException("Fehler", e); } }
From source file:de.jost_net.JVerein.io.Reporter.java
License:Open Source License
/** * Erzeugt eine Zelle fuer die uebergebene Zahl. * // w w w . j av a 2s .co m * @param value * die Zahl. * @return die erzeugte Zelle. */ private PdfPCell getDetailCell(double value) { Font f = null; if (value >= 0) { f = getFreeSans(8, BaseColor.BLACK); } else { f = getFreeSans(8, BaseColor.RED); } PdfPCell cell = new PdfPCell(new Phrase(Einstellungen.DECIMALFORMAT.format(value), f)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); return cell; }
From source file:de.jost_net.JVerein.io.StatistikJahrgaengeExportPDF.java
License:Open Source License
@Override protected void open() throws DocumentException, FileNotFoundException { fos = new FileOutputStream(file); reporter = new Reporter(fos, "Statistik Jahrgnge, Stichtag: " + new JVDateFormatTTMMJJJJ().format(stichtag) + "", "", 3); reporter.addHeaderColumn("Jahrgang", Element.ALIGN_CENTER, 50, BaseColor.LIGHT_GRAY); reporter.addHeaderColumn("Insgesamt", Element.ALIGN_CENTER, 50, BaseColor.LIGHT_GRAY); reporter.addHeaderColumn("mnnlich", Element.ALIGN_CENTER, 50, BaseColor.LIGHT_GRAY); reporter.addHeaderColumn("weiblich", Element.ALIGN_CENTER, 50, BaseColor.LIGHT_GRAY); reporter.addHeaderColumn("ohne Angabe", Element.ALIGN_CENTER, 50, BaseColor.LIGHT_GRAY); reporter.createHeader(50, Element.ALIGN_LEFT); int summegesamt = 0; int summemaennlich = 0; int summeweiblich = 0; int summeohne = 0; for (String key : statistik.keySet()) { reporter.addColumn(key, Element.ALIGN_CENTER); StatistikJahrgang dsbj = statistik.get(key); reporter.addColumn(Einstellungen.INTFORMAT.format(dsbj.getAnzahlgesamt()), Element.ALIGN_RIGHT); reporter.addColumn(Einstellungen.INTFORMAT.format(dsbj.getAnzahlmaennlich()), Element.ALIGN_RIGHT); reporter.addColumn(Einstellungen.INTFORMAT.format(dsbj.getAnzahlweiblich()), Element.ALIGN_RIGHT); reporter.addColumn(Einstellungen.INTFORMAT.format(dsbj.getAnzahlOhne()), Element.ALIGN_RIGHT); summegesamt += dsbj.getAnzahlgesamt(); summemaennlich += dsbj.getAnzahlmaennlich(); summeweiblich += dsbj.getAnzahlweiblich(); summeohne += dsbj.getAnzahlOhne(); }/* w w w .j a v a 2s . co m*/ reporter.addColumn("Summe", Element.ALIGN_CENTER); reporter.addColumn(Einstellungen.INTFORMAT.format(summegesamt), Element.ALIGN_RIGHT); reporter.addColumn(Einstellungen.INTFORMAT.format(summemaennlich), Element.ALIGN_RIGHT); reporter.addColumn(Einstellungen.INTFORMAT.format(summeweiblich), Element.ALIGN_RIGHT); reporter.addColumn(Einstellungen.INTFORMAT.format(summeohne), Element.ALIGN_RIGHT); reporter.closeTable(); }
From source file:edu.harvard.mcz.precapture.encoder.LabelEncoder.java
License:Open Source License
@SuppressWarnings("hiding") public static boolean printList(ArrayList<ContainerLabel> containers) throws PrintFailedException { log.debug("Invoked printList "); boolean result = false; ContainerLabel label = new ContainerLabel(); if (containers.isEmpty()) { log.debug("No labels to print."); } else {/*from w w w.j ava 2s. c o m*/ LabelDefinitionType printDefinition = null; LabelDefinitionListType printDefs = PreCaptureSingleton.getInstance().getPrintFormatDefinitionList(); List<LabelDefinitionType> printDefList = printDefs.getLabelDefinition(); Iterator<LabelDefinitionType> il = printDefList.iterator(); while (il.hasNext()) { LabelDefinitionType def = il.next(); if (def.getTitle().equals(PreCaptureSingleton.getInstance().getProperties().getProperties() .getProperty(PreCaptureProperties.KEY_SELECTED_PRINT_DEFINITION))) { printDefinition = def; } } if (printDefinition == null) { log.error("No selected print format defintion found."); //TODO change from message to error handling dialog that allows picking a print format. JOptionPane.showMessageDialog(null, "Unable to print. No print format is selected."); } else { log.debug(printDefinition.getTitle()); log.debug(printDefinition.getTextOrentation().toString()); LabelEncoder encoder = new LabelEncoder(containers.get(0)); try { Image image = encoder.getImage(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(PreCaptureSingleton.getInstance() .getProperties().getProperties().getProperty(PreCaptureProperties.KEY_LABELPRINTFILE))); // Convert units in print definition to points (72 points/inch, 28.346456 points/cm) int paperWidthPoints = 612; // 8.5" int paperHeightPoints = 792; // 11" int marginsPoints = 36; // 0.5" int labelWidthPoints = 540; // 7.5" int labelHeightPoints = 720; // 10" int numColumns = 1; // goes with above numColumns = printDefinition.getColumns(); float relWidthTextCell = printDefinition.getRelWidthTextCell(); float relWidthBarcodeCell = printDefinition.getRelWidthBarcodeCell(); log.debug("relWidthTextCell = " + relWidthTextCell); log.debug("relWidthBarcodeCell = " + relWidthBarcodeCell); if (printDefinition.getUnits().toString().toLowerCase().equals("inches")) { paperWidthPoints = (int) Math.floor(printDefinition.getPaperWidth() * 72f); paperHeightPoints = (int) Math.floor(printDefinition.getPaperHeight() * 72f); marginsPoints = (int) Math.floor(printDefinition.getMargins() * 72f); labelWidthPoints = (int) Math.floor(printDefinition.getLabelWidth() * 72f); labelHeightPoints = (int) Math.floor(printDefinition.getLabelHeight() * 72f); } if (printDefinition.getUnits().toString().toLowerCase().equals("cm")) { paperWidthPoints = (int) Math.floor(printDefinition.getPaperWidth() * 28.346456f); paperHeightPoints = (int) Math.floor(printDefinition.getPaperHeight() * 28.346456f); marginsPoints = (int) Math.floor(printDefinition.getMargins() * 28.346456f); labelWidthPoints = (int) Math.floor(printDefinition.getLabelWidth() * 28.346456f); labelHeightPoints = (int) Math.floor(printDefinition.getLabelHeight() * 28.346456f); } if (printDefinition.getUnits().toString().toLowerCase().equals("points")) { paperWidthPoints = (int) Math.floor(printDefinition.getPaperWidth() * 1f); paperHeightPoints = (int) Math.floor(printDefinition.getPaperHeight() * 1f); marginsPoints = (int) Math.floor(printDefinition.getMargins() * 1f); labelWidthPoints = (int) Math.floor(printDefinition.getLabelWidth() * 1f); labelHeightPoints = (int) Math.floor(printDefinition.getLabelHeight() * 1f); } if (paperWidthPoints == 612 && paperHeightPoints == 792) { document.setPageSize(PageSize.LETTER); } else { document.setPageSize(new Rectangle(paperWidthPoints, paperHeightPoints)); } document.setMargins(marginsPoints, marginsPoints, marginsPoints, marginsPoints); document.open(); // Sanity check if (paperWidthPoints <= 0) { paperWidthPoints = 612; } if (paperHeightPoints <= 0) { paperHeightPoints = 792; } if (marginsPoints < 0) { marginsPoints = 0; } if (labelWidthPoints <= 0) { labelWidthPoints = 540; } if (labelHeightPoints <= 0) { labelHeightPoints = 720; } if (paperWidthPoints + (marginsPoints * 2) < labelWidthPoints) { labelWidthPoints = paperWidthPoints + (marginsPoints * 2); log.debug("Adjusting label width to fit printable page width"); } if (paperHeightPoints + (marginsPoints * 2) < labelHeightPoints) { labelHeightPoints = paperHeightPoints + (marginsPoints * 2); log.debug("Adjusting label height to fit printable page height"); } // calculate how many columns will fit on the paper. int columns = (int) Math.floor((paperWidthPoints - (marginsPoints * 2)) / labelWidthPoints); // if specified column count is smaller, use the specified. if (numColumns < columns) { columns = numColumns; log.debug( "Fewer columns specified in definition than will fit on page, using specified column count of " + numColumns); } // define two table cells per column, one for text one for barcode. int subCellColumnCount = columns * 2; // set the table, with an absolute width and relative widths of the cells in the table; PdfPTable table = setupTable(paperWidthPoints, marginsPoints, labelWidthPoints, columns, subCellColumnCount, relWidthTextCell, relWidthBarcodeCell); // figure out the width of the cells containing the barcodes. float ratio = ((float) relWidthBarcodeCell) / (((float) relWidthBarcodeCell) + ((float) relWidthTextCell)); float barcodeCellWidthPoints = (float) Math.floor(labelWidthPoints * ratio); log.debug("Width of barcode cell in points: " + barcodeCellWidthPoints); //Rectangle pageSizeRectangle = new Rectangle(paperWidthPoints, paperHeightPoints); //table.setWidthPercentage(cellWidthsPoints, pageSizeRectangle); //table.setTotalWidth(cellWidthsPoints); // Calculate how many cells fit on a page (two cells per label). int labelsPerColumn = (int) Math .floor((paperHeightPoints - (marginsPoints * 2)) / labelHeightPoints); int cellsPerPage = subCellColumnCount * labelsPerColumn; log.debug("Labels per column = " + labelsPerColumn); log.debug("Cells per page = " + cellsPerPage); Iterator<ContainerLabel> iterLabels = containers.iterator(); int cellCounter = 0; // counts number of cells filled on a page. int counter = 0; // counts number of pre capture label data rows to print (each of which may request more than one copy). // TODO: Doesn't fit on page. while (iterLabels.hasNext()) { // Loop through all of the container labels found to print label = iterLabels.next(); if (label != null) { log.debug(label); log.debug("Label: " + counter + " " + label.toString()); for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) { // For each container label, loop through the number of requested copies // Generate a text and a barcode cell for each, and add to array for page int toPrintPlus = toPrint + 1; // for pretty counter in log. log.debug("Copy " + toPrintPlus + " of " + label.getNumberToPrint()); PdfPCell cell = label.toPDFCell(printDefinition); cell.setFixedHeight(labelHeightPoints); // Colors to illustrate where the cells are on the layout if (PreCaptureSingleton.getInstance().getProperties().getProperties() .getProperty(PreCaptureProperties.KEY_DEBUGLABEL).equals("true")) { cell.setBackgroundColor(new BaseColor(255, 255, 30)); } PdfPCell cell_barcode = new PdfPCell(); cell_barcode.setBorderColor(BaseColor.LIGHT_GRAY); cell_barcode.disableBorderSide(PdfPCell.LEFT); cell_barcode.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell_barcode.setHorizontalAlignment(Element.ALIGN_RIGHT); cell_barcode.setFixedHeight(labelHeightPoints); if (PreCaptureSingleton.getInstance().getProperties().getProperties() .getProperty(PreCaptureProperties.KEY_DEBUGLABEL).equals("true")) { cell_barcode.setBackgroundColor(new BaseColor(255, 30, 255)); } encoder = new LabelEncoder(label); image = encoder.getImage(); image.setAlignment(Image.ALIGN_TOP); //image.setAlignment(Image.ALIGN_LEFT); image.setAlignment(Image.ALIGN_RIGHT); image.scaleToFit(barcodeCellWidthPoints, labelHeightPoints); cell_barcode.addElement(image); table.addCell(cell); table.addCell(cell_barcode); cellCounter = cellCounter + 2; // we've added two cells to the page (two cells per label). log.debug("Cells " + cellCounter + " of " + cellsPerPage + " cells per page."); // If we have hit a full set of labels for the page, add them to the document // in each column, filling left to right if (cellCounter >= cellsPerPage - 1) { log.debug("Page is full"); log.debug("Table has " + table.getNumberOfColumns() + " columns and " + table.getRows().size() + " rows "); // Reset to begin next page cellCounter = 0; table.setLockedWidth(true); document.add(table); log.debug("Adding new page"); document.newPage(); table = setupTable(paperWidthPoints, marginsPoints, labelWidthPoints, columns, subCellColumnCount, relWidthTextCell, relWidthBarcodeCell); log.debug("Setup new table"); } } // end loop through toPrint (for a taxon/precapture label data row) counter++; // Increment number of pre capture label data rows. } // end if not null label } // end while results has next (for all taxa requested) // get any remaining cells in pairs if (cellCounter > 0) { log.debug("Adding remaining cells in partial page"); if (cellCounter <= cellsPerPage) { for (int i = cellCounter; i <= cellsPerPage; i++) { PdfPCell emptyCell = new PdfPCell(); emptyCell.setBorder(PdfPCell.NO_BORDER); table.addCell(emptyCell); } } log.debug("Table has " + table.getNumberOfColumns() + " columns and " + table.getRows().size() + " rows "); table.setLockedWidth(true); document.add(table); } document.close(); // send to printer PrintingUtility.sendPDFToPrinter(printDefinition, paperWidthPoints, paperHeightPoints); // Check to see if there was content in the document. if (counter == 0) { result = false; } else { // Printed to pdf ok. result = true; } } catch (FileNotFoundException e) { log.debug(e.getMessage(), e); throw new PrintFailedException("File not found."); } catch (DocumentException e) { log.error(e.getMessage(), e); throw new PrintFailedException("Error building/printing PDF document. " + e.getMessage()); } catch (OutOfMemoryError e) { System.out.println("Out of memory error. " + e.getMessage()); System.out.println("Failed. Too many labels."); throw new PrintFailedException("Ran out of memory, too many labels at once."); } catch (BarcodeCreationException e) { System.out.println("BarcodeCreationException. " + e.getMessage()); System.out.println("Failed. Couldn't create barcode."); throw new PrintFailedException( "Unable to create barcode. Probably too many characters to encode. " + e.getMessage()); } } log.debug("printList Done. Success = " + result); } return result; }
From source file:es.clinica.veterinaria.albaranes.AlbaranPdf.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(5); table.setTotalWidth(new float[] { 55, 150, 200, 70, 70 }); table.setLockedWidth(true);//from w w w .j a va 2s. 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("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<VentaLinea> listVenta = getVenta().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); 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); 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(venta.getCostesinIva()) + " ")); 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); // float costetotal = (float) (venta.getCoste() * (1+(iva*0.01))); 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(venta.getIvas()) + " ")); 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); 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(venta.getCoste()) + " ")); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); table.addCell(cell); return table; }
From source file:es.clinica.veterinaria.facturas.FacturaPdf.java
private void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1);/* w w w.j ava 2s . c om*/ // Lets write a big header String fecha = new SimpleDateFormat("dd / MM / yyyy").format(factura.getFecha()); // Paragraph titulo = new Paragraph("FACTURA N " + factura.getNumero() + // "\nFecha: " + fecha, catFont); // titulo.setAlignment(Element.ALIGN_RIGHT); // preface.add(titulo); addEmptyLine(preface, 2); document.add(preface); // preface = new Paragraph("CENTRO VETERINARIO \"El Rey de la Casa\""); preface.setAlignment(Element.ALIGN_RIGHT); addEmptyLine(preface, 2); document.add(preface); // preface = new Paragraph("Cliente: " + factura.getCliente().getFullname() + // "\nNIF/CIF: " + factura.getCliente().getNif() + // "\n" + factura.getCliente().getDireccion() + // "\n" + factura.getCliente().getCiudad().getPoblacion() + // " (" + factura.getCliente().getProvincia().getProvincia() + ")" + // "\nTelfono: " + factura.getCliente().getTelefono(), smallBold); // preface.setAlignment(Element.ALIGN_LEFT); addEmptyLine(preface, 2); document.add(preface); //preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", // redFont)); //document.add(preface); // Start a new page // document.newPage(); }
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);/*from ww w .jav a 2s . 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; }