Package com.lowagie.text

Examples of com.lowagie.text.Image


        List images = new ArrayList();
        for(int i = 0; i < MAX_NUM_IMG; i++)
        {
          String imgName = (new StringBuilder(String.valueOf(path.substring(0, path.indexOf(".png"))))).append(i).append(".png").toString();
          Image png = Image.getInstance(imgName);
          if(png == null)
          {
            break;
          }
          images.add(png);
        }

        Table table = new Table(images.size());
        for(int i = 0; i < images.size(); i++)
        {
          Image png = (Image)images.get(i);
          if(HORIZONTAL_ORIENTATION.equalsIgnoreCase(orientation))
          {
            Cell pngCell = new Cell(png);
            pngCell.setBorder(0);
            table.setBorder(0);
            table.addCell(pngCell);
          } else
          {
            png.setAlignment(5);
            pdfDocument.add(png);
          }
        }

        pdfDocument.add(table);
      } else
      {
        Image jpg = Image.getInstance(path);
        float height = jpg.getHeight();
        float width = jpg.getWidth();

        // if in need to change layout
        if(width > MAX_WIDTH || height > MAX_HEIGHT){
          changeLayout(pdfDocument, jpg, width, height);
        }
View Full Code Here


      transformSVGIntoPNG(inputStream, imageFileOutputStream);
     
        Document pdfDocument = new Document(PageSize.A4.rotate());
        PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, outputStream);
        pdfDocument.open();
        Image jpg = Image.getInstance(imageFile.getPath());
        fitImage(jpg);
     
        pdfDocument.add(jpg);
        pdfDocument.close();
        docWriter.close();
