Package com.itextpdf.text

Examples of com.itextpdf.text.Image


      final ChainedProperties chain,
      final DocListener document,
      final ImageProvider img_provider,
      final HashMap<String, Image> img_store,
      final String img_baseurl) throws DocumentException, IOException {
    Image img = null;
    // getting the image using an image provider
    if (img_provider != null)
      img = img_provider.getImage(src, attrs, chain, document);
    // getting the image from an image store
    if (img == null && img_store != null) {
      Image tim = img_store.get(src);
      if (tim != null)
        img = Image.getInstance(tim);
    }
    if (img != null)
      return img;
View Full Code Here


     */
    public void addElement(Element element) {
        if (element == null)
            return;
        if (element instanceof Image) {
            Image img = (Image)element;
            PdfPTable t = new PdfPTable(1);
            float w = img.getWidthPercentage();
            if (w == 0) {
                t.setTotalWidth(img.getScaledWidth());
                t.setLockedWidth(true);
            }
            else
                t.setWidthPercentage(w);
            t.setSpacingAfter(img.getSpacingAfter());
            t.setSpacingBefore(img.getSpacingBefore());
            switch (img.getAlignment()) {
                case Image.LEFT:
                    t.setHorizontalAlignment(Element.ALIGN_LEFT);
                    break;
                case Image.RIGHT:
                    t.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    break;
                default:
                    t.setHorizontalAlignment(Element.ALIGN_CENTER);
                    break;
            }
            PdfPCell c = new PdfPCell(img, true);
            c.setPadding(0);
            c.setBorder(img.getBorder());
            c.setBorderColor(img.getBorderColor());
            c.setBorderWidth(img.getBorderWidth());
            c.setBackgroundColor(img.getBackgroundColor());
            t.addCell(c);
            element = t;
        }
        if (element.type() == Element.CHUNK) {
          element = new Paragraph((Chunk)element);
View Full Code Here

        return overflow;
    }

    private void addToLine(PdfChunk chunk) {
        if (chunk.changeLeading && chunk.isImage()) {
          Image img = chunk.getImage();
          float f = img.getScaledHeight() + chunk.getImageOffsetY()
            + img.getBorderWidthTop() + img.getSpacingBefore();
          if (f > height) height = f;
        }
      line.add(chunk);
    }
View Full Code Here

            chunk = line.get(k);
            if (!chunk.isImage()) {
                normal_leading = Math.max(chunk.font().size(), normal_leading);
            }
            else {
              Image img = chunk.getImage();
              float height = img.getScaledHeight() + chunk.getImageOffsetY() + img.getSpacingBefore();
              image_leading = Math.max(height, image_leading);
            }
        }
        return new float[]{normal_leading, image_leading};
    }
View Full Code Here

            case GRAPHIC_AND_DESCRIPTION:
                ct2 = new ColumnText(t);
                ct2.setRunDirection(runDirection);
                ct2.setSimpleColumn(signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), 0, Element.ALIGN_RIGHT);

                Image im = Image.getInstance(signatureGraphic);
                im.scaleToFit(signatureRect.getWidth(), signatureRect.getHeight());

                Paragraph p = new Paragraph();
                // must calculate the point to draw from to make image appear in middle of column
                float x = 0;
                // experimentation found this magic number to counteract Adobe's signature graphic, which
                // offsets the y co-ordinate by 15 units
                float y = -im.getScaledHeight() + 15;

                x = x + (signatureRect.getWidth() - im.getScaledWidth()) / 2;
                y = y - (signatureRect.getHeight() - im.getScaledHeight()) / 2;
                p.add(new Chunk(im, x + (signatureRect.getWidth() - im.getScaledWidth()) / 2, y, false));
                ct2.addElement(p);
                ct2.go();
                break;
            case GRAPHIC:
                ct2 = new ColumnText(t);
                ct2.setRunDirection(runDirection);
                ct2.setSimpleColumn(signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), 0, Element.ALIGN_RIGHT);

                im = Image.getInstance(signatureGraphic);
                im.scaleToFit(signatureRect.getWidth(), signatureRect.getHeight());

                p = new Paragraph();
                // must calculate the point to draw from to make image appear in middle of column
                x = 0;
                // experimentation found this magic number to counteract Adobe's signature graphic, which
                // offsets the y co-ordinate by 15 units
                y = -im.getScaledHeight() + 15;

                x = x + (signatureRect.getWidth() - im.getScaledWidth()) / 2;
                y = y - (signatureRect.getHeight() - im.getScaledHeight()) / 2;
                p.add(new Chunk(im, x, y, false));
                ct2.addElement(p);
                ct2.go();
                break;
            default:
