Package org.odftoolkit.odfdom.incubator.doc.draw

Examples of org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawFrame


   *         based on the given URI.
   * */
  public String newImage(URI imageUri) {
    try {
      OdfContentDom contentDom = this.getContentDom();
      OdfDrawFrame drawFrame = contentDom.newOdfElement(OdfDrawFrame.class);
      XPath xpath = contentDom.getXPath();
      if (this instanceof SpreadsheetDocument) {
        TableTableCellElement lastCell = (TableTableCellElement) xpath.evaluate("//table:table-cell[last()]",
            contentDom, XPathConstants.NODE);
        lastCell.appendChild(drawFrame);
        drawFrame.removeAttribute("text:anchor-type");

      } else if (this instanceof TextDocument) {
        TextPElement lastPara = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom,
            XPathConstants.NODE);
        if (lastPara == null) {
          lastPara = ((TextDocument) this).newParagraph();
        }
        lastPara.appendChild(drawFrame);
        drawFrame.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PARAGRAPH.toString());
      } else if (this instanceof PresentationDocument) {
        DrawPageElement lastPage = (DrawPageElement) xpath.evaluate("//draw:page[last()]", contentDom,
            XPathConstants.NODE);
        lastPage.appendChild(drawFrame);
      }
      OdfDrawImage image = (OdfDrawImage) drawFrame.newDrawImageElement();
      String imagePath = image.newImage(imageUri);
      return imagePath;
    } catch (Exception ex) {
      Logger.getLogger(Document.class.getName()).log(Level.SEVERE, null, ex);
    }
View Full Code Here


      OdfTextDocument doc = OdfTextDocument.newTextDocument();
      String imagePath1 = doc.newImage(ResourceUtilities.getURI("testA.jpg"));
      Assert.assertTrue(getImageCount(doc) == 1);
      OdfDrawImage image = getImageByPath(doc, imagePath1).get(0);
      Assert.assertTrue(image.getImageUri().toString().equals(imagePath1));
      OdfDrawFrame frame1 = (OdfDrawFrame) image.getParentNode();
      frame1.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PAGE.toString());
      frame1.setTextAnchorPageNumberAttribute(1);

      //add paragraph
      OfficeTextElement office = doc.getContentRoot();
      OdfTextParagraph para1 = (OdfTextParagraph) office.newTextPElement();
      para1.setTextContent("insert an image here");
      String imagePath2 = doc.newImage(mImageUri_ODFDOM);

      OdfTextParagraph para2 = (OdfTextParagraph) office.newTextPElement();
      para2.setTextContent("another");
      String imagePath3 = doc.newImage(mImageUri_ODFDOM);
      OdfDrawImage image3 = getImageByPath(doc, imagePath3).get(1);
      OdfDrawFrame frame3 = (OdfDrawFrame) image3.getParentNode();
      frame3.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.CHAR.toString());

      doc.save(ResourceUtilities.newTestOutputFile("addimages.odt"));

      //load the file again
      OdfTextDocument doc1 = (OdfTextDocument) OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath("addimages.odt"));
