Examples of BinaryPartAbstractImage


Examples of org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage

     
      // Base64 decode it
      byte[] bytes = Base64.decodeBase64( xpResult.getBytes("UTF8") );
     
      // Create image part and add it
          BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wmlPackage, sourcePart, bytes);
         
     
          String filenameHint = null;
          String altText = null;
          int id1 = 0;
          int id2 = 1;               
          Inline inline = null;
          long cxl = 0;
          long cyl = 0;
          try {
            cxl = Long.parseLong(cx);
            cyl = Long.parseLong(cy);
          } catch (Exception e) {}
          if (cxl==0 || cyl==0) {
            // Let BPAI work out size
            log.debug("image size - from image");
            inline = imagePart.createImageInline( filenameHint, altText,
              id1, id2, false);
          } else {
            // Use existing size
            log.debug("image size - from content control size");
                // Respect aspect ratio of injected image
                ImageSize size = imagePart.getImageInfo().getSize();
                double ratio = (double) size.getHeightPx() / (double) size.getWidthPx();
                log.debug("fit ratio: " + ratio);
                if (ratio > 1) {
                    cxl =  (long)((double) cyl / ratio);
                } else {
                    cyl =  (long)((double) cxl * ratio);
                }
            inline = imagePart.createImageInline( filenameHint, altText,
              id1, id2, cxl, cyl, false);             
          }

          // In certain circumstances, save it immediately
          if (wmlPackage.getTargetPartStore()!=null
              && wmlPackage.getTargetPartStore() instanceof UnzippedPartStore) {
            log.debug("incrementally saving " + imagePart.getPartName().getName())
            ((UnzippedPartStore)wmlPackage.getTargetPartStore()).saveBinaryPart(imagePart);
            // remove it from memory
            ByteBuffer bb = null;
            imagePart.setBinaryData(bb);//new byte[0]);
            imagePart.setImageInfo(null); // this might help as well
          }
         
         
          // Now add the inline in w:p/w:r/w:drawing
      org.docx4j.wml.ObjectFactory factory = new org.docx4j.wml.ObjectFactory();
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage

     
      // Base64 decode it
      byte[] bytes = Base64.decodeBase64( xpResult.getBytes("UTF8") );
     
      // Create image part and add it
          BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wmlPackage, sourcePart, bytes);

          // In certain circumstances, save it immediately
          if (wmlPackage.getTargetPartStore()!=null
              && wmlPackage.getTargetPartStore() instanceof UnzippedPartStore) {
            log.debug("incrementally saving " + imagePart.getPartName().getName())
            ((UnzippedPartStore)wmlPackage.getTargetPartStore()).saveBinaryPart(imagePart);
            // remove it from memory
            ByteBuffer bb = null;
            imagePart.setBinaryData(bb);//new byte[0]);
            imagePart.setImageInfo(null); // this might help as well
          }
         
      return imagePart.getRelLast().getId();
     
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage

       
        // Base64 decode it
        byte[] bytes = Base64.decodeBase64( r.getBytes("UTF8") );
       
        // Create image part and add it
            BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wmlPackage, sourcePart, bytes);
