List of usage examples for com.itextpdf.text.pdf PdfPCell setFixedHeight
public void setFixedHeight(float fixedHeight)
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 {/*w w w . ja v a 2 s . 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:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java
License:Open Source License
void addSpacerRow() throws DocumentException { PdfPTable table = createTable(ONE_COLUMN); PdfPCell spacerCell = createCell(); spacerCell.setFixedHeight(SPACER_HEIGHT); table.addCell(spacerCell);/*from w ww . j a v a 2 s . c o m*/ getDocument().add(table); }
From source file:IPDGES.ConcentForm.java
private void formatCellBorder(PdfPCell cell, int h) { cell.setFixedHeight(h); cell.setBorder(0); }
From source file:jdbreport.model.io.pdf.itext5.PdfWriter.java
License:Apache License
private PdfPCell writeCell(ReportModel model, jdbreport.model.Cell srcCell, int row, int col) throws BadElementException, IOException, SaveReportException { CellStyle style = model.getStyles(srcCell.getStyleId()); java.awt.Rectangle rect = model.getCellRect(row, col, true, true); float h = (float) Units.PT.setYPixels((int) rect.getHeight()); float w = (float) Units.PT.setXPixels((int) rect.getWidth()); PdfPCell pdfCell; if (srcCell.getPicture() != null) { Icon icon = srcCell.getPicture().getIcon(); java.awt.Image awtImage = ((ImageIcon) icon).getImage(); com.itextpdf.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell = new PdfPCell(image); } else {/*from ww w . j a v a 2 s . c om*/ pdfCell = new PdfPCell(); String text = null; if (srcCell.getValue() instanceof CellValue<?>) { StringWriter strWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(strWriter); if (!((CellValue<?>) srcCell.getValue()).write(printWriter, model, row, col, this, ReportBook.PDF)) { java.awt.Image awtImage = ((CellValue<?>) srcCell.getValue()).getAsImage(model, row, col); if (awtImage != null) { com.itextpdf.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell.setImage(image); } } else { text = strWriter.getBuffer().toString(); } } else { if (jdbreport.model.Cell.TEXT_HTML.equals(srcCell.getContentType())) { writeHTMLText(model.getStyles(srcCell.getStyleId()), srcCell, pdfCell); } else { text = model.getCellText(srcCell); } } if (text != null && text.length() > 0) { com.itextpdf.text.Font font; if (fonts.containsKey(style.getId())) { font = fonts.get(style.getId()); } else { font = getFontMapper().styleToPdf(style); fonts.put(style.getId(), font); } Paragraph p; if (font != null) { p = new Paragraph(text, font); } else { p = new Paragraph(text); } pdfCell.setPhrase(p); } } pdfCell.setFixedHeight(h); pdfCell.setPadding(1); pdfCell.setBackgroundColor(new BaseColor(style.getBackground().getRGB())); pdfCell.setHorizontalAlignment(toPdfHAlignment(style.getHorizontalAlignment())); pdfCell.setVerticalAlignment(toPdfVAlignment(style.getVerticalAlignment())); if (style.getAngle() != 0) { pdfCell.setRotation(roundAngle(style.getAngle())); } assignBorders(style, pdfCell); pdfCell.setNoWrap(!style.isWrapLine()); if (srcCell.getColSpan() > 0) { pdfCell.setColspan(srcCell.getColSpan() + 1); } if (srcCell.getRowSpan() > 0) { pdfCell.setRowspan(srcCell.getRowSpan() + 1); } return pdfCell; }
From source file:net.digitstar.vanadio.AbstractReportPdf.java
License:Apache License
protected PdfPTable createHeader(Document document, int page, int pageTotal, ReportOptions reportOptions) { PdfPTable header = new PdfPTable(3); header.setTotalWidth(document.right() - document.left()); PdfPCell def = header.getDefaultCell(); String left = ""; String center = ""; String right = ""; if (reportOptions.isShowPageNumberIfOnePage() || (!reportOptions.isShowPageNumberIfOnePage() && pageTotal > 1)) { right = reportOptions.isShowPageTotal() ? Labels.PAGE_TOTAL.getLabelFormatted(page, pageTotal) : Labels.PAGE.getLabelFormatted(page); }//from ww w . j a va 2s .co m def.setFixedHeight(computeHeight(FontType.HEADERFOOTER.getFont())); def.setBorder(CellStyle.Border.NONE.getValue()); if (reportOptions.isUseHrRuler()) def.setBorder(CellStyle.Border.BOTTOM.getValue()); def.setHorizontalAlignment(CellStyle.Align.LEFT.getValue()); header.addCell(new Phrase(left, FontType.HEADERFOOTER.getFont())); def.setHorizontalAlignment(CellStyle.Align.CENTER.getValue()); header.addCell(new Phrase(center, FontType.HEADERFOOTER.getFont())); def.setHorizontalAlignment(CellStyle.Align.RIGHT.getValue()); header.addCell(new Phrase(right, FontType.HEADERFOOTER.getFont())); return header; }
From source file:net.digitstar.vanadio.AbstractReportPdf.java
License:Apache License
protected PdfPTable createFooter(Document document, int page, int pageTotal, ReportOptions reportOptions) { PdfPTable footer = new PdfPTable(3); footer.setTotalWidth(document.right() - document.left()); PdfPCell def = footer.getDefaultCell(); String left = ""; String center = ""; String right = ""; def.setFixedHeight(computeHeight(FontType.HEADERFOOTER.getFont())); def.setBorder(CellStyle.Border.NONE.getValue()); if (reportOptions.isUseHrRuler()) def.setBorder(CellStyle.Border.TOP.getValue()); if (reportOptions.isShowPrintDate()) right = Labels.PRINTED.getLabelFormatted(getDateTimeFormat().format(new Date())); def.setHorizontalAlignment(CellStyle.Align.LEFT.getValue()); footer.addCell(new Phrase(left, FontType.HEADERFOOTER.getFont())); def.setHorizontalAlignment(CellStyle.Align.CENTER.getValue()); footer.addCell(new Phrase(center, FontType.HEADERFOOTER.getFont())); def.setHorizontalAlignment(CellStyle.Align.RIGHT.getValue()); footer.addCell(new Phrase(right, FontType.HEADERFOOTER.getFont())); return footer; }
From source file:net.digitstar.vanadio.helpers.PdfHelper.java
License:Apache License
public static PdfPCell newCell(CellStyle style) { PdfPCell cell = new PdfPCell(); if (style != null) { if (style.getNestedTable() != null) { cell = new PdfPCell(style.getNestedTable()); style.setNestedTable(null);//from w w w . java 2 s. co m } else if (style.getImage() != null) { cell = new PdfPCell(style.getImage(), style.isFitImage()); style.setImage(null); } else if (style.getText() != null) { cell = new PdfPCell(style.getText()); style.setText((String) null); } cell.setColspan(style.getColspan()); cell.setRowspan(style.getRowspan()); cell.setMinimumHeight(style.getMinimumHeight()); cell.setFixedHeight(style.getFixedHeight()); cell.setNoWrap(style.isNoWrap()); cell.setRotation(style.getRotation().getValue()); style = Alignment.assign(style); cell.setHorizontalAlignment(style.getHorizAlign().getValue()); cell.setVerticalAlignment(style.getVertAlign().getValue()); cell.setUseVariableBorders(style.isUseVariableBorders()); cell.setUseBorderPadding(style.isUseBorderPadding()); if (!style.getBorderWidth().isAllSideEqual()) { cell.setBorderWidthBottom(style.getBorderWidth().getBottom()); cell.setBorderWidthLeft(style.getBorderWidth().getLeft()); cell.setBorderWidthRight(style.getBorderWidth().getRight()); cell.setBorderWidthTop(style.getBorderWidth().getTop()); } else { cell.setBorderWidth(style.getBorderWidth().getValue()); } cell.setPaddingBottom(style.getPadding().getBottom()); cell.setPaddingLeft(style.getPadding().getLeft()); cell.setPaddingRight(style.getPadding().getRight()); cell.setPaddingTop(style.getPadding().getTop()); cell.setBorderColorBottom(style.getBorderColor().getBottom()); cell.setBorderColorLeft(style.getBorderColor().getLeft()); cell.setBorderColorRight(style.getBorderColor().getRight()); cell.setBorderColorTop(style.getBorderColor().getTop()); cell.setBorder(style.getBorder().getValue()); cell.setBackgroundColor(style.getBackgroundColor()); if (style.getGreyFill() >= 0) { cell.setGrayFill(style.getGreyFill()); } } return cell; }
From source file:org.inspira.condominio.pdf.DocumentoEgresos.java
public void exportarPdf(String destino) throws IOException, DocumentException { File file = new File(destino); file.getParentFile().mkdirs();//w ww.j a va 2 s . c o m PdfWriter.getInstance(documento, new FileOutputStream(file)); documento.open(); documento.add(new Paragraph( "Periodo: ".concat( DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()).format(new Date())), F_NORMAL)); documento.add(new Paragraph(admin, F_NORMAL)); Paragraph heading = new Paragraph("Gastos ".concat(tipoDeGasto), new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, new BaseColor(0x000000))); heading.setSpacingBefore(16f); heading.setSpacingAfter(16f); Paragraph heading2 = new Paragraph("Autoriz", new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL, new BaseColor(0x000000))); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); Paragraph heading3 = new Paragraph("Vo. Bo.", new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL, new BaseColor(0x000000))); PdfPCell cell1 = new PdfPCell(heading2); cell1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell1.setColspan(1); cell1.setFixedHeight(20f); cell1.setBorder(Rectangle.NO_BORDER); PdfPCell cell2 = new PdfPCell(heading3); cell2.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); cell2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell2.setColspan(1); cell2.setFixedHeight(20f); cell2.setBorder(Rectangle.NO_BORDER); table.addCell(cell1); table.addCell(cell2); table.setSpacingBefore(16f); table.setSpacingAfter(32f); documento.add(heading); agregarTablaEgresos(egresos); documento.add(table); agregarZonaVistoBueno(); documento.close(); }
From source file:org.inspira.condominio.pdf.DocumentoEgresos.java
private void agregarZonaVistoBueno() throws DocumentException { PdfPCell cell1 = new PdfPCell(new Phrase("", F_NORMAL)); cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell1.setColspan(5);//from www . java2 s.co m cell1.setFixedHeight(20f); cell1.setBorder(Rectangle.BOTTOM); PdfPCell cell2 = new PdfPCell(new Phrase("", F_NORMAL)); cell2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell2.setColspan(1); cell2.setFixedHeight(20f); cell2.setBorder(Rectangle.NO_BORDER); PdfPCell cell3 = new PdfPCell(new Phrase("", F_NORMAL)); cell3.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell3.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell3.setColspan(5); cell3.setFixedHeight(20f); cell3.setBorder(Rectangle.BOTTOM); PdfPCell cell4 = new PdfPCell(new Phrase(presidente, F_NORMAL)); cell4.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell4.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell4.setColspan(5); cell4.setFixedHeight(20f); cell4.setBorder(Rectangle.NO_BORDER); PdfPCell cell5 = new PdfPCell(new Phrase("", F_NORMAL)); cell5.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell5.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell5.setColspan(1); cell5.setFixedHeight(20f); cell5.setBorder(Rectangle.NO_BORDER); PdfPCell cell6 = new PdfPCell(new Phrase("", F_NORMAL)); cell6.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell6.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell6.setColspan(5); cell6.setFixedHeight(20f); cell6.setBorder(Rectangle.NO_BORDER); PdfPCell cell7 = new PdfPCell(new Phrase(("(Administrador)"), F_NORMAL)); cell7.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell7.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell7.setColspan(5); cell7.setFixedHeight(20f); cell7.setBorder(Rectangle.NO_BORDER); PdfPCell cell8 = new PdfPCell(new Phrase("", F_NORMAL)); cell8.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell8.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell8.setColspan(1); cell8.setFixedHeight(20f); cell8.setBorder(Rectangle.NO_BORDER); PdfPCell cell9 = new PdfPCell(new Phrase(("(Presidente comit de vigilancia)"), F_NORMAL)); cell9.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell9.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell9.setColspan(5); cell9.setFixedHeight(20f); cell9.setBorder(Rectangle.NO_BORDER); PdfPTable table = new PdfPTable(11); table.setWidthPercentage(100); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); table.addCell(cell5); table.addCell(cell6); table.addCell(cell7); table.addCell(cell8); table.addCell(cell9); documento.add(table); }
From source file:org.inspira.condominio.pdf.DocumentoEgresos.java
private void agregarTablaEgresos(InformacionEgreso[] egresos) throws DocumentException { PdfPCell cell1 = new PdfPCell(new Phrase("Fecha", F_CELL_HEADER_TEXT)); cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell1.setColspan(2);//from w ww . j av a2 s . c om cell1.setFixedHeight(20f); cell1.setBackgroundColor(new BaseColor(0xff009846)); PdfPCell cell2 = new PdfPCell(new Phrase("Descripcin", F_CELL_HEADER_TEXT)); cell2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell2.setColspan(6); cell2.setBackgroundColor(new BaseColor(0xff009846)); cell2.setFixedHeight(20f); PdfPCell cell3 = new PdfPCell(new Phrase("Monto", F_CELL_HEADER_TEXT)); cell3.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell3.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell3.setColspan(2); cell3.setBackgroundColor(new BaseColor(0xff009846)); cell3.setFixedHeight(20f); PdfPCell cell4 = new PdfPCell(new Phrase("Pagado con", F_CELL_HEADER_TEXT)); cell4.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell4.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell4.setColspan(2); cell4.setBackgroundColor(new BaseColor(0xff009846)); cell4.setFixedHeight(20f); PdfPCell cell5 = new PdfPCell(new Phrase("Total", F_NORMAL)); cell5.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); cell5.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell5.setColspan(8); cell5.setFixedHeight(20f); PdfPCell cell6 = new PdfPCell(); cell6.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell6.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell6.setColspan(4); cell6.setFixedHeight(20f); PdfPTable table = new PdfPTable(12); table.setWidthPercentage(100); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); float total = agregarEgresos(table, egresos); cell5.setBorder(Rectangle.RIGHT); table.addCell(cell5); cell6.setPhrase(new Phrase(String.format("%.2f pesos", total), F_NORMAL)); table.addCell(cell6); documento.add(table); }