Package org.docx4j.relationships

Examples of org.docx4j.relationships.Relationship


    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


   
    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

          || entry instanceof JaxbCustomXmlDataStoragePart) {
        sb.append("\nFound a CustomXmlDataStoragePart, named " + entry.getPartName().getName() );
        if (entry.getRelationshipsPart()==null) { continue; }
        sb.append("\n.. it has a rels part");
        // Look in its rels for rel of @Type customXmlProps (eg @Target="itemProps1.xml")
        Relationship r = entry.getRelationshipsPart().getRelationshipByType(
            Namespaces.CUSTOM_XML_DATA_STORAGE_PROPERTIES);
        if (r==null) {
          sb.append("\n.. but that doesn't point to a  customXmlProps part");
          continue;
        }
View Full Code Here

   */
  @Override
  public AlternativeFormatInputPart addAltChunk(AltChunkType type, byte[] bytesthrows Docx4JException {
   
    AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(type);
    Relationship altChunkRel = this.addTargetPart(afiPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
    // now that its attached to the package ..
    afiPart.registerInContentTypeManager();
   
    afiPart.setBinaryData(bytes);    
   
    // .. the bit in document body
    CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
    ac.setId(altChunkRel.getId() );
    if (this instanceof ContentAccessor) {
     ((ContentAccessor)this).getContent().add(ac);
    } else {
      throw new Docx4JException(this.getClass().getName() + " doesn't implement ContentAccessor");
    }
View Full Code Here

   */
  @Override
  public AlternativeFormatInputPart addAltChunk(AltChunkType type, InputStream is)   throws Docx4JException {
   
    AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(type);
    Relationship altChunkRel = this.addTargetPart(afiPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
    // now that its attached to the package ..
    afiPart.registerInContentTypeManager();   
   
    afiPart.setBinaryData(is);
   
    // .. the bit in document body
    CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
    ac.setId(altChunkRel.getId() );
    if (this instanceof ContentAccessor) {
     ((ContentAccessor)this).getContent().add(ac);
    } else {
      throw new Docx4JException(this.getClass().getName() + " doesn't implement ContentAccessor");
    }
View Full Code Here

      String sheetName, long sheetId)
    throws InvalidFormatException, JAXBException {
   
    WorksheetPart worksheetPart = new WorksheetPart(partName);
   
    Relationship r = wb.addTargetPart(worksheetPart);
   
    Sheets sheets = wb.getJaxbElement().getSheets();
   
    Sheet s = Context.getsmlObjectFactory().createSheet();
    s.setName(sheetName);
    s.setId(r.getId());
    s.setSheetId(sheetId);
   
    sheets.getSheet().add(s);
   
    // minimal content for the part
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

    // 1. Notes master
    NotesMasterPart nmp = new NotesMasterPart();
    NotesMaster notesmaster = (NotesMaster)XmlUtils.unmarshalString(notesMasterXml, Context.jcPML);
    nmp.setJaxbElement(notesmaster);
    // .. connect it to /ppt/presentation.xml
    Relationship ppRelNmp = pp.addTargetPart(nmp);
    /*
     *  <p:notesMasterIdLst>
                <p:notesMasterId r:id="rId3"/>
            </p:notesMasterIdLst>
     */
    pp.getJaxbElement().setNotesMasterIdLst(createNotesMasterIdListPlusEntry(ppRelNmp.getId()));
   
    // .. NotesMasterPart typically has a rel to a theme
    // .. can we get away without it?
    // Nope .. read this in from a file
    ThemePart themePart = new ThemePart(new PartName("/ppt/theme/theme2.xml"));
View Full Code Here

   

    // Do it again on another slide
    SlidePart slidePart2 = presentationMLPackage.createSlidePart(pp, layoutPart,
        new PartName("/ppt/slides/slide2.xml"));
    Relationship rel = slidePart2.addTargetPart(imagePart);
   
    slidePart2.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(
        createPicture(rel.getId()));
   
    // All done: save it
    presentationMLPackage.save(new java.io.File(outputfilepath));

    System.out.println("\n\n done .. saved " + outputfilepath);
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 = System.getProperty("user.dir") + "/pptx-out.pptx";
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.