View Full Code Here

        continue;
      float currentMaxHeight = maxHeight + extraHeights[k];
     
      writeBorderAndBackground(xPos, yPos, currentMaxHeight, cell, canvases);

      Image img = cell.getImage();
     
      float tly = cell.getTop() + yPos - cell.getEffectivePaddingTop();
      if (cell.getHeight() <= currentMaxHeight) {
        switch (cell.getVerticalAlignment()) {
        case Element.ALIGN_BOTTOM:
          tly = cell.getTop() + yPos - currentMaxHeight + cell.getHeight()
              - cell.getEffectivePaddingTop();
          break;
        case Element.ALIGN_MIDDLE:
          tly = cell.getTop() + yPos + (cell.getHeight() - currentMaxHeight) / 2
              - cell.getEffectivePaddingTop();
          break;
        default:
          break;
        }
      }
      if (img != null) {
                if (cell.getRotation() != 0) {
                    img = Image.getInstance(img);
                    img.setRotation(img.getImageRotation() + (float)(cell.getRotation() * Math.PI / 180.0));
                }
        boolean vf = false;
        if (cell.getHeight() > currentMaxHeight) {
          img.scalePercent(100);
          float scale = (currentMaxHeight - cell.getEffectivePaddingTop() - cell
              .getEffectivePaddingBottom())
              / img.getScaledHeight();
          img.scalePercent(scale * 100);
          vf = true;
        }
        float left = cell.getLeft() + xPos
            + cell.getEffectivePaddingLeft();
        if (vf) {
          switch (cell.getHorizontalAlignment()) {
          case Element.ALIGN_CENTER:
            left = xPos
                + (cell.getLeft() + cell.getEffectivePaddingLeft()
                    + cell.getRight()
                    - cell.getEffectivePaddingRight() - img
                    .getScaledWidth()) / 2;
            break;
          case Element.ALIGN_RIGHT:
            left = xPos + cell.getRight()
                - cell.getEffectivePaddingRight()
                - img.getScaledWidth();
            break;
          default:
            break;
          }
          tly = cell.getTop() + yPos - cell.getEffectivePaddingTop();
        }
        img.setAbsolutePosition(left, tly - img.getScaledHeight());
        try {
          canvases[PdfPTable.TEXTCANVAS].addImage(img);
        } catch (DocumentException e) {
          throw new ExceptionConverter(e);
        }
View Full Code Here

        }
        continue;
      }
      fixHs[k] = cell.getFixedHeight();
      minHs[k] = cell.getMinimumHeight();
      Image img = cell.getImage();
      PdfPCell newCell = new PdfPCell(cell);
      if (img != null) {
        if (newHeight > cell.getEffectivePaddingBottom() + cell.getEffectivePaddingTop() + 2) {
          newCell.setPhrase(null);
          allEmpty = false;
View Full Code Here

                lastSplit = currentChar;
            if (width - charWidth < 0) {
              // If the chunk is an image and it is the first one in line, check if resize requested
              // If so, resize to fit the current line width
              if (lastValidChunk == null && ck.isImage()) {
                Image img = ck.getImage();
                if (img.isScaleToFitLineWhenOverflow()) {
                  float scalePercent = width / img.getWidth() * 100;
                  img.scalePercent(scalePercent);
                  charWidth = width;
                }
              }
            }
            if (width - charWidth < 0)
View Full Code Here

                    if (chunk.isAttribute(Chunk.CHAR_SPACING)) {
                      Float cs = (Float) chunk.getAttribute(Chunk.CHAR_SPACING);
            text.setCharacterSpacing(cs.floatValue());
          }
                    if (chunk.isImage()) {
                        Image image = chunk.getImage();
                        float matrix[] = image.matrix();
                        matrix[Image.CX] = xMarker + chunk.getImageOffsetX() - matrix[Image.CX];
                        matrix[Image.CY] = yMarker + chunk.getImageOffsetY() - matrix[Image.CY];
                        graphics.addImage(image, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
                        text.moveText(xMarker + lastBaseFactor + image.getScaledWidth() - text.getXTLM(), 0);
                    }
                }
                xMarker += width;
                ++chunkStrokeIdx;
            }
View Full Code Here

   * @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())
        setBottom(getTop() - getFixedHeight());
View Full Code Here

TOP

Related Classes of com.itextpdf.text.Image

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.