Пример #1
0
 /**
  * Constructs a <CODE>PdfPCell</CODE> with a <CODE>Phrase</CODE>. The default padding is 2.
  *
  * @param phrase the text
  */
 public PdfPCell(Phrase phrase) {
   super(0, 0, 0, 0);
   borderWidth = 0.5f;
   border = BOX;
   column.addText(this.phrase = phrase);
   column.setLeading(0, 1);
 }
Пример #2
0
 /**
  * Constructs a <CODE>PdfPCell</CODE> with a <CODE>PdfPtable</CODE>. This constructor allows
  * nested tables.
  *
  * @param table The <CODE>PdfPTable</CODE>
  * @param style The style to apply to the cell (you could use getDefaultCell())
  * @since 2.1.0
  */
 public PdfPCell(PdfPTable table, PdfPCell style) {
   super(0, 0, 0, 0);
   borderWidth = 0.5f;
   border = BOX;
   column.setLeading(0, 1);
   this.table = table;
   table.setWidthPercentage(100);
   table.setExtendLastRow(true);
   column.addElement(table);
   if (style != null) {
     cloneNonPositionParameters(style);
     verticalAlignment = style.verticalAlignment;
     paddingLeft = style.paddingLeft;
     paddingRight = style.paddingRight;
     paddingTop = style.paddingTop;
     paddingBottom = style.paddingBottom;
     colspan = style.colspan;
     rowspan = style.rowspan;
     cellEvent = style.cellEvent;
     useDescender = style.useDescender;
     useBorderPadding = style.useBorderPadding;
     rotation = style.rotation;
   } else {
     setPadding(0);
   }
 }
Пример #3
0
 void setTable(PdfPTable table) {
   this.table = table;
   column.setText(null);
   image = null;
   if (table != null) {
     table.setExtendLastRow(verticalAlignment == Element.ALIGN_TOP);
     column.addElement(table);
     table.setWidthPercentage(100);
   }
 }
 /**
  * Add an element to be rendered in a column. Note that you can only add a <CODE>Phrase</CODE> or
  * a <CODE>Chunk</CODE> if the columns are not all simple. This is an underlying restriction in
  * {@link com.spilowagie.text.pdf.ColumnText}
  *
  * @param element element to add
  * @throws DocumentException if element can't be added
  */
 public void addElement(Element element) throws DocumentException {
   if (simple) {
     columnText.addElement(element);
   } else if (element instanceof Phrase) {
     columnText.addText((Phrase) element);
   } else if (element instanceof Chunk) {
     columnText.addText((Chunk) element);
   } else {
     throw new DocumentException(
         "Can't add " + element.getClass() + " to MultiColumnText with complex columns");
   }
 }
Пример #5
0
 /**
  * Constructs a <CODE>PdfPCell</CODE> with an <CODE>Image</CODE>. The default padding is 0.25 for
  * a border width of 0.5.
  *
  * @param image the <CODE>Image</CODE>
  * @param fit <CODE>true</CODE> to fit the image to the cell
  */
 public PdfPCell(Image image, boolean fit) {
   super(0, 0, 0, 0);
   borderWidth = 0.5f;
   border = BOX;
   column.setLeading(0, 1);
   if (fit) {
     this.image = image;
     setPadding(borderWidth / 2);
   } else {
     image.setScaleToFitLineWhenOverflow(false);
     column.addText(this.phrase = new Phrase(new Chunk(image, 0, 0, true)));
     setPadding(0);
   }
 }
Пример #6
0
 /**
  * Adds an iText element to the cell.
  *
  * @param element
  */
 public void addElement(Element element) {
   if (table != null) {
     table = null;
     column.setText(null);
   }
   if (element instanceof PdfPTable) {
     ((PdfPTable) element).setSplitLate(false);
   } else if (element instanceof PdfDiv) {
     for (Element divChildElement : ((PdfDiv) element).getContent()) {
       if (divChildElement instanceof PdfPTable) {
         ((PdfPTable) divChildElement).setSplitLate(false);
       }
     }
   }
   column.addElement(element);
 }