View Full Code Here

      for (Iterator iterator = documentsMap.keySet().iterator(); iterator.hasNext();) {
        String label = (String) iterator.next();
        DocumentContainer docContainer = documentsMap.get(label);
        byte[] content = docContainer.getContent();
        if (content != null) {
          Image img = null;
          try {
            img = Image.getInstance(content);
            table.addCell(img)
          } catch (Exception e) {
            logger.debug("Trying to evaluate response as a PDF file... ");
            table.addCell("");
//            try {
//              PdfReader reader = new PdfReader(content);
//              PdfImportedPage page = writer.getImportedPage(reader, 1);
//              writer.addPage(page);
//              table.addCell("");
//            } catch (Exception x) {
//              logger.error("Error in inserting image for document " + label, e);
//              logger.error("Error in inserting pdf file for document " + label, x);
//              table.addCell("");
//            }
          }
        }
        cellsCounter++;
      }

      // if cell counter is not pair make it pair
      if(cellsCounter%2!=0){
        table.addCell("");
      }
      document.add(table);

    }
    else
    { // ************* NO DEFAULT STYLE *****************
      logger.debug("No default style");

      // I want to calculate total height of scaled heights!!
      //int totalScaledHeight=calculateTotaleScaledHeights(documentsMap, defaultStyle);

      // run on all documents
      for (Iterator iterator = documentsMap.keySet().iterator(); iterator.hasNext();) {
        String label = (String) iterator.next();
        logger.debug("document with label "+label);

        DocumentContainer docContainer=  documentsMap.get(label);
        MetadataStyle style=docContainer.getStyle();


        // one table for each image, set at absolute position
        PdfPTable table=new PdfPTable(1);

        // width and height specified for the container by style attribute
        int widthStyle=style.getWidth();
        int heightStyle=style.getHeight();
        logger.debug("style for document width: "+widthStyle+ " height: "+heightStyle);

        // width and height for the table scaled to the document size
        int tableWidth=calculatePxSize(docWidth, widthStyle, videoWidth);
        int tableHeight=calculatePxSize(docHeight, heightStyle, videoHeight);

        logger.debug("table for document width: "+tableWidth+ " height: "+tableHeight);

        // x and y position as specified for the container by the style attribute
        int yStyle=style.getY();
        int xStyle=style.getX();
        // width and height scaled to the document size
        int xPos=(calculatePxPos(docWidth, xStyle, videoWidth));
        int yPos=(int)docHeight-(calculatePxPos(docHeight, yStyle, videoHeight));
        logger.debug("Table position at x: "+xPos+ " y: "+yPos);

        // get the image
        byte[] content=docContainer.getContent();
        if(content != null){
          Image img = null;
          try {
            img = Image.getInstance(content);
          }
          catch (Exception e) {
            logger.debug("Trying to evaluate response as a PDF file... ");
            try {
              PdfReader reader = new PdfReader(content);
              PdfContentByte cb = writer.getDirectContent();
              PdfImportedPage page = writer.getImportedPage(reader, 1);
              float[] tm = getTransformationMatrix(page, xPos, yPos, tableWidth, tableHeight);
              cb.addTemplate(page, tm[0], tm[1], tm[2], tm[3], tm[4], tm[5]);
            } catch (Exception x) {
              logger.error("Error in inserting image for document " + label, e);
              logger.error("Error in inserting pdf file for document " + label, x);
            }
            continue;
          }

          //if it is a REPORT and has more than one page, too large, you have to resize the image, but how to understand it?
          // if image size is more than double of the container size cut the first part,otherwise scale it
          if(docContainer.getDocumentType().equals("REPORT")){
            boolean cutImageWIdth=isToCutWidth(img, tableWidth);
            boolean cutImageHeight=isToCutHeight(img, tableWidth);

            if(cutImageWIdth==true || cutImageHeight==true){
              logger.debug("Report will be cut to width "+tableWidth+" and height "+tableHeight);
              try{
                img=cutImage(content, cutImageHeight, cutImageWIdth, tableHeight, tableWidth, (int)img.getWidth(), (int)img.getHeight());
              }catch (Exception e) {
                logger.error("Error in image cut, cutt will be ignored and image will be drawn anyway ",e);
              }
            }
          }

          // this is percentage to resize
          // The image must be size within the cell         
          int percToResize=percentageToResize((int)img.getWidth(), (int)img.getHeight(), tableWidth, tableHeight);
          logger.debug("image will be scaled of percentage "+percToResize);
          img.scalePercent(percToResize);
         
          PdfPCell cell= new PdfPCell(img);
          cell.setNoWrap(true);
          cell.setFixedHeight(tableHeight);
          cell.setBorderWidth(0);
View Full Code Here

    }
    catch (Exception e) {
      e.printStackTrace();
    }
    byte[] newBytes=getBytes(region);
    Image cutImg = Image.getInstance(newBytes);
    //ImageIO.write(region,"PNG",new File("C:/nuovaImmagine222.PNG"));
    logger.debug("OUT");

    return cutImg;
  }
View Full Code Here

  private void setHeader(JSONObject header) {
    try {
      String title = header.optString(TITLE);
      String imgName = header.optString(IMG);
      String imagePosition = header.optString(POSITION);
      Image image = null;
      if ( imgName != null && !imgName.equals("")
          && !imgName.equals("null") ) {
        File imageFile = getImage(imgName);
        if (!imageFile.exists() || !imageFile.isFile()) {
          logger.error("Image " + imgName + " not found!!!");
View Full Code Here

  private void setFooter(JSONObject footer) {
    try {
      String title = footer.optString(TITLE);
      String imgName = footer.optString(IMG);
      String imagePosition = footer.optString(POSITION);
      Image image = null;
      if ( imgName != null && !imgName.equals("")
          && !imgName.equals("null") ) {
        File imageFile = getImage(imgName);
        if (!imageFile.exists() || !imageFile.isFile()) {
          logger.error("Image " + imgName + " not found!!!");
View Full Code Here

      inputStream = new ByteArrayInputStream(svg.getBytes("ISO-8859-1"));
      File imageFile = File.createTempFile("chart", ".jpg");
      outputStream = new FileOutputStream(imageFile);
      transformSVGIntoJPEG(inputStream, outputStream);
     
        Image jpg = Image.getInstance(imageFile.getPath());
       
        float topMargin = margins[0];
        float bottomMargin = margins[1];
       
        float chartMaxHeight = PageSize.A4.getWidth() - (topMargin + bottomMargin)// remember that the page is A4 rotated
        float chartMaxWidth = PageSize.A4.getHeight() - (MARGIN_LEFT + MARGIN_RIGHT)// remember that the page is A4 rotated
       
        float[] newDimensions = fitImage( jpg, chartMaxWidth, chartMaxHeight );

        float positionX = (PageSize.A4.getHeight() - newDimensions[0]) / 2;
        float positionY = bottomMargin + (chartMaxHeight - newDimensions[1]) / 2; // center the image into the available height
        jpg.setAbsolutePosition(positionX, positionY);
       
        pdfDocument.add(jpg);
    } catch (Exception e) {
      throw new RuntimeException("Error while adding chart", e);
    }
View Full Code Here

   
    if (inline.getGraphic() != null) {
     
      byte[] imagedata = BinaryPartAbstractImage.getImage(wordMLPackage,
          inline.getGraphic() );
      Image img = Image.getInstance( imagedata );
      if (paraParent instanceof Document) {       
        ((Document)paraParent).add(img);
      } else if (paraParent instanceof PdfPTable) {       
        ((PdfPTable)paraParent).addCell(img);
      } else {
View Full Code Here

          File dirF = new File(dirS);
            tmpFile = File.createTempFile("tempPDFExport", ".pdf", dirF);
            Document pdfDocument = new Document();
            PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, new FileOutputStream(tmpFile));
            pdfDocument.open();
            Image jpg = Image.getInstance(imageFile.getPath());
            jpg.setRotation(new Double(Math.PI/2).floatValue());
            jpg.scaleAbsolute(770, 520);
            pdfDocument.add(jpg);
            pdfDocument.close();
            docWriter.close();
            maptmpfile = tmpFile;
         
View Full Code Here

          File dirF = new File(dirS);
            tmpFile = File.createTempFile("tempPDFExport", ".pdf", dirF);
            Document pdfDocument = new Document();
            PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, new FileOutputStream(tmpFile));
            pdfDocument.open();
            Image jpg = Image.getInstance(imageFile.getPath());
            jpg.setRotation(new Double(Math.PI/2).floatValue());
            jpg.scaleAbsolute(770, 520);
            pdfDocument.add(jpg);
            pdfDocument.close();
            docWriter.close();
            maptmpfile = tmpFile;
         
View Full Code Here

TOP

Related Classes of com.lowagie.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.