Java Code Examples for com.lowagie.text.pdf.PdfPCell#setVerticalAlignment()
The following examples show how to use
com.lowagie.text.pdf.PdfPCell#setVerticalAlignment() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cell.java From MesquiteCore with GNU Lesser General Public License v3.0 | 6 votes |
/** * Creates a PdfPCell based on this Cell object. * @return a PdfPCell * @throws BadElementException */ public PdfPCell createPdfPCell() throws BadElementException { if (rowspan > 1) throw new BadElementException("PdfPCells can't have a rowspan > 1"); if (isTable()) return new PdfPCell(((Table)arrayList.get(0)).createPdfPTable()); PdfPCell cell = new PdfPCell(); cell.setVerticalAlignment(verticalAlignment); cell.setHorizontalAlignment(horizontalAlignment); cell.setColspan(colspan); cell.setUseBorderPadding(useBorderPadding); cell.setUseDescender(useDescender); cell.setLeading(leading(), 0); cell.cloneNonPositionParameters(this); for (Iterator i = getElements(); i.hasNext(); ) { cell.addElement((Element)i.next()); } return cell; }
Example 2
Source File: Cell.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Creates a PdfPCell based on this Cell object. * @return a PdfPCell * @throws BadElementException */ public PdfPCell createPdfPCell() throws BadElementException { if (rowspan > 1) throw new BadElementException("PdfPCells can't have a rowspan > 1"); if (isTable()) return new PdfPCell(((Table)arrayList.get(0)).createPdfPTable()); PdfPCell cell = new PdfPCell(); cell.setVerticalAlignment(verticalAlignment); cell.setHorizontalAlignment(horizontalAlignment); cell.setColspan(colspan); cell.setUseBorderPadding(useBorderPadding); cell.setUseDescender(useDescender); cell.setLeading(getLeading(), 0); cell.cloneNonPositionParameters(this); cell.setNoWrap(getMaxLines() == 1); for (Iterator i = getElements(); i.hasNext(); ) { Element e = (Element)i.next(); if (e.type() == Element.PHRASE || e.type() == Element.PARAGRAPH) { Paragraph p = new Paragraph((Phrase)e); p.setAlignment(horizontalAlignment); e = p; } cell.addElement(e); } return cell; }
Example 3
Source File: PdfWebTable.java From unitime with Apache License 2.0 | 6 votes |
private float addImage(PdfPCell cell, String name) { try { java.awt.Image awtImage = (java.awt.Image)iImages.get(name); if (awtImage==null) return 0; Image img = Image.getInstance(awtImage, Color.WHITE); Chunk ck = new Chunk(img, 0, 0); if (cell.getPhrase()==null) { cell.setPhrase(new Paragraph(ck)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(ck); } return awtImage.getWidth(null); } catch (Exception e) { return 0; } }
Example 4
Source File: PdfDatabaseInformationsReport.java From javamelody with Apache License 2.0 | 6 votes |
private void writeRow(String[] row) { final PdfPCell defaultCell = getDefaultCell(); defaultCell.setVerticalAlignment(Element.ALIGN_TOP); for (final String value : row) { if (value == null || value.isEmpty()) { addCell(""); } else { if (isNumber(value)) { defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else { defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); } addCell(value); } } }
Example 5
Source File: PdfRuntimeDependenciesReport.java From javamelody with Apache License 2.0 | 5 votes |
private void writeHeader() throws DocumentException { final List<String> headers = new ArrayList<String>(); headers.add("Beans"); headers.addAll(calledBeans); final int[] relativeWidths = new int[headers.size()]; Arrays.fill(relativeWidths, 0, headers.size(), 1); relativeWidths[0] = 4; final PdfPTable table = new PdfPTable(headers.size()); table.setWidthPercentage(100); table.setWidths(relativeWidths); table.setHeaderRows(1); final PdfPCell defaultCell = table.getDefaultCell(); defaultCell.setGrayFill(0.9f); defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER); defaultCell.setVerticalAlignment(Element.ALIGN_MIDDLE); defaultCell.setPaddingLeft(0); defaultCell.setPaddingRight(0); for (final String header : headers) { table.addCell(new Phrase(header, boldCellFont)); // pas la première entête de colonne defaultCell.setRotation(90); } defaultCell.setRotation(0); defaultCell.setPaddingLeft(2); defaultCell.setPaddingRight(2); currentTable = table; }
Example 6
Source File: PdfInstructionalOfferingTableBuilder.java From unitime with Apache License 2.0 | 5 votes |
public PdfPCell createCell() { PdfPCell cell = new PdfPCell(); cell.setBorderColor(sBorderColor); cell.setPadding(3); cell.setBorderWidth(0); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(iBgColor); return cell; }
Example 7
Source File: PdfExamGridTable.java From unitime with Apache License 2.0 | 5 votes |
public void addText(PdfPCell cell, String text, boolean bold) { if (text==null) return; if (text.indexOf("<span")>=0) text = text.replaceAll("</span>","").replaceAll("<span .*>", ""); text = text.replaceAll("<br>", "\n"); text = text.replaceAll("<BR>", "\n"); if (cell.getPhrase()==null) { cell.setPhrase(new Paragraph(text, PdfFont.getFont(bold))); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(new Chunk("\n"+text, PdfFont.getFont(bold))); } }
Example 8
Source File: PdfExamGridTable.java From unitime with Apache License 2.0 | 5 votes |
public PdfPCell createCellNoBorder() { PdfPCell cell = new PdfPCell(); cell.setBorderColor(sBorderColor); cell.setPadding(3); cell.setBorderWidth(0); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); return cell; }
Example 9
Source File: PdfExamGridTable.java From unitime with Apache License 2.0 | 5 votes |
public PdfPCell createCell() { PdfPCell cell = new PdfPCell(); cell.setBorderColor(sBorderColor); cell.setPadding(3); cell.setBorderWidth(0); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthTop(1); cell.setBorderWidthBottom(1); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); return cell; }
Example 10
Source File: PdfTimetableGridTable.java From unitime with Apache License 2.0 | 5 votes |
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception { if (text==null) return; if (text.indexOf("<span")>=0) text = text.replaceAll("</span>","").replaceAll("<span .*>", ""); Font font = PdfFont.getFont(bold); BaseFont bf = font.getBaseFont(); float width = bf.getWidthPoint(text, font.getSize()); PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width); template.beginText(); template.setColorFill(Color.BLACK); template.setFontAndSize(bf, font.getSize()); template.setTextMatrix(0, 2); template.showText(text); template.endText(); template.setWidth(width); template.setHeight(font.getSize() + 2); //make an Image object from the template Image img = Image.getInstance(template); img.setRotationDegrees(270); //embed the image in a Chunk Chunk ck = new Chunk(img, 0, 0); if (cell.getPhrase()==null) { cell.setPhrase(new Paragraph(ck)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else { cell.getPhrase().add(ck); } }
Example 11
Source File: PdfTimetableGridTable.java From unitime with Apache License 2.0 | 5 votes |
public void addText(PdfPCell cell, String text, boolean bold) { if (text==null) return; if (text.indexOf("<span")>=0) text = text.replaceAll("</span>","").replaceAll("<span .*>", ""); if (cell.getPhrase()==null) { cell.setPhrase(new Paragraph(text, PdfFont.getSmallFont(bold))); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(new Chunk("\n"+text, PdfFont.getSmallFont(bold))); } }
Example 12
Source File: PdfTimetableGridTable.java From unitime with Apache License 2.0 | 5 votes |
public PdfPCell createCellNoBorder() { PdfPCell cell = new PdfPCell(); cell.setBorderColor(sBorderColor); cell.setPadding(3); cell.setBorderWidth(0); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); return cell; }
Example 13
Source File: PdfWebTable.java From unitime with Apache License 2.0 | 5 votes |
private PdfPCell createCell() { PdfPCell cell = new PdfPCell(); cell.setBorderColor(Color.BLACK); cell.setPadding(3); cell.setBorderWidth(0); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); return cell; }
Example 14
Source File: PdfInstructionalOfferingTableBuilder.java From unitime with Apache License 2.0 | 5 votes |
public void addText(PdfPCell cell, String text, boolean bold, boolean italic, int orientation, Color color, boolean newLine) { if (text==null) return; if (cell.getPhrase()==null) { Chunk ch = new Chunk(text, PdfFont.getFont(bold, italic, color)); cell.setPhrase(new Paragraph(ch)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(orientation); } else { cell.getPhrase().add(new Chunk((newLine?"\n":"")+text, PdfFont.getFont(bold, italic, color))); } }
Example 15
Source File: IncCell.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** Creates a new instance of IncCell */ public IncCell(String tag, ChainedProperties props) { cell = new PdfPCell((Phrase)null); String value = props.getProperty("colspan"); if (value != null) cell.setColspan(Integer.parseInt(value)); value = props.getProperty("align"); if (tag.equals("th")) cell.setHorizontalAlignment(Element.ALIGN_CENTER); if (value != null) { if ("center".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_CENTER); else if ("right".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_RIGHT); else if ("left".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_LEFT); else if ("justify".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); } value = props.getProperty("valign"); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); if (value != null) { if ("top".equalsIgnoreCase(value)) cell.setVerticalAlignment(Element.ALIGN_TOP); else if ("bottom".equalsIgnoreCase(value)) cell.setVerticalAlignment(Element.ALIGN_BOTTOM); } value = props.getProperty("border"); float border = 0; if (value != null) border = Float.parseFloat(value); cell.setBorderWidth(border); value = props.getProperty("cellpadding"); if (value != null) cell.setPadding(Float.parseFloat(value)); cell.setUseDescender(true); value = props.getProperty("bgcolor"); cell.setBackgroundColor(Markup.decodeColor(value)); }
Example 16
Source File: IncCell.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** Creates a new instance of IncCell */ public IncCell(String tag, ChainedProperties props) { cell = new PdfPCell((Phrase)null); String value = props.getProperty("colspan"); if (value != null) cell.setColspan(Integer.parseInt(value)); value = props.getProperty("align"); if (tag.equals("th")) cell.setHorizontalAlignment(Element.ALIGN_CENTER); if (value != null) { if ("center".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_CENTER); else if ("right".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_RIGHT); else if ("left".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_LEFT); else if ("justify".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); } value = props.getProperty("valign"); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); if (value != null) { if ("top".equalsIgnoreCase(value)) cell.setVerticalAlignment(Element.ALIGN_TOP); else if ("bottom".equalsIgnoreCase(value)) cell.setVerticalAlignment(Element.ALIGN_BOTTOM); } value = props.getProperty("border"); float border = 0; if (value != null) border = Float.parseFloat(value); cell.setBorderWidth(border); value = props.getProperty("cellpadding"); if (value != null) cell.setPadding(Float.parseFloat(value)); cell.setUseDescender(true); value = props.getProperty("bgcolor"); cell.setBackgroundColor(Markup.decodeColor(value)); }
Example 17
Source File: Cell.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Creates a PdfPCell based on this Cell object. * * @return a PdfPCell * @throws BadElementException */ public PdfPCell createPdfPCell() throws BadElementException { if (rowspan > 1) { throw new BadElementException("PdfPCells can't have a rowspan > 1"); } if (isTable()) { return new PdfPCell(((Table) arrayList.get(0)).createPdfPTable()); } PdfPCell cell = new PdfPCell(); cell.setVerticalAlignment(verticalAlignment); cell.setHorizontalAlignment(horizontalAlignment); cell.setColspan(colspan); cell.setUseBorderPadding(useBorderPadding); cell.setUseDescender(useDescender); cell.setLeading(getLeading(), 0); cell.cloneNonPositionParameters(this); cell.setNoWrap(getMaxLines() == 1); for (Iterator i = getElements(); i.hasNext();) { Element e = (Element) i.next(); if (e.type() == Element.PHRASE || e.type() == Element.PARAGRAPH) { Paragraph p = new Paragraph((Phrase) e); p.setAlignment(horizontalAlignment); e = p; } cell.addElement(e); } return cell; }
Example 18
Source File: SimpleCell.java From gcs with Mozilla Public License 2.0 | 4 votes |
/** * Creates a PdfPCell with these attributes. * * @param rowAttributes * @return a PdfPCell based on these attributes. */ public PdfPCell createPdfPCell(SimpleCell rowAttributes) { PdfPCell cell = new PdfPCell(); cell.setBorder(NO_BORDER); SimpleCell tmp = new SimpleCell(CELL); tmp.setSpacing_left(spacing_left); tmp.setSpacing_right(spacing_right); tmp.setSpacing_top(spacing_top); tmp.setSpacing_bottom(spacing_bottom); tmp.cloneNonPositionParameters(rowAttributes); tmp.softCloneNonPositionParameters(this); cell.setCellEvent(tmp); cell.setHorizontalAlignment(rowAttributes.horizontalAlignment); cell.setVerticalAlignment(rowAttributes.verticalAlignment); cell.setUseAscender(rowAttributes.useAscender); cell.setUseBorderPadding(rowAttributes.useBorderPadding); cell.setUseDescender(rowAttributes.useDescender); cell.setColspan(colspan); if (horizontalAlignment != Element.ALIGN_UNDEFINED) { cell.setHorizontalAlignment(horizontalAlignment); } if (verticalAlignment != Element.ALIGN_UNDEFINED) { cell.setVerticalAlignment(verticalAlignment); } if (useAscender) { cell.setUseAscender(useAscender); } if (useBorderPadding) { cell.setUseBorderPadding(useBorderPadding); } if (useDescender) { cell.setUseDescender(useDescender); } float p; float sp_left = spacing_left; if (Float.isNaN(sp_left)) { sp_left = 0f; } float sp_right = spacing_right; if (Float.isNaN(sp_right)) { sp_right = 0f; } float sp_top = spacing_top; if (Float.isNaN(sp_top)) { sp_top = 0f; } float sp_bottom = spacing_bottom; if (Float.isNaN(sp_bottom)) { sp_bottom = 0f; } p = padding_left; if (Float.isNaN(p)) { p = 0f; } cell.setPaddingLeft(p + sp_left); p = padding_right; if (Float.isNaN(p)) { p = 0f; } cell.setPaddingRight(p + sp_right); p = padding_top; if (Float.isNaN(p)) { p = 0f; } cell.setPaddingTop(p + sp_top); p = padding_bottom; if (Float.isNaN(p)) { p = 0f; } cell.setPaddingBottom(p + sp_bottom); Element element; for (Iterator i = content.iterator(); i.hasNext();) { element = (Element) i.next(); cell.addElement(element); } return cell; }
Example 19
Source File: PdfDataEntryFormUtil.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static PdfPCell getPdfPCell( float minHeight, int cellContentType, boolean hasBorder ) { PdfPCell cell = new PdfPCell(); cell.setMinimumHeight( minHeight ); if( hasBorder ) { cell.setBorderWidth( 0.1f ); cell.setBorderColor( COLOR_CELLBORDER ); } else { cell.setBorder( Rectangle.NO_BORDER ); } cell.setPadding( 2.0f ); switch ( cellContentType ) { case CELL_COLUMN_TYPE_ENTRYFIELD: cell.setHorizontalAlignment( Element.ALIGN_CENTER ); cell.setVerticalAlignment( Element.ALIGN_MIDDLE ); break; case CELL_COLUMN_TYPE_HEADER: cell.setHorizontalAlignment( Element.ALIGN_CENTER ); cell.setVerticalAlignment( Element.ALIGN_MIDDLE ); break; case CELL_COLUMN_TYPE_LABEL: cell.setHorizontalAlignment( Element.ALIGN_RIGHT ); cell.setVerticalAlignment( Element.ALIGN_TOP ); default: break; } return cell; }
Example 20
Source File: ExampleEAN128Test.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Example Barcode EAN128. */ @Test public void main() throws Exception { // step 1 Document document = new Document(); // step 2 PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("ean128.pdf")); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); PdfPTable pageTot = new PdfPTable(1); pageTot.getDefaultCell().setPadding(0f); pageTot.getDefaultCell().setBorder(Rectangle.NO_BORDER); pageTot.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); pageTot.setWidthPercentage(100f); // Data for the barcode : it is composed of 3 blocks whith AI 402, 90 // and 421 // The blocks whith the type 402 and 90 are of variable size so you must // put a FNC1 // to delimitate the block String code402 = "24132399420058289" + Barcode128.FNC1; String code90 = "3700000050" + Barcode128.FNC1; String code421 = "422356"; String data = code402 + code90 + code421; PdfPTable cell = new PdfPTable(1); cell.getDefaultCell().setBorder(Rectangle.NO_BORDER); cell.getDefaultCell().setPadding(0f); PdfPCell info = new PdfPCell(new Phrase("Barcode EAN 128")); info.setBorder(Rectangle.NO_BORDER); pageTot.addCell(info); Barcode128 shipBarCode = new Barcode128(); shipBarCode.setX(0.75f); shipBarCode.setN(1.5f); shipBarCode.setChecksumText(true); shipBarCode.setGenerateChecksum(true); shipBarCode.setSize(10f); shipBarCode.setTextAlignment(Element.ALIGN_CENTER); shipBarCode.setBaseline(10f); shipBarCode.setCode(data); shipBarCode.setBarHeight(50f); Image imgShipBarCode = shipBarCode.createImageWithBarcode(cb, Color.black, Color.blue); PdfPCell shipment = new PdfPCell(new Phrase(new Chunk(imgShipBarCode, 0, 0))); shipment.setFixedHeight(shipBarCode.getBarcodeSize().getHeight() + 16f); shipment.setPaddingTop(5f); shipment.setPaddingBottom(10f); shipment.setBorder(Rectangle.BOX); shipment.setVerticalAlignment(Element.ALIGN_TOP); shipment.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addCell(shipment); pageTot.addCell(cell); document.add(pageTot); // step 5 document.close(); }