Package org.docx4j.relationships

Examples of org.docx4j.relationships.Relationship


    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
        .createPackage();
    // Delete the Styles part, since it clutters up our output
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
    Relationship styleRel = mdp.getStyleDefinitionsPart().getSourceRelationships().get(0);
    mdp.getRelationshipsPart().removeRelationship(styleRel);   

    // OK, the guts of this sample:
    // The 2 things you need:
    // 1. the Header part
    Relationship relationship = createHeaderPart(wordMLPackage);
    // 2. an entry in SectPr
    createHeaderReference(wordMLPackage, relationship);

    // Display the result as Flat OPC XML
    FlatOpcXmlCreator worker = new FlatOpcXmlCreator(wordMLPackage);
View Full Code Here


  public static Relationship createHeaderPart(
      WordprocessingMLPackage wordprocessingMLPackage)
      throws Exception {
   
    HeaderPart headerPart = new HeaderPart();
    Relationship rel =  wordprocessingMLPackage.getMainDocumentPart()
        .addTargetPart(headerPart);
   
    // After addTargetPart, so image can be added properly
    headerPart.setJaxbElement(getHdr(wordprocessingMLPackage, headerPart));
View Full Code Here

   
    if (this.getRelationshipsPart()==null) {
      return null;
    } else {
      // Look in its rels for rel of @Type customXmlProps (eg @Target="itemProps1.xml")
      Relationship r = this.getRelationshipsPart().getRelationshipByType(
          Namespaces.CUSTOM_XML_DATA_STORAGE_PROPERTIES);
      if (r==null) {
        log.warn(".. but that doesn't point to a  customXmlProps part");
        return null;
      }
View Full Code Here

  }

  private Relationship createHeaderPart(String nameSuffix) throws Exception {
   
    HeaderPart headerPart = new HeaderPart(new PartName("/word/header-" + nameSuffix + ".xml"));
    Relationship rel =  wordMLPackage.getMainDocumentPart().addTargetPart(headerPart);
   
    setHdr( headerPart);

    return rel;
  }
View Full Code Here

 
  private void setHdr(HeaderPart headerPart) throws Exception  {
   
    ImagePngPart imagePart = new ImagePngPart(new PartName("/media/background.png"));
    imagePart.setBinaryData(image);
    Relationship rel = headerPart.addTargetPart(imagePart, AddPartBehaviour.REUSE_EXISTING); // the one image is shared by the 3 header parts
   
    String openXML = "<w:hdr mc:Ignorable=\"w14 wp14\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
              + "<w:p>"
                  + "<w:pPr>"
                      + "<w:pStyle w:val=\"Header\"/>"
                  +"</w:pPr>"
                  + "<w:r>"
                      + "<w:rPr>"
                          + "<w:noProof/>"
                      +"</w:rPr>"
                      + "<w:pict>"
                          + "<v:shapetype coordsize=\"21600,21600\" filled=\"f\" id=\"_x0000_t75\" o:preferrelative=\"t\" o:spt=\"75\" path=\"m@4@5l@4@11@9@11@9@5xe\" stroked=\"f\">"
                              + "<v:stroke joinstyle=\"miter\"/>"
                              + "<v:formulas>"
                                  + "<v:f eqn=\"if lineDrawn pixelLineWidth 0\"/>"
                                  + "<v:f eqn=\"sum @0 1 0\"/>"
                                  + "<v:f eqn=\"sum 0 0 @1\"/>"
                                  + "<v:f eqn=\"prod @2 1 2\"/>"
                                  + "<v:f eqn=\"prod @3 21600 pixelWidth\"/>"
                                  + "<v:f eqn=\"prod @3 21600 pixelHeight\"/>"
                                  + "<v:f eqn=\"sum @0 0 1\"/>"
                                  + "<v:f eqn=\"prod @6 1 2\"/>"
                                  + "<v:f eqn=\"prod @7 21600 pixelWidth\"/>"
                                  + "<v:f eqn=\"sum @8 21600 0\"/>"
                                  + "<v:f eqn=\"prod @7 21600 pixelHeight\"/>"
                                  + "<v:f eqn=\"sum @10 21600 0\"/>"
                              +"</v:formulas>"
                              + "<v:path gradientshapeok=\"t\" o:connecttype=\"rect\" o:extrusionok=\"f\"/>"
                              + "<o:lock aspectratio=\"t\" v:ext=\"edit\"/>"
                          +"</v:shapetype>"
                          + "<v:shape id=\"WordPictureWatermark835936646\" o:allowincell=\"f\" o:spid=\"_x0000_s2050\" style=\"position:absolute;margin-left:0;margin-top:0;width:467.95pt;height:615.75pt;z-index:-251657216;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin\" type=\"#_x0000_t75\">"
                              + "<v:imagedata blacklevel=\"22938f\" gain=\"19661f\" o:title=\"docx4j-logo\" r:id=\"" + rel.getId() + "\"/>"
                          +"</v:shape>"
                      +"</w:pict>"
                  +"</w:r>"
              +"</w:p>"
          +"</w:hdr>";
View Full Code Here

    public void inlineToDocx(WordprocessingMLPackage wordPackage, Text text, Object paramValue, Matcher matcher) {
        try {
            AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/" + UUID.randomUUID().toString() + ".html"));
            afiPart.setBinaryData(paramValue.toString().getBytes());
            afiPart.setContentType(new ContentType("text/html"));
            Relationship altChunkRel = wordPackage.getMainDocumentPart().addTargetPart(afiPart);
            CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
            ac.setId(altChunkRel.getId());
            R run = (R) text.getParent();
            run.getContent().add(ac);
            text.setValue("");
            wordPackage.getContentTypeManager().addDefaultContentType("html", "text/html");
        } catch (Exception e) {
View Full Code Here

        CTAnchorClientData data = new CTAnchorClientData();
        anchor.setClientData(data);

        drawing.getJaxbElement().getEGAnchor().add(anchor);

        Relationship rel = new Relationship();
        rel.setId(rid);
        rel.setType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image");
        rel.setTarget("../media/" + name);

        drawing.getRelationshipsPart().addRelationship(rel);
        RelationshipsPart relPart = drawing.getRelationshipsPart();
        pkg.getParts().remove(relPart.getPartName());
        pkg.getParts().put(relPart);
View Full Code Here

    SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
    WorksheetPart worksheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/sheet1.xml"), "Sheet1", 1);

    // Create Drawing part and add to sheet
    Drawing drawingPart = new Drawing();
    Relationship drawingRel = worksheet.addTargetPart(drawingPart);

    // Add anchor XML to worksheet
    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) ));
View Full Code Here

 
      // Add <legacyDrawing r:id="rId1"/>
      VMLPart vmlPart = new VMLPart();
      vmlPart.setContents(getVml(0,0))// corresponds to A1
        // you'll need extra VML for each comment
      Relationship rel = sheet.addTargetPart(vmlPart);
      CTLegacyDrawing legacyDrawing = Context.getsmlObjectFactory().createCTLegacyDrawing();
      legacyDrawing.setId(rel.getId());
      sheet.getContents().setLegacyDrawing(legacyDrawing);
 
  }
View Full Code Here

      (PresentationMLPackage)OpcPackage.load(new java.io.File(inputfilepath));
   
    MainPresentationPart mpp = presentationMLPackage.getMainPresentationPart();
   
    //mpp.removeSlide(10);
    Relationship rel = mpp.getRelationshipsPart().getRelationshipByID("rId2");
    mpp.removeSlide(rel);
   
    System.out.println("\n\n saving .. \n\n");
    String outputfilepath = "data/pptx4j/RemovedSlide-Pptx4j.pptx";
    presentationMLPackage.save(new java.io.File(outputfilepath));
View Full Code Here

TOP

Related Classes of org.docx4j.relationships.Relationship

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.