Add file relationships
This commit is contained in:
@ -41,12 +41,13 @@ export class Compiler {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
const xmlNumbering = xml(this.formatter.format(this.file.Numbering));
|
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 xmlHeader = xml(this.formatter.format(this.file.Header.Header));
|
||||||
const xmlFooter = xml(this.formatter.format(this.file.Footer.Footer));
|
const xmlFooter = xml(this.formatter.format(this.file.Footer.Footer));
|
||||||
const xmlHeaderRelationships = xml(this.formatter.format(this.file.Header.Relationships));
|
const xmlHeaderRelationships = xml(this.formatter.format(this.file.Header.Relationships));
|
||||||
const xmlFooterRelationships = xml(this.formatter.format(this.file.Footer.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, {
|
this.archive.append(xmlDocument, {
|
||||||
name: "word/document.xml",
|
name: "word/document.xml",
|
||||||
@ -84,8 +85,12 @@ export class Compiler {
|
|||||||
name: "word/_rels/footer1.xml.rels",
|
name: "word/_rels/footer1.xml.rels",
|
||||||
});
|
});
|
||||||
|
|
||||||
this.archive.append(xmlContentTypes, {
|
// this.archive.append(xmlContentTypes, {
|
||||||
name: "[Content_Types].xml",
|
// name: "[Content_Types].xml",
|
||||||
|
// });
|
||||||
|
|
||||||
|
this.archive.append(xmlFileRelationships, {
|
||||||
|
name: "_rels/.rels",
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const data of this.file.Media.array) {
|
for (const data of this.file.Media.array) {
|
||||||
|
@ -18,7 +18,8 @@ export class File {
|
|||||||
private readonly properties: Properties;
|
private readonly properties: Properties;
|
||||||
private readonly numbering: Numbering;
|
private readonly numbering: Numbering;
|
||||||
private readonly media: Media;
|
private readonly media: Media;
|
||||||
private readonly relationships: Relationships;
|
private readonly docRelationships: Relationships;
|
||||||
|
private readonly fileRelationships: Relationships;
|
||||||
private readonly headerWrapper: HeaderWrapper;
|
private readonly headerWrapper: HeaderWrapper;
|
||||||
private readonly footerWrapper: FooterWrapper;
|
private readonly footerWrapper: FooterWrapper;
|
||||||
private readonly contentTypes: ContentTypes;
|
private readonly contentTypes: ContentTypes;
|
||||||
@ -38,11 +39,19 @@ export class File {
|
|||||||
|
|
||||||
this.properties = new Properties(options);
|
this.properties = new Properties(options);
|
||||||
this.numbering = new Numbering();
|
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.media = new Media();
|
||||||
this.headerWrapper = new HeaderWrapper(this.media);
|
this.headerWrapper = new HeaderWrapper(this.media);
|
||||||
this.footerWrapper = new FooterWrapper(this.media);
|
this.footerWrapper = new FooterWrapper(this.media);
|
||||||
this.contentTypes = new ContentTypes();
|
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 {
|
public addParagraph(paragraph: Paragraph): void {
|
||||||
@ -62,8 +71,8 @@ export class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public createImage(image: string): void {
|
public createImage(image: string): void {
|
||||||
const mediaData = this.media.addMedia(image, this.relationships.RelationshipCount);
|
const mediaData = this.media.addMedia(image, this.docRelationships.RelationshipCount);
|
||||||
this.relationships.createRelationship(
|
this.docRelationships.createRelationship(
|
||||||
mediaData.referenceId,
|
mediaData.referenceId,
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||||
`media/${mediaData.fileName}`,
|
`media/${mediaData.fileName}`,
|
||||||
@ -91,8 +100,12 @@ export class File {
|
|||||||
return this.media;
|
return this.media;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get Relationships(): Relationships {
|
public get DocumentRelationships(): Relationships {
|
||||||
return this.relationships;
|
return this.docRelationships;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get FileRelationships(): Relationships {
|
||||||
|
return this.fileRelationships;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get Header(): HeaderWrapper {
|
public get Header(): HeaderWrapper {
|
||||||
|
@ -10,7 +10,10 @@ export type RelationshipType =
|
|||||||
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"
|
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"
|
||||||
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering"
|
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering"
|
||||||
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"
|
| "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 {
|
export class Relationship extends XmlComponent {
|
||||||
constructor(id: string, type: RelationshipType, target: string) {
|
constructor(id: string, type: RelationshipType, target: string) {
|
||||||
|
@ -10,11 +10,6 @@ export class Relationships extends XmlComponent {
|
|||||||
xmlns: "http://schemas.openxmlformats.org/package/2006/relationships",
|
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 {
|
public addRelationship(relationship: Relationship): void {
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
||||||
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/></Relationships>
|
|
Reference in New Issue
Block a user