//        BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createPNGPart(wmlPackage, sourcePart, bytes);
       
            String filenameHint = null;
            String altText = null;
            int id1 = 0;
            int id2 = 1;               
            Inline inline = null;
            long cxl = 0;
            long cyl = 0;
            try {
              cxl = ef.getExtent().getCx();
              cyl = ef.getExtent().getCy();
            } catch (Exception e) {}
            if (cxl==0 || cyl==0) {
              // Let BPAI work out size
              log.debug("image size - from image");
              inline = imagePart.createImageInline( filenameHint, altText,
                id1, id2, false);
//              inline = imagePart.createImageInline( filenameHint, altText,
//                id1, id2, 100000, 100000, false);             
            } else {
              // Use existing size
              log.debug("image size - from content control size");
                  // Respect aspect ratio of injected image
                  ImageSize size = imagePart.getImageInfo().getSize();
                  double ratio = (double) size.getHeightPx() / (double) size.getWidthPx();
                  log.debug("fit ratio: " + ratio);
                  if (ratio > 1) {
                      cxl =  (long)((double) cyl / ratio);
                  } else {
                      cyl =  (long)((double) cxl * ratio);
                  }
              inline = imagePart.createImageInline( filenameHint, altText,
                id1, id2, cxl, cyl, false);             
            }
           
            // Now add the inline in w:p/w:r/w:drawing
        org.docx4j.wml.ObjectFactory factory = new org.docx4j.wml.ObjectFactory();
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage

     
      image = this.getImage();

      wordMLPackage = WordprocessingMLPackage.createPackage();
       
      BinaryPartAbstractImage imagePartBG = BinaryPartAbstractImage.createImagePart(wordMLPackage, image);

      wordMLPackage.getMainDocumentPart().getJaxbElement().setBackground(
          createBackground(
              imagePartBG.getRelLast().getId()));

      wordMLPackage.getMainDocumentPart().addParagraphOfText("To see your background, go to 'Web layout' or 'Full screen reading' document view!");
     
        File f = new File(DOCX_OUT);
        wordMLPackage.save(f);
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage

       
        Picture picture = doc.getPicturesTable().extractPicture(run,
            true);
        Inline inline;
        try {
          BinaryPartAbstractImage imagePart = BinaryPartAbstractImage
              .createImagePart(wordMLPackage, picture.getContent());

          long cx = UnitsOfMeasurement
              .twipToEMU(Math.round((double) imagePart
                  .getImageInfo().getSize().getWidthMpt()
                  * ((double) picture
                      .getHorizontalScalingFactor() * 0.00001d))) * 2L;
          long cy = UnitsOfMeasurement
              .twipToEMU(Math.round((double) imagePart
                  .getImageInfo().getSize().getHeightMpt()
                  * ((double) picture
                      .getVerticalScalingFactor() * 0.00001d))) * 2L;

          inline = imagePart.createImageInline(null, "", ID1++,
              ID2++, cx, cy, false);

          org.docx4j.wml.R imgrun = factory.createR();
          org.docx4j.wml.Drawing drawing = factory.createDrawing();
          imgrun.getContent().add(drawing);
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage

        CTBlip blip = imgPt.getSpPr().getBlipFill().getBlip();       
        if (blip.getEmbed()!=null) {
         
          String relId = blip.getEmbed();
          //Relationship r = diagramDataPart.getRelationshipsPart().getRelationshipByID(relId);
          BinaryPartAbstractImage bpai = (BinaryPartAbstractImage)diagramDataPart.getRelationshipsPart().getPart(relId);

          // Add it
          Image image = factory.createSmartArtDataHierarchyImagesImage();
          image.setContentType(bpai.getContentType());
          image.setId(imgPt.getModelId());
         
          image.setValue(bpai.getBytes());
         
          images.getImage().add(image);
         
          // reference
          org.opendope.SmartArt.dataHierarchy.ImageRef imageRef = factory.createImageRef();
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage

  public static String addImage(DiagramDataPart ddp, String base64) {
    // No need to pass content type.
       
    log.debug("Adding image: " + base64);
   
    BinaryPartAbstractImage imagePart = null;
    try {
      // Base64 decode it
      byte[] bytes = Base64.decodeBase64( base64.getBytes("UTF8") );
     
      // Create image part and add it
      imagePart = BinaryPartAbstractImage.createImagePart(
          ddp.getPackage(), ddp, bytes);
    } catch (Exception e) {
      e.printStackTrace();
      log.error(e.getMessage(), e);

      // Can't use this image, so insert a placeholder
      log.info(".. attempting to use broken image placeholder");
      try {
        byte[] bytes = IOUtils.toByteArray(org.docx4j.utils.ResourceUtils.getResource(
            "image_broken.gif"));
       
        imagePart = BinaryPartAbstractImage.createImagePart(
            ddp.getPackage(), ddp, bytes);

        log.info(".. used broken image placeholder");
       
      } catch (Exception e1) {
        e1.printStackTrace();
        return "";
      }
    }
   
        return imagePart.getSourceRelationships().get(0).getId();
  }
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage

  public static org.docx4j.wml.P newImage( WordprocessingMLPackage wordMLPackage,
      byte[] bytes,
      String filenameHint, String altText,
      int id1, int id2) throws Exception {
   
        BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
   
        Inline inline = imagePart.createImageInline( filenameHint, altText,
          id1, id2, false);
       
        // Now add the inline in w:p/w:r/w:drawing
    org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
    org.docx4j.wml.P  p = factory.createP();
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage

  public static org.docx4j.wml.P newImage( WordprocessingMLPackage wordMLPackage,
      byte[] bytes,
      String filenameHint, String altText,
      int id1, int id2, long cx) throws Exception {
   
        BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
   
        Inline inline = imagePart.createImageInline( filenameHint, altText,
          id1, id2, cx, false);
       
        // Now add the inline in w:p/w:r/w:drawing
    org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
    org.docx4j.wml.P  p = factory.createP();
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage

    org.xlsx4j.sml.CTDrawing drawing = org.xlsx4j.jaxb.Context.getsmlObjectFactory().createCTDrawing();
        worksheet.getJaxbElement().setDrawing(drawing);
            drawing.setId( drawingRel.getId() );    
   
    // Create image part and add to Drawing part
        BinaryPartAbstractImage imagePart
          = BinaryPartAbstractImage.createImagePart(pkg, drawingPart,
              FileUtils.readFileToByteArray(new File(imagefilePath) ));
        String imageRelID = imagePart.getSourceRelationship().getId();
   
    // Create and set drawing part content
        // Take your pick ..
        // .. build it using code
//        drawingPart.setJaxbElement(
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.