List of usage examples for com.itextpdf.text Chunk isEmpty
public boolean isEmpty()
Chunk
is empty. From source file:edu.harvard.mcz.precapture.ui.ContainerLabel.java
License:Open Source License
/** * /*from ww w. j a va 2 s . com*/ * @return a PDF paragraph cell containing a text encoding of the fields in this set. */ public PdfPCell toPDFCell(LabelDefinitionType printDefinition) { PdfPCell cell = new PdfPCell(); ; if (printDefinition.getTextOrentation().toString().toLowerCase() .equals(TextOrentationType.VERTICAL.toString().toLowerCase())) { log.debug("Print orientation of text is Vertical"); cell.setRotation(90); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); } cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.disableBorderSide(PdfPCell.RIGHT); cell.setPaddingLeft(3); cell.setNoWrap(false); int leading = (int) (fields.get(0).getField().getFontSize() + printDefinition.getFontDelta()) - 1; Paragraph higher = new Paragraph(leading, "", new Font(Font.FontFamily.TIMES_ROMAN, fields.get(0).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL)); higher.setSpacingBefore(0); higher.setSpacingAfter(0); boolean added = false; boolean hasContent = false; for (int i = 0; i < fields.size(); i++) { log.debug(i); if (fields.get(i).getField().isNewLine() || (i == fields.size() - 1)) { if (!higher.isEmpty()) { log.debug(higher.getContent()); cell.addElement(higher); } leading = (int) (fields.get(i).getField().getFontSize() + printDefinition.getFontDelta()) - 1; higher = new Paragraph(leading, "", new Font(Font.FontFamily.TIMES_ROMAN, fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL)); higher.setSpacingBefore(0); higher.setSpacingAfter(0); added = false; hasContent = false; } log.debug(fields.get(i).getTextField().getText().trim()); Chunk chunk = new Chunk(fields.get(i).getTextField().getText().trim()); if (fields.get(i).getField().isUseItalic()) { chunk.setFont(new Font(Font.FontFamily.TIMES_ROMAN, fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.ITALIC)); } else { chunk.setFont(new Font(Font.FontFamily.TIMES_ROMAN, fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL)); } if (!chunk.isEmpty()) { hasContent = true; higher.add(chunk); log.debug(fields.get(i).getField().getSuffix()); if (fields.get(i).getField().getSuffix() != null && fields.get(i).getField().getSuffix().length() > 0) { higher.add(new Chunk(fields.get(i).getField().getSuffix())); } if (fields.get(i).getTextField().getText().trim().length() > 0) { // add a trailing space as a separator if there was something to separate. higher.add(new Chunk(" ")); } } } if (!added) { log.debug(higher.getContent()); cell.addElement(higher); } String extraText = PreCaptureSingleton.getInstance().getProperties().getProperties() .getProperty(PreCaptureProperties.KEY_EXTRAHUMANTEXT); if (extraText != null && extraText.length() > 0) { log.debug(extraText); cell.addElement(new Chunk(extraText)); } return cell; }