Package com.lowagie.text

Examples of com.lowagie.text.Chunk


            setPadding(borderWidth / 2);
        }
        else {
            borderWidth = 0.5f;
            border = BOX;
            column.addText(this.phrase = new Phrase(new Chunk(image, 0, 0)));
            column.setLeading(0, 1);
            setPadding(0);
        }
    }
View Full Code Here


      final BaseFontFontMetrics fontMetrics = metaData.getBaseFontFontMetrics
          (fontName, fontSize, bold, italic, "utf-8", false, false);
      final BaseFont baseFont = fontMetrics.getBaseFont();
      final Font font = new Font(baseFont, (float) fontSize, style, textColor);
      final Chunk c = new Chunk(text, font);
      if (backgroundColor != null)
      {
        c.setBackground(backgroundColor);
      }
      target.add(c);
    }
View Full Code Here

  }


  protected void writePageAnchor(int pageIndex) throws DocumentException {
    Map pdfFontAttrs = getDefaultPdfFontAttributes();
    Chunk chunk;
    if (pdfFontAttrs == null)
    {
      chunk = new Chunk(" ");
    }
    else
    {
      // no underline or strikethrough
      Font pdfFont = getFont(pdfFontAttrs, getLocale(), false);
      chunk = new Chunk(" ", pdfFont);
    }
   
    chunk.setLocalDestination(JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + (pageIndex + 1));

    tagHelper.startPageAnchor();
   
    ColumnText colText = new ColumnText(pdfContentByte);
    colText.setSimpleColumn(
View Full Code Here

    if (renderer != null)
    {
      int xoffset = 0;
      int yoffset = 0;

      Chunk chunk = null;

      float scaledWidth = availableImageWidth;
      float scaledHeight = availableImageHeight;

      if (renderer.getType() == JRRenderable.TYPE_IMAGE)
      {
        com.lowagie.text.Image image = null;

        float xalignFactor = getXAlignFactor(printImage);
        float yalignFactor = getYAlignFactor(printImage);

        switch(printImage.getScaleImageValue())
        {
          case CLIP :
          {
            // Image load might fail, from given image data.
            // Better to test and replace the renderer now, in case of lazy load error.
            renderer =
              JRImageRenderer.getOnErrorRendererForDimension(
                renderer,
                printImage.getOnErrorTypeValue()
                );
            if (renderer == null)
            {
              break;
            }
           
            int normalWidth = availableImageWidth;
            int normalHeight = availableImageHeight;

            Dimension2D dimension = renderer.getDimension();
            if (dimension != null)
            {
              normalWidth = (int)dimension.getWidth();
              normalHeight = (int)dimension.getHeight();
            }

            xoffset = (int)(xalignFactor * (availableImageWidth - normalWidth));
            yoffset = (int)(yalignFactor * (availableImageHeight - normalHeight));

            int minWidth = Math.min(normalWidth, availableImageWidth);
            int minHeight = Math.min(normalHeight, availableImageHeight);

            BufferedImage bi =
              new BufferedImage(minWidth, minHeight, BufferedImage.TYPE_INT_ARGB);

            Graphics2D g = bi.createGraphics();
            if (printImage.getModeValue() == ModeEnum.OPAQUE)
            {
              g.setColor(printImage.getBackcolor());
              g.fillRect(0, 0, minWidth, minHeight);
            }
            renderer.render(
              g,
              new java.awt.Rectangle(
                (xoffset > 0 ? 0 : xoffset),
                (yoffset > 0 ? 0 : yoffset),
                normalWidth,
                normalHeight
                )
              );
            g.dispose();

            xoffset = (xoffset < 0 ? 0 : xoffset);
            yoffset = (yoffset < 0 ? 0 : yoffset);

            //awtImage = bi.getSubimage(0, 0, minWidth, minHeight);

            //image = com.lowagie.text.Image.getInstance(awtImage, printImage.getBackcolor());
            image = com.lowagie.text.Image.getInstance(bi, null);

            break;
          }
          case FILL_FRAME :
          {
            if (printImage.isUsingCache() && loadedImagesMap.containsKey(renderer))
            {
              image = (com.lowagie.text.Image)loadedImagesMap.get(renderer);
            }
            else
            {
              try
              {
                image = com.lowagie.text.Image.getInstance(renderer.getImageData());
                imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
              }
              catch(Exception e)
              {
                JRImageRenderer tmpRenderer =
                  JRImageRenderer.getOnErrorRendererForImage(
                    JRImageRenderer.getInstance(renderer.getImageData()),
                    printImage.getOnErrorTypeValue()
                    );
                if (tmpRenderer == null)
                {
                  break;
                }
                java.awt.Image awtImage = tmpRenderer.getImage();
                image = com.lowagie.text.Image.getInstance(awtImage, null);
              }

              if (printImage.isUsingCache())
              {
                loadedImagesMap.put(renderer, image);
              }
            }

            image.scaleAbsolute(availableImageWidth, availableImageHeight);
            break;
          }
          case RETAIN_SHAPE :
          default :
          {
            if (printImage.isUsingCache() && loadedImagesMap.containsKey(renderer))
            {
              image = (com.lowagie.text.Image)loadedImagesMap.get(renderer);
            }
            else
            {
              try
              {
                image = com.lowagie.text.Image.getInstance(renderer.getImageData());
                imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
              }
              catch(Exception e)
              {
                JRImageRenderer tmpRenderer =
                  JRImageRenderer.getOnErrorRendererForImage(
                    JRImageRenderer.getInstance(renderer.getImageData()),
                    printImage.getOnErrorTypeValue()
                    );
                if (tmpRenderer == null)
                {
                  break;
                }
                java.awt.Image awtImage = tmpRenderer.getImage();
                image = com.lowagie.text.Image.getInstance(awtImage, null);
              }

              if (printImage.isUsingCache())
              {
                loadedImagesMap.put(renderer, image);
              }
            }

            image.scaleToFit(availableImageWidth, availableImageHeight);

            xoffset = (int)(xalignFactor * (availableImageWidth - image.getPlainWidth()));
            yoffset = (int)(yalignFactor * (availableImageHeight - image.getPlainHeight()));

            xoffset = (xoffset < 0 ? 0 : xoffset);
            yoffset = (yoffset < 0 ? 0 : yoffset);

            break;
          }
        }

        if (image != null)
        {
          chunk = new Chunk(image, 0, 0);

          scaledWidth = image.getScaledWidth();
          scaledHeight = image.getScaledHeight();
        }
      }
      else
      {
        double normalWidth = availableImageWidth;
        double normalHeight = availableImageHeight;

        double displayWidth = availableImageWidth;
        double displayHeight = availableImageHeight;

        double ratioX = 1f;
        double ratioY = 1f;
       
        Rectangle2D clip = null;

        Dimension2D dimension = renderer.getDimension();
        if (dimension != null)
        {
          normalWidth = dimension.getWidth();
          normalHeight = dimension.getHeight();
          displayWidth = normalWidth;
          displayHeight = normalHeight;
         
          float xalignFactor = getXAlignFactor(printImage);
          float yalignFactor = getYAlignFactor(printImage);

          switch (printImage.getScaleImageValue())
          {
            case CLIP:
            {
              xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth));
              yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight));
              clip =
                new Rectangle2D.Double(
                  - xoffset,
                  - yoffset,
                  availableImageWidth,
                  availableImageHeight
                  );
              break;
            }
            case FILL_FRAME:
            {
              ratioX = availableImageWidth / normalWidth;
              ratioY = availableImageHeight / normalHeight;
              normalWidth *= ratioX;
              normalHeight *= ratioY;
              xoffset = 0;
              yoffset = 0;
              break;
            }
            case RETAIN_SHAPE:
            default:
            {
              ratioX = availableImageWidth / normalWidth;
              ratioY = availableImageHeight / normalHeight;
              ratioX = ratioX < ratioY ? ratioX : ratioY;
              ratioY = ratioX;
              normalWidth *= ratioX;
              normalHeight *= ratioY;
              xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth));
              yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight));
              break;
            }
          }
        }

        PdfTemplate template = pdfContentByte.createTemplate((float)displayWidth, (float)displayHeight);

        Graphics2D g = forceSvgShapes
          ? template.createGraphicsShapes((float)displayWidth, (float)displayHeight)
          : template.createGraphics(availableImageWidth, availableImageHeight, new LocalFontMapper());

        if (clip != null)
        {
          g.setClip(clip);
        }
       
        if (printImage.getModeValue() == ModeEnum.OPAQUE)
        {
          g.setColor(printImage.getBackcolor());
          g.fillRect(0, 0, (int)displayWidth, (int)displayHeight);
        }

        Rectangle2D rectangle = new Rectangle2D.Double(0, 0, displayWidth, displayHeight);

        renderer.render(g, rectangle);
        g.dispose();

        pdfContentByte.saveState();
        pdfContentByte.addTemplate(
          template,
          (float)ratioX, 0f, 0f, (float)ratioY,
          printImage.getX() + getOffsetX() + xoffset,
          jasperPrint.getPageHeight()
            - printImage.getY() - getOffsetY()
            - (int)normalHeight
            - yoffset
          );
        pdfContentByte.restoreState();

        Image image = getPxImage();
        image.scaleAbsolute(availableImageWidth, availableImageHeight);
        chunk = new Chunk(image, 0, 0);
      }

      /*
      image.setAbsolutePosition(
        printImage.getX() + offsetX + borderOffset,
View Full Code Here

    
    boolean firstChunk = true;
    while(runLimit < text.length() && (runLimit = iterator.getRunLimit()) <= text.length())
    {
      Map attributes = iterator.getAttributes();
      Chunk chunk = getChunk(attributes, text.substring(iterator.getIndex(), runLimit), locale);
     
      if (firstChunk)
      {
        // only set anchor + bookmark for the first chunk in the text
        setAnchor(chunk, textElement, textElement);
View Full Code Here

  protected Chunk getChunk(Map attributes, String text, Locale locale)
  {
    // underline and strikethrough are set on the chunk below
    Font font = getFont(attributes, locale, false);

    Chunk chunk = new Chunk(text, font);
   
    if (hasUnderline(attributes))
    {
      // using the same values as sun.font.Fond2D
      chunk.setUnderline(null, 0, 1f / 18, 0, -1f / 12, 0);
    }
   
    if (hasStrikethrough(attributes))
    {
      // using the same thickness as sun.font.Fond2D.
      // the position is calculated in Fond2D based on the ascent, defaulting
      // to iText default position which depends on the font size
      chunk.setUnderline(null, 0, 1f / 18, 0, 1f / 3, 0);
    }

    Color backcolor = (Color)attributes.get(TextAttribute.BACKGROUND);
    if (backcolor != null)
    {
      chunk.setBackground(backcolor);
    }

    Object script = attributes.get(TextAttribute.SUPERSCRIPT);
    if (script != null)
    {
      if (TextAttribute.SUPERSCRIPT_SUPER.equals(script))
      {
        chunk.setTextRise(font.getCalculatedLeading(1f)/2);
      }
      else if (TextAttribute.SUPERSCRIPT_SUB.equals(script))
      {
        chunk.setTextRise(-font.getCalculatedLeading(1f)/2);
      }
    }

    if (splitCharacter != null)
    {
      //TODO use line break offsets if available?
      chunk.setSplitCharacter(splitCharacter);
    }

    return chunk;
  }
View Full Code Here

Date now = new Date();
System.out.println("date--> " + now);
DateFormat df = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
String s1 = df.format(now);
         
Chunk CONNECT = new Chunk(new LineSeparator(5.5f, 95, Color.BLUE, Element.ALIGN_CENTER, 3.5f));
  //  LineSeparator UNDERLINE =new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -2);

//public HeaderFooter getMyHeader(String titulo) throws ServletException { 
//    Phrase p= new Phrase(); 
//    Chunk chunkTemp = new Chunk("My Company Name\n", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL); 
View Full Code Here

                } else if ("SEPERATOR_LINE".equals(questionType) || "SEPERATOR_TEXT".equals(questionType)) {
                    // not really a question; ingore completely
                } else {
                    value = surveyResponseAnswer.getString("textResponse");
                }
                Chunk chunk = new Chunk(surveyQuestion.getString("question") + ": " + value);
                Paragraph p = new Paragraph(chunk);
                document.add(p);
            }
            ByteBuffer outByteBuffer = ByteBuffer.wrap(baos.toByteArray());
            results.put("outByteBuffer", outByteBuffer);
View Full Code Here

    public static List createContents(java.util.List<DrlRuleParser> rules) {
        List index = new List( true );

        for ( DrlRuleParser drlRuleData : rules ) {
            Chunk chunk = new Chunk( drlRuleData.getName() );
            // chunk.setLocalGoto( item.getName() );
            ListItem listItem = new ListItem( chunk );
            index.add( listItem );
        }
View Full Code Here

                } else if ("SEPERATOR_LINE".equals(questionType) || "SEPERATOR_TEXT".equals(questionType)) {
                    // not really a question; ingore completely
                } else {
                    value = surveyResponseAnswer.getString("textResponse");
                }
                Chunk chunk = new Chunk(surveyQuestion.getString("question") + ": " + value);
                Paragraph p = new Paragraph(chunk);
                document.add(p);
            }
            ByteBuffer outByteBuffer = ByteBuffer.wrap(baos.toByteArray());
            results.put("outByteBuffer", outByteBuffer);
View Full Code Here

TOP

Related Classes of com.lowagie.text.Chunk

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.