Пример #7
0
 /**
  * Constructs a deep copy of a <CODE>PdfPCell</CODE>.
  *
  * @param cell the <CODE>PdfPCell</CODE> to duplicate
  */
 public PdfPCell(PdfPCell cell) {
   super(cell.llx, cell.lly, cell.urx, cell.ury);
   cloneNonPositionParameters(cell);
   verticalAlignment = cell.verticalAlignment;
   paddingLeft = cell.paddingLeft;
   paddingRight = cell.paddingRight;
   paddingTop = cell.paddingTop;
   paddingBottom = cell.paddingBottom;
   phrase = cell.phrase;
   fixedHeight = cell.fixedHeight;
   minimumHeight = cell.minimumHeight;
   noWrap = cell.noWrap;
   colspan = cell.colspan;
   rowspan = cell.rowspan;
   if (cell.table != null) table = new PdfPTable(cell.table);
   image = Image.getInstance(cell.image);
   cellEvent = cell.cellEvent;
   useDescender = cell.useDescender;
   column = ColumnText.duplicate(cell.column);
   useBorderPadding = cell.useBorderPadding;
   rotation = cell.rotation;
   id = cell.id;
   role = cell.role;
   if (cell.accessibleAttributes != null)
     accessibleAttributes = new HashMap<PdfName, PdfObject>(cell.accessibleAttributes);
   headers = cell.headers;
 }
Пример #8
0
 /**
  * Returns the height of the cell.
  *
  * @return the height of the cell
  * @since 3.0.0
  */
 public float getMaxHeight() {
   boolean pivoted = getRotation() == 90 || getRotation() == 270;
   Image img = getImage();
   if (img != null) {
     img.scalePercent(100);
     float refWidth = pivoted ? img.getScaledHeight() : img.getScaledWidth();
     float scale =
         (getRight() - getEffectivePaddingRight() - getEffectivePaddingLeft() - getLeft())
             / refWidth;
     img.scalePercent(scale * 100);
     float refHeight = pivoted ? img.getScaledWidth() : img.getScaledHeight();
     setBottom(getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - refHeight);
   } else {
     if ((pivoted && hasFixedHeight()) || getColumn() == null)
       setBottom(getTop() - getFixedHeight());
     else {
       ColumnText ct = ColumnText.duplicate(getColumn());
       float right, top, left, bottom;
       if (pivoted) {
         right = PdfPRow.RIGHT_LIMIT;
         top = getRight() - getEffectivePaddingRight();
         left = 0;
         bottom = getLeft() + getEffectivePaddingLeft();
       } else {
         right = isNoWrap() ? PdfPRow.RIGHT_LIMIT : getRight() - getEffectivePaddingRight();
         top = getTop() - getEffectivePaddingTop();
         left = getLeft() + getEffectivePaddingLeft();
         bottom =
             hasFixedHeight()
                 ? getTop() + getEffectivePaddingBottom() - getFixedHeight()
                 : PdfPRow.BOTTOM_LIMIT;
       }
       PdfPRow.setColumn(ct, left, bottom, right, top);
       try {
         ct.go(true);
       } catch (DocumentException e) {
         throw new ExceptionConverter(e);
       }
       if (pivoted)
         setBottom(
             getTop()
                 - getEffectivePaddingTop()
                 - getEffectivePaddingBottom()
                 - ct.getFilledWidth());
       else {
         float yLine = ct.getYLine();
         if (isUseDescender()) yLine += ct.getDescender();
         setBottom(yLine - getEffectivePaddingBottom());
       }
     }
   }
   float height = getHeight();
   if (height == getEffectivePaddingTop() + getEffectivePaddingBottom()) height = 0;
   if (hasFixedHeight()) height = getFixedHeight();
   else if (hasMinimumHeight() && height < getMinimumHeight()) height = getMinimumHeight();
   return height;
 }
Пример #9
0
 /**
  * Gets the arabic shaping options.
  *
  * @return the arabic shaping options
  */
 public int getArabicOptions() {
   return column.getArabicOptions();
 }
