List of usage examples for com.lowagie.text.pdf PdfPCell setUseBorderPadding
public void setUseBorderPadding(boolean use)
From source file:org.gtdfree.addons.PDFExportAddOn.java
License:Open Source License
private PdfPCell newCell(Paragraph p) throws BadElementException { PdfPCell c = new PdfPCell(p); c.setBorder(PdfPCell.BOX);//from w ww . j a v a2 s . c o m c.setBorderWidth(0.1f); c.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); c.setPaddingBottom(3f); c.setPaddingLeft(3f); c.setPaddingRight(3f); c.setPaddingTop(0f); c.setUseBorderPadding(true); return c; }
From source file:org.odftoolkit.odfdom.converter.internal.itext.stylable.StylableParagraph.java
License:Open Source License
private PdfPCell createCell() { PdfPCell cell = new PdfPCell(); cell.setBorder(Table.NO_BORDER);//from w w w . java2 s.c o m cell.setPadding(0.0f); cell.setUseBorderPadding(true); cell.getColumn().setAdjustFirstLine(false); cell.setUseDescender(true); return cell; }
From source file:org.tellervo.desktop.print.SeriesReport.java
License:Open Source License
/** * Get PdfPTable containing the ring width data for this series * //from w w w .j a v a 2 s.c o m * @return PdfPTable * @throws DocumentException * @throws IOException * @throws MalformedURLException */ private void getDataTable(Boolean wj) throws DocumentException, MalformedURLException, IOException { // THE actual table PdfPTable mainTable = new PdfPTable(11); // Cell for column headers PdfPCell colHeadCell = new PdfPCell(); // Model for data DecadalModel model; // Flag to show if there are *any* ring remarks Boolean hasRemarks = false; float[] columnWidths = new float[] { 20f, 8f, 8f, 8f, 8f, 8f, 8f, 8f, 8f, 8f, 8f }; mainTable.setWidths(columnWidths); mainTable.setWidthPercentage(100f); if (wj == true) { if (s.hasWeiserjahre() == true) { model = new WJTableModel(s); document.add(new Chunk("Weiserjahre:", subSubSectionFont)); } else { return; } } else { model = new UnitAwareDecadalModel(s); document.add(new Chunk("Ring widths:", subSubSectionFont)); } int rows = model.getRowCount(); // Do column headers if (wj == true) { colHeadCell.setPhrase(new Phrase("inc/dec", tableHeaderFont)); } else if (this.s.getTridasUnits() == null) { // Unitless colHeadCell.setPhrase(new Phrase(" ", tableHeaderFont)); } else { // Normal tridas units try { /*if(this.s.getTridasUnits().getNormalTridas().equals(NormalTridasUnit.MICROMETRES)) { colHeadCell.setPhrase(new Phrase("microns", tableHeaderFont)); }*/ // Use the current default display units colHeadCell.setPhrase(new Phrase(displayUnits.value(), tableHeaderFont)); /*if(displayUnits.equals(NormalTridasUnit.MICROMETRES)) { colHeadCell.setPhrase(new Phrase("microns", tableHeaderFont)); } else if(displayUnits.equals(NormalTridasUnit.HUNDREDTH_MM)) { colHeadCell.setPhrase(new Phrase("1/100th mm", tableHeaderFont)); } */ } catch (Exception e) { colHeadCell.setPhrase(new Phrase(" ", tableHeaderFont)); } } colHeadCell.setBorderWidthBottom(headerLineWidth); colHeadCell.setBorderWidthTop(headerLineWidth); colHeadCell.setBorderWidthLeft(headerLineWidth); colHeadCell.setBorderWidthRight(headerLineWidth); mainTable.addCell(colHeadCell); for (int i = 0; i < 10; i++) { colHeadCell.setPhrase(new Phrase(Integer.toString(i), tableHeaderFont)); colHeadCell.setHorizontalAlignment(Element.ALIGN_CENTER); colHeadCell.setBorderWidthBottom(headerLineWidth); colHeadCell.setBorderWidthTop(headerLineWidth); colHeadCell.setBorderWidthLeft(lineWidth); colHeadCell.setBorderWidthRight(lineWidth); if (i == 0) colHeadCell.setBorderWidthLeft(headerLineWidth); if (i == 9) colHeadCell.setBorderWidthRight(headerLineWidth); mainTable.addCell(colHeadCell); } // Loop through rows for (int row = 0; row < rows; row++) { // Loop through columns for (int col = 0; col < 11; col++) { // Mini table to hold remark icons PdfPTable remarksMiniTable = new PdfPTable(3); float[] widths = { 0.3f, 0.3f, 0.6f }; remarksMiniTable.setWidths(widths); remarksMiniTable.setWidthPercentage(100); // Get ring value or year number for first column Phrase cellValuePhrase = null; Object value = model.getValueAt(row, col); if (value == null) { cellValuePhrase = new Phrase(""); } else { /*if(displayUnits.equals(NormalTridasUnit.HUNDREDTH_MM)) { try{ Integer val = (Integer) value; val =val/10; cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col)); } catch (Exception e){ cellValuePhrase = new Phrase(value.toString(), getTableFont(col)); } } else if(displayUnits.equals(NormalTridasUnit.FIFTIETH_MM)) { try{ Integer val = (Integer) value; val =val/20; cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col)); } catch (Exception e){ cellValuePhrase = new Phrase(value.toString(), getTableFont(col)); } } else if(displayUnits.equals(NormalTridasUnit.TWENTIETH_MM)) { try{ Integer val = (Integer) value; val =val/50; cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col)); } catch (Exception e){ cellValuePhrase = new Phrase(value.toString(), getTableFont(col)); } } else if(displayUnits.equals(NormalTridasUnit.TENTH_MM)) { try{ Integer val = (Integer) value; val =val/100; cellValuePhrase = new Phrase(String.valueOf(val), getTableFont(col)); } catch (Exception e){ cellValuePhrase = new Phrase(value.toString(), getTableFont(col)); } } else if(displayUnits.equals(NormalTridasUnit.MICROMETRES)) {*/ cellValuePhrase = new Phrase(value.toString(), getTableFont(col)); //} } // Get any remarks and compile them into a mini table org.tellervo.desktop.Year year = model.getYear(row, col); List<TridasRemark> remarksList = null; remarksList = s.getRemarksForYear(year); // If there are remarks, cycle through them adding cells to the mini table if (col != 0 && remarksList.size() > 0) { hasRemarks = true; // Get icons for remarks int cellnum = 1; int remarknum = 0; for (TridasRemark remark : remarksList) { // Keep track of which remark we are on. remarknum++; // String for holding remark name for debugging String remstr = "?"; // The actual remark icon Image icon = null; // A table cell for the remark PdfPCell remarkCell = new PdfPCell(); // Set default attributes for remark and value cells remarkCell.setBorderWidthBottom(0); remarkCell.setBorderWidthTop(0); remarkCell.setBorderWidthLeft(0); remarkCell.setBorderWidthRight(0); remarkCell.setHorizontalAlignment(Element.ALIGN_RIGHT); remarkCell.setPadding(0); remarkCell.setUseBorderPadding(true); // A table cell for the ring width value PdfPCell valueCell = new PdfPCell(); valueCell = remarkCell; // Get actual icon (either tridas or tellervo) if (remark.isSetNormalTridas()) { remstr = remark.getNormalTridas().toString(); icon = getTridasIcon(remark.getNormalTridas()); if (icon == null) icon = Builder.getITextImageMissingIcon(); } else if (TELLERVO.equals(remark.getNormalStd())) { remstr = remark.getNormal(); icon = getCorinaIcon(remark.getNormal()); if (icon == null) icon = Builder.getITextImageMissingIcon(); } else { if (remark.isSetValue()) { remstr = remark.getValue(); } else if (remark.isSetNormal()) { remstr = remark.getNormal(); } else { remstr = "Unknown"; } icon = Builder.getITextImageIcon("user.png"); } // Print debug info for this remark String errStr = "Getting icon for " + remstr + " for year " + year.toString() + "(cell value = " + cellnum + ")"; System.out.print(errStr); // Shrink the icon a bit icon.scalePercent(20); // Add icon to minitable remarkCell.addElement(icon); remarksMiniTable.addCell(remarkCell); cellnum++; if (cellnum == 1 && remarksList.size() < cellnum) { // First cell and no remark so print blank valueCell.setPhrase(new Phrase("")); remarksMiniTable.addCell(valueCell); cellnum++; } if (cellnum == 2 && remarksList.size() < cellnum) { // Second cell and no remark so print blank valueCell.setPhrase(new Phrase("")); remarksMiniTable.addCell(valueCell); cellnum++; } if (cellnum == 3) { // In third cell so print value valueCell.setPhrase(cellValuePhrase); remarksMiniTable.addCell(valueCell); cellnum++; } else if (cellnum % 3 == 0) { // In third column so print blank valueCell.setPhrase(new Phrase("")); remarksMiniTable.addCell(valueCell); cellnum++; } if (remarknum == remarksList.size()) { valueCell.setPhrase(new Phrase("")); remarksMiniTable.addCell(valueCell); remarksMiniTable.addCell(valueCell); } remarkCell = null; valueCell = null; } } else { // No remarks so make mini table have blank, blank, value // Create blank and value cells PdfPCell blankCell = new PdfPCell(); PdfPCell valueCell = new PdfPCell(); // Set up style blankCell.setBorderWidthBottom(0); blankCell.setBorderWidthTop(0); blankCell.setBorderWidthLeft(0); blankCell.setBorderWidthRight(0); blankCell.setHorizontalAlignment(Element.ALIGN_RIGHT); blankCell.setPadding(0); blankCell.setUseBorderPadding(true); valueCell = blankCell; // Add cells to mini table remarksMiniTable.addCell(blankCell); remarksMiniTable.addCell(blankCell); valueCell.setPhrase(cellValuePhrase); remarksMiniTable.addCell(valueCell); } // Set border styles depending on where we are in the table // Defaults PdfPCell mainTableCell = new PdfPCell(); mainTableCell.setBorderWidthBottom(lineWidth); mainTableCell.setBorderWidthTop(lineWidth); mainTableCell.setBorderWidthLeft(lineWidth); mainTableCell.setBorderWidthRight(lineWidth); mainTableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); // Row headers if (col == 0) { mainTableCell.setHorizontalAlignment(Element.ALIGN_LEFT); mainTableCell.setBorderWidthLeft(headerLineWidth); mainTableCell.setBorderWidthRight(headerLineWidth); } // First data column if (col == 1) { mainTableCell.setBorderWidthLeft(headerLineWidth); } // Last data column if (col == 10) { mainTableCell.setBorderWidthRight(headerLineWidth); } // Last row if (row == model.getRowCount() - 1) { mainTableCell.setBorderWidthBottom(headerLineWidth); } // Write mini table to cell mainTableCell.addElement(remarksMiniTable); //mainTableCell.addElement(userRemarksMiniTable); // Write cell to main table mainTable.addCell(mainTableCell); } } // Add table to document document.add(mainTable); if (!wj && hasRemarks) getTableKey(); }