View Full Code Here

      // an image consists always of a 'draw:image' and a 'draw:frame' parent

      // FUTURE USAGE: para.createDrawFrame().createDrawImage("/myweb.org/images/myHoliday.png", "/Pictures/myHoliday.png");
      //             Child access methods are still not part of the v0.6.x releases
      // CURRENT USAGE:
      OdfDrawFrame odfFrame = (OdfDrawFrame) OdfXMLFactory.newOdfElement(odfContent, DrawFrameElement.ELEMENT_NAME);
      para.appendChild(odfFrame);
      OdfDrawImage odfImage = (OdfDrawImage) OdfXMLFactory.newOdfElement(odfContent, OdfDrawImage.ELEMENT_NAME);
      odfFrame.appendChild(odfImage);
      odfImage.newImage(ResourceUtilities.getURI(TEST_PIC));

      OdfDrawImage odfImage2 = (OdfDrawImage) OdfXMLFactory.newOdfElement(odfContent, OdfDrawImage.ELEMENT_NAME);
      odfFrame.appendChild(odfImage2);
      //Deactivated as test fail, when test machine is not online (painful for offline work)
      //odfImage2.newImage(new URI("http://odftoolkit.org/attachments/wiki_images/odftoolkit/Table_fruits_diagramm.jpg"));
      odfDoc.save(ResourceUtilities.newTestOutputFile("odfdom-wiki-dom.odt"));

    } catch (Exception e) {
View Full Code Here

      Assert.fail("Failed with " + ex.getClass().getName() + ": '" + ex.getMessage() + "'");
    }
  }

  private void addImageToDocument(OdfContentDom dom, TextPElement para) throws Exception {
    OdfDrawFrame drawFrame = new OdfDrawFrame(dom);
    drawFrame.setDrawNameAttribute("graphics1");
    drawFrame.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PARAGRAPH.toString());
    drawFrame.setSvgWidthAttribute("4.233cm");
    drawFrame.setSvgHeightAttribute("4.233cm");
    drawFrame.setDrawZIndexAttribute(0);
    para.appendChild(drawFrame);

    OdfDrawImage image = new OdfDrawImage(dom);
    drawFrame.appendChild(image);
    image.newImage(ResourceUtilities.getURI(TEST_PIC));
  }
View Full Code Here

    drawFrame.appendChild(image);
    image.newImage(ResourceUtilities.getURI(TEST_PIC));
  }

  private void addFrameForEmbeddedDoc(OdfContentDom dom, TextPElement para, String path) throws Exception {
    OdfDrawFrame drawFrame = new OdfDrawFrame(dom);
    drawFrame.setDrawNameAttribute(path);
    drawFrame.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PARAGRAPH.toString());
    drawFrame.setSvgXAttribute("0.834cm");
    drawFrame.setSvgYAttribute("2.919cm");
    drawFrame.setSvgWidthAttribute("13.257cm");
    drawFrame.setSvgHeightAttribute("11.375cm");
    drawFrame.setDrawZIndexAttribute(0);

    DrawObjectElement object = new DrawObjectElement(dom);
    object.setXlinkHrefAttribute("./" + path);
    object.setXlinkActuateAttribute("onLoad");
    object.setXlinkShowAttribute("embed");
    object.setXlinkTypeAttribute("simple");
    drawFrame.appendChild(object);
    para.appendChild(drawFrame);
  }
View Full Code Here

    // FUTURE USAGE:
    // para.createDrawFrame().createDrawImage("/myweb.org/images/myHoliday.png",
    // "/Pictures/myHoliday.png");
    // Child access methods are still not part of the v0.6.x releases
    // CURRENT USAGE:
    OdfDrawFrame odfFrame = (OdfDrawFrame) OdfXMLFactory.newOdfElement(odfContent,
        DrawFrameElement.ELEMENT_NAME);
    para.appendChild(odfFrame);
    OdfDrawImage odfImage = (OdfDrawImage) OdfXMLFactory.newOdfElement(odfContent, OdfDrawImage.ELEMENT_NAME);
    odfFrame.appendChild(odfImage);
    odfImage.newImage(ResourceUtilities.getURI(TEST_PIC));

    OdfDrawImage odfImage2 = (OdfDrawImage) OdfXMLFactory.newOdfElement(odfContent, OdfDrawImage.ELEMENT_NAME);
    odfFrame.appendChild(odfImage2);
    // Deactivated as test fail, when test machine is not online
    // (painful for offline work)
    // odfImage2.newImage(new
    // URI("http://odftoolkit.org/attachments/wiki_images/odftoolkit/Table_fruits_diagramm.jpg"));
    odfDoc.save(ResourceUtilities.newTestOutputFile("simple-wiki-dom.odt"));
