How to use the word/_rels/document.xml.rels function in word

To help you get started, we’ve selected a few word examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dolanmiu / docx / src / import-dotx / import-dotx.ts View on Github external
public async extract(data: Buffer): Promise {
        const zipContent = await JSZip.loadAsync(data);

        const stylesContent = await zipContent.files["word/styles.xml"].async("text");
        const stylesFactory = new ExternalStylesFactory();
        const styles = stylesFactory.newInstance(stylesContent);

        const documentContent = zipContent.files["word/document.xml"];
        const documentRefs: IDocumentRefs = this.extractDocumentRefs(await documentContent.async("text"));
        const titlePageIsDefined = this.titlePageIsDefined(await documentContent.async("text"));

        const relationshipContent = zipContent.files["word/_rels/document.xml.rels"];
        const documentRelationships: IRelationshipFileInfo[] = this.findReferenceFiles(await relationshipContent.async("text"));

        const media = new Media();

        const headers: IDocumentHeader[] = [];
        for (const headerRef of documentRefs.headers) {
            const relationFileInfo = documentRelationships.find((rel) => rel.id === headerRef.id);
            if (relationFileInfo === null || !relationFileInfo) {
                throw new Error(`Can not find target file for id ${headerRef.id}`);
            }

            const xmlData = await zipContent.files[`word/${relationFileInfo.target}`].async("text");
            const xmlObj = xml2js(xmlData, { compact: false, captureSpacesBetweenElements: true }) as XMLElement;
            let headerXmlElement: XMLElement | undefined;
            for (const xmlElm of xmlObj.elements || []) {
                if (xmlElm.name === "w:hdr") {
github open-xml-templating / docxtemplater / coffee / docxgen.js View on Github external
DocxGen.prototype.loadImageRels = function() {
    var RidArray, content, tag;
    content = DocUtils.decode_utf8(this.zip.files["word/_rels/document.xml.rels"].data);
    this.xmlDoc = DocUtils.Str2xml(content);
    RidArray = (function() {
      var _i, _len, _ref, _results;
      _ref = this.xmlDoc.getElementsByTagName('Relationship');
      _results = [];
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        tag = _ref[_i];
        _results.push(parseInt(tag.getAttribute("Id").substr(3)));
      }
      return _results;
    }).call(this);
    this.maxRid = RidArray.max();
    this.imageRels = [];
    return this;
  };
github gitlabhq / gitlabhq / app / assets / javascripts / index.js View on Github external
.then((content) => {
        this.docx.setStyles(content);
        return this.asyncResult.files['word/_rels/document.xml.rels'].async('string');
      })
      .then((content) => {
github open-xml-templating / docxtemplater / js / docxgen.js View on Github external
ImgManager.prototype.loadImageRels = function() {
      var RidArray, content, tag;
      content = DocUtils.decode_utf8(this.zip.files["word/_rels/document.xml.rels"].asText());
      this.xmlDoc = DocUtils.Str2xml(content);
      RidArray = (function() {
        var _i, _len, _ref, _results;
        _ref = this.xmlDoc.getElementsByTagName('Relationship');
        _results = [];
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          tag = _ref[_i];
          _results.push(parseInt(tag.getAttribute("Id").substr(3)));
        }
        return _results;
      }).call(this);
      this.maxRid = RidArray.max();
      this.imageRels = [];
      return this;
    };
github open-xml-templating / docxtemplater / coffee / docxgen.js View on Github external
compression: null,
        date: new Date(),
        dir: false
      }
    };
    this.zip.file(file.name, file.data, file.options);
    extension = imageName.replace(/[^.]+\.([^.]+)/, '$1');
    this.addExtensionRels("image/" + extension, extension);
    relationships = this.xmlDoc.getElementsByTagName("Relationships")[0];
    newTag = this.xmlDoc.createElement('Relationship');
    newTag.namespaceURI = null;
    newTag.setAttribute('Id', "rId" + this.maxRid);
    newTag.setAttribute('Type', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image');
    newTag.setAttribute('Target', "media/" + imageName);
    relationships.appendChild(newTag);
    this.zip.files["word/_rels/document.xml.rels"].data = DocUtils.encode_utf8(DocUtils.xml2Str(this.xmlDoc));
    return this.maxRid;
  };

word

Word Processing Document library

Apache-2.0
Latest version published 4 years ago

Package Health Score

70 / 100
Full package analysis