Пример #10
0
 /**
  * Setter for property image.
  *
  * @param image New value of property image.
  */
 public void setImage(Image image) {
   column.setText(null);
   table = null;
   this.image = image;
 }
 /**
  * Sets the arabic shaping options. The option can be AR_NOVOWEL, AR_COMPOSEDTASHKEEL and AR_LIG.
  *
  * @param arabicOptions the arabic shaping options
  */
 public void setArabicOptions(int arabicOptions) {
   columnText.setArabicOptions(arabicOptions);
 }
 /**
  * Sets the ratio between the extra word spacing and the extra character spacing when the text is
  * fully justified. Extra word spacing will grow <CODE>spaceCharRatio</CODE> times more than extra
  * character spacing. If the ratio is <CODE>PdfWriter.NO_SPACE_CHAR_RATIO</CODE> then the extra
  * character spacing will be zero.
  *
  * @param spaceCharRatio the ratio between the extra word spacing and the extra character spacing
  */
 public void setSpaceCharRatio(float spaceCharRatio) {
   columnText.setSpaceCharRatio(spaceCharRatio);
 }
 /**
  * Adds a <CODE>Phrase</CODE> to the current text array. Will not have any effect if addElement()
  * was called before.
  *
  * @param phrase the text
  * @since 2.1.5
  */
 public void addText(Phrase phrase) {
   columnText.addText(phrase);
 }
Пример #14
0
 /**
  * Gets state of first line height based on max ascender
  *
  * @return true if an ascender is to be used.
  */
 public boolean isUseAscender() {
   return column.isUseAscender();
 }
Пример #15
0
 /**
  * Sets the extra space between paragraphs.
  *
  * @param extraParagraphSpace the extra space between paragraphs
  */
 public void setExtraParagraphSpace(float extraParagraphSpace) {
   column.setExtraParagraphSpace(extraParagraphSpace);
 }
Пример #16
0
 /**
  * Gets the extra space between paragraphs.
  *
  * @return the extra space between paragraphs
  */
 public float getExtraParagraphSpace() {
   return column.getExtraParagraphSpace();
 }
Пример #17
0
 /**
  * Gets the variable leading.
  *
  * @return the leading
  */
 public float getMultipliedLeading() {
   return column.getMultipliedLeading();
 }
Пример #18
0
 /**
  * Gets the fixed leading.
  *
  * @return the leading
  */
 public float getLeading() {
   return column.getLeading();
 }
Пример #19
0
 /**
  * Enables/ Disables adjustment of first line height based on max ascender.
  *
  * @param useAscender adjust height if true
  */
 public void setUseAscender(boolean useAscender) {
   column.setUseAscender(useAscender);
 }
Пример #20
0
 /**
  * Sets the following paragraph lines indent.
  *
  * @param indent the indent
  */
 public void setFollowingIndent(float indent) {
   column.setFollowingIndent(indent);
 }
 /**
  * Copy the parameters from the specified ColumnText to use when rendering. Parameters like <CODE>
  * setArabicOptions</CODE> must be set in this way.
  *
  * @param sourceColumn
  */
 public void useColumnParams(ColumnText sourceColumn) {
   // note that canvas will be overwritten later
   columnText.setSimpleVars(sourceColumn);
 }
Пример #22
0
 /**
  * Gets the following paragraph lines indent.
  *
  * @return the indent
  */
 public float getFollowingIndent() {
   return column.getFollowingIndent();
 }
 /**
  * Adds a <CODE>Chunk</CODE> to the current text array. Will not have any effect if addElement()
  * was called before.
  *
  * @param chunk the text
  * @since 2.1.5
  */
 public void addText(Chunk chunk) {
   columnText.addText(chunk);
 }
Пример #24
0
 /**
  * Sets the right paragraph lines indent.
  *
  * @param indent the indent
  */
 public void setRightIndent(float indent) {
   column.setRightIndent(indent);
 }
  /**
   * Write out the columns. After writing, use {@link #isOverflow()} to see if all text was written.
   *
   * @param canvas PdfContentByte to write with
   * @param document document to write to (only used to get page limit info)
   * @param documentY starting y position to begin writing at
   * @return the current height (y position) after writing the columns
   * @throws DocumentException on error
   */
  public float write(PdfContentByte canvas, PdfDocument document, float documentY)
      throws DocumentException {
    this.document = document;
    columnText.setCanvas(canvas);
    if (columnDefs.isEmpty()) {
      throw new DocumentException("MultiColumnText has no columns");
    }
    overflow = false;
    float currentHeight = 0;
    boolean done = false;
    try {
      while (!done) {
        if (top == AUTOMATIC) {
          top =
              document.getVerticalPosition(
                  true); // RS - 07/07/2005 - Get current doc writing position for top of columns on
          // new page.
        } else if (nextY == AUTOMATIC) {
          nextY =
              document.getVerticalPosition(
                  true); // RS - 07/07/2005 - - Get current doc writing position for top of columns
          // on new page.
        }
        ColumnDef currentDef = (ColumnDef) columnDefs.get(getCurrentColumn());
        columnText.setYLine(top);

        float[] left = currentDef.resolvePositions(Rectangle.LEFT);
        float[] right = currentDef.resolvePositions(Rectangle.RIGHT);
        if (document.isMarginMirroring() && document.getPageNumber() % 2 == 0) {
          float delta = document.rightMargin() - document.left();
          left = (float[]) left.clone();
          right = (float[]) right.clone();
          for (int i = 0; i < left.length; i += 2) {
            left[i] -= delta;
          }
          for (int i = 0; i < right.length; i += 2) {
            right[i] -= delta;
          }
        }

        currentHeight = Math.max(currentHeight, getHeight(left, right));

        if (currentDef.isSimple()) {
          columnText.setSimpleColumn(left[2], left[3], right[0], right[1]);
        } else {
          columnText.setColumns(left, right);
        }

        int result = columnText.go();
        if ((result & ColumnText.NO_MORE_TEXT) != 0) {
          done = true;
          top = columnText.getYLine();
        } else if (shiftCurrentColumn()) {
          top = nextY;
        } else { // check if we are done because of height
          totalHeight += currentHeight;
          if ((desiredHeight != AUTOMATIC) && (totalHeight >= desiredHeight)) {
            overflow = true;
            break;
          } else { // need to start new page and reset the columns
            documentY = nextY;
            newPage();
            currentHeight = 0;
          }
        }
      }
    } catch (DocumentException ex) {
      ex.printStackTrace();
      throw ex;
    }
    if (desiredHeight == AUTOMATIC && columnDefs.size() == 1) {
      currentHeight = documentY - columnText.getYLine();
    }
    return currentHeight;
  }
Пример #26
0
 /**
  * Gets the right paragraph lines indent.
  *
  * @return the indent
  */
 public float getRightIndent() {
   return column.getRightIndent();
 }
 /**
  * Sets the run direction.
  *
  * @param runDirection the run direction
  */
 public void setRunDirection(int runDirection) {
   columnText.setRunDirection(runDirection);
 }
Пример #28
0
 /**
  * Gets the space/character extra spacing ratio for fully justified text.
  *
  * @return the space/character extra spacing ratio
  */
 public float getSpaceCharRatio() {
   return column.getSpaceCharRatio();
 }
 /**
  * Sets the default alignment
  *
  * @param alignment the default alignment
  */
 public void setAlignment(int alignment) {
   columnText.setAlignment(alignment);
 }
Пример #30
0
 /**
  * Gets the run direction of the text content in the cell
  *
  * @return One of the following values: PdfWriter.RUN_DIRECTION_DEFAULT,
  *     PdfWriter.RUN_DIRECTION_NO_BIDI, PdfWriter.RUN_DIRECTION_LTR or
  *     PdfWriter.RUN_DIRECTION_RTL.
  */
 public int getRunDirection() {
   return column.getRunDirection();
 }