View Full Code Here

      Assert.fail("Failed with " + ex.getClass().getName() + ": '" + ex.getMessage() + "'");
    }
  }

  private void addImageToDocument(OdfContentDom dom, TextPElement para) throws Exception {
    OdfDrawFrame drawFrame = new OdfDrawFrame(dom);
    drawFrame.setDrawNameAttribute("graphics1");
    drawFrame.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PARAGRAPH.toString());
    drawFrame.setSvgWidthAttribute("4.233cm");
    drawFrame.setSvgHeightAttribute("4.233cm");
    drawFrame.setDrawZIndexAttribute(0);
    para.appendChild(drawFrame);

    OdfDrawImage image = new OdfDrawImage(dom);
    drawFrame.appendChild(image);
    image.newImage(ResourceUtilities.getURI(TEST_PIC));
  }
View Full Code Here

    drawFrame.appendChild(image);
    image.newImage(ResourceUtilities.getURI(TEST_PIC));
  }

  private void addFrameForEmbeddedDoc(OdfContentDom dom, TextPElement para, String path) throws Exception {
    OdfDrawFrame drawFrame = new OdfDrawFrame(dom);
    drawFrame.setDrawNameAttribute(path);
    drawFrame.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PARAGRAPH.toString());
    drawFrame.setSvgXAttribute("0.834cm");
    drawFrame.setSvgYAttribute("2.919cm");
    drawFrame.setSvgWidthAttribute("13.257cm");
    drawFrame.setSvgHeightAttribute("11.375cm");
    drawFrame.setDrawZIndexAttribute(0);

    DrawObjectElement object = new DrawObjectElement(dom);
    object.setXlinkHrefAttribute("./" + path);
    object.setXlinkActuateAttribute("onLoad");
    object.setXlinkShowAttribute("embed");
    object.setXlinkTypeAttribute("simple");
    drawFrame.appendChild(object);
    para.appendChild(drawFrame);
  }
View Full Code Here

      Assert.fail("Failed with " + ex.getClass().getName() + ": '" + ex.getMessage() + "'");
    }
  }

  private void addImageToDocument(OdfContentDom dom, TextPElement para) throws Exception {
    OdfDrawFrame drawFrame = new OdfDrawFrame(dom);
    drawFrame.setDrawNameAttribute("graphics1");
    drawFrame.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PARAGRAPH.toString());
    drawFrame.setSvgWidthAttribute("4.233cm");
    drawFrame.setSvgHeightAttribute("4.233cm");
    drawFrame.setDrawZIndexAttribute(0);
    para.appendChild(drawFrame);

    OdfDrawImage image = new OdfDrawImage(dom);
    drawFrame.appendChild(image);
    image.newImage(ResourceUtilities.getURI(TEST_PIC));
  }
View Full Code Here

    drawFrame.appendChild(image);
    image.newImage(ResourceUtilities.getURI(TEST_PIC));
  }

  private void addFrameForEmbeddedDoc(OdfContentDom dom, TextPElement para, String path) throws Exception {
    OdfDrawFrame drawFrame = new OdfDrawFrame(dom);
    drawFrame.setDrawNameAttribute(path);
    drawFrame.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PARAGRAPH.toString());
    drawFrame.setSvgXAttribute("0.834cm");
    drawFrame.setSvgYAttribute("2.919cm");
    drawFrame.setSvgWidthAttribute("13.257cm");
    drawFrame.setSvgHeightAttribute("11.375cm");
    drawFrame.setDrawZIndexAttribute(0);

    DrawObjectElement object = new DrawObjectElement(dom);
    object.setXlinkHrefAttribute("./" + path);
    object.setXlinkActuateAttribute("onLoad");
    object.setXlinkShowAttribute("embed");
    object.setXlinkTypeAttribute("simple");
    drawFrame.appendChild(object);
    para.appendChild(drawFrame);
  }
View Full Code Here

TOP

Related Classes of org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawFrame

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.