diff --git a/src/export/packer/compiler.ts b/src/export/packer/compiler.ts index d0b0172cde..1b440cc294 100644 --- a/src/export/packer/compiler.ts +++ b/src/export/packer/compiler.ts @@ -41,12 +41,13 @@ export class Compiler { }, }); const xmlNumbering = xml(this.formatter.format(this.file.Numbering)); - const xmlRelationships = xml(this.formatter.format(this.file.Relationships)); + const xmlRelationships = xml(this.formatter.format(this.file.DocumentRelationships)); + const xmlFileRelationships = xml(this.formatter.format(this.file.FileRelationships)); const xmlHeader = xml(this.formatter.format(this.file.Header.Header)); const xmlFooter = xml(this.formatter.format(this.file.Footer.Footer)); const xmlHeaderRelationships = xml(this.formatter.format(this.file.Header.Relationships)); const xmlFooterRelationships = xml(this.formatter.format(this.file.Footer.Relationships)); - const xmlContentTypes = xml(this.formatter.format(this.file.ContentTypes)); + // const xmlContentTypes = xml(this.formatter.format(this.file.ContentTypes)); this.archive.append(xmlDocument, { name: "word/document.xml", @@ -84,8 +85,12 @@ export class Compiler { name: "word/_rels/footer1.xml.rels", }); - this.archive.append(xmlContentTypes, { - name: "[Content_Types].xml", + // this.archive.append(xmlContentTypes, { + // name: "[Content_Types].xml", + // }); + + this.archive.append(xmlFileRelationships, { + name: "_rels/.rels", }); for (const data of this.file.Media.array) { diff --git a/src/file/file.ts b/src/file/file.ts index 172424717c..19be012486 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -18,7 +18,8 @@ export class File { private readonly properties: Properties; private readonly numbering: Numbering; private readonly media: Media; - private readonly relationships: Relationships; + private readonly docRelationships: Relationships; + private readonly fileRelationships: Relationships; private readonly headerWrapper: HeaderWrapper; private readonly footerWrapper: FooterWrapper; private readonly contentTypes: ContentTypes; @@ -38,11 +39,19 @@ export class File { this.properties = new Properties(options); this.numbering = new Numbering(); - this.relationships = new Relationships(); + this.docRelationships = new Relationships(); + this.docRelationships.createRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml"); + this.docRelationships.createRelationship(2, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml"); + this.docRelationships.createRelationship(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", "header1.xml"); + this.docRelationships.createRelationship(4, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", "footer1.xml"); this.media = new Media(); this.headerWrapper = new HeaderWrapper(this.media); this.footerWrapper = new FooterWrapper(this.media); this.contentTypes = new ContentTypes(); + this.fileRelationships = new Relationships(); + this.fileRelationships.createRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "word/document.xml"); + this.fileRelationships.createRelationship(2, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml"); + this.fileRelationships.createRelationship(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml"); } public addParagraph(paragraph: Paragraph): void { @@ -62,8 +71,8 @@ export class File { } public createImage(image: string): void { - const mediaData = this.media.addMedia(image, this.relationships.RelationshipCount); - this.relationships.createRelationship( + const mediaData = this.media.addMedia(image, this.docRelationships.RelationshipCount); + this.docRelationships.createRelationship( mediaData.referenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`, @@ -91,8 +100,12 @@ export class File { return this.media; } - public get Relationships(): Relationships { - return this.relationships; + public get DocumentRelationships(): Relationships { + return this.docRelationships; + } + + public get FileRelationships(): Relationships { + return this.fileRelationships; } public get Header(): HeaderWrapper { diff --git a/src/file/relationships/relationship/relationship.ts b/src/file/relationships/relationship/relationship.ts index 016df01506..fdf927e1e8 100644 --- a/src/file/relationships/relationship/relationship.ts +++ b/src/file/relationships/relationship/relationship.ts @@ -10,7 +10,10 @@ export type RelationshipType = | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings" | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" - | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"; + | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer" + | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" + | "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" + | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"; export class Relationship extends XmlComponent { constructor(id: string, type: RelationshipType, target: string) { diff --git a/src/file/relationships/relationships.ts b/src/file/relationships/relationships.ts index 2b7043d0a3..debfcada67 100644 --- a/src/file/relationships/relationships.ts +++ b/src/file/relationships/relationships.ts @@ -10,11 +10,6 @@ export class Relationships extends XmlComponent { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships", }), ); - - this.createRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml"); - this.createRelationship(2, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml"); - this.createRelationship(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", "header1.xml"); - this.createRelationship(4, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", "footer1.xml"); } public addRelationship(relationship: Relationship): void { diff --git a/template/_rels/.rels b/template/_rels/.rels deleted file mode 100644 index 32548d4238..0000000000 --- a/template/_rels/.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file