2018-06-09 23:49:01 +01:00
|
|
|
import { XmlComponent } from "file/xml-components";
|
2018-10-23 00:31:51 +01:00
|
|
|
|
2018-09-17 20:06:51 +01:00
|
|
|
import { FooterReferenceType } from "./document";
|
2018-01-31 00:31:54 +00:00
|
|
|
import { Footer } from "./footer/footer";
|
2018-10-23 00:31:51 +01:00
|
|
|
import { Image, IMediaData, Media } from "./media";
|
2018-08-09 01:55:50 +01:00
|
|
|
import { ImageParagraph, Paragraph } from "./paragraph";
|
2018-01-31 00:31:54 +00:00
|
|
|
import { Relationships } from "./relationships";
|
|
|
|
import { Table } from "./table";
|
|
|
|
|
2018-09-17 20:06:51 +01:00
|
|
|
export interface IDocumentFooter {
|
2018-11-02 02:51:57 +00:00
|
|
|
readonly footer: FooterWrapper;
|
|
|
|
readonly type: FooterReferenceType;
|
2018-09-17 20:06:51 +01:00
|
|
|
}
|
|
|
|
|
2018-01-31 00:31:54 +00:00
|
|
|
export class FooterWrapper {
|
|
|
|
private readonly footer: Footer;
|
|
|
|
private readonly relationships: Relationships;
|
|
|
|
|
2018-10-23 00:31:51 +01:00
|
|
|
constructor(private readonly media: Media, referenceId: number, initContent?: XmlComponent) {
|
2018-09-04 17:16:31 +03:00
|
|
|
this.footer = new Footer(referenceId, initContent);
|
2018-01-31 00:31:54 +00:00
|
|
|
this.relationships = new Relationships();
|
|
|
|
}
|
|
|
|
|
|
|
|
public addParagraph(paragraph: Paragraph): void {
|
|
|
|
this.footer.addParagraph(paragraph);
|
|
|
|
}
|
|
|
|
|
|
|
|
public createParagraph(text?: string): Paragraph {
|
|
|
|
const para = new Paragraph(text);
|
|
|
|
this.addParagraph(para);
|
|
|
|
return para;
|
|
|
|
}
|
|
|
|
|
|
|
|
public addTable(table: Table): void {
|
|
|
|
this.footer.addTable(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
public createTable(rows: number, cols: number): Table {
|
|
|
|
return this.footer.createTable(rows, cols);
|
|
|
|
}
|
|
|
|
|
2018-09-20 00:41:57 +01:00
|
|
|
public addChildElement(childElement: XmlComponent): void {
|
2018-05-28 09:15:44 +02:00
|
|
|
this.footer.addChildElement(childElement);
|
|
|
|
}
|
|
|
|
|
2018-09-14 02:37:03 +01:00
|
|
|
public addImageRelationship(image: Buffer, refId: number, width?: number, height?: number): IMediaData {
|
2018-09-04 17:16:31 +03:00
|
|
|
const mediaData = this.media.addMedia(image, refId, width, height);
|
2018-01-31 00:31:54 +00:00
|
|
|
this.relationships.createRelationship(
|
2018-10-23 00:31:51 +01:00
|
|
|
mediaData.referenceId,
|
2018-01-31 00:31:54 +00:00
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
|
|
|
`media/${mediaData.fileName}`,
|
|
|
|
);
|
2018-09-04 17:16:31 +03:00
|
|
|
return mediaData;
|
|
|
|
}
|
2018-09-07 21:48:59 +01:00
|
|
|
|
2018-10-02 16:17:26 +03:00
|
|
|
public addHyperlinkRelationship(target: string, refId: number, targetMode?: "External" | undefined): void {
|
|
|
|
this.relationships.createRelationship(
|
|
|
|
refId,
|
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
|
|
|
|
target,
|
|
|
|
targetMode,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-23 00:31:51 +01:00
|
|
|
public createImage(image: Buffer | string | Uint8Array | ArrayBuffer, width?: number, height?: number): void {
|
|
|
|
// TODO
|
|
|
|
// tslint:disable-next-line:no-any
|
|
|
|
const mediaData = this.addImageRelationship(image as any, this.relationships.RelationshipCount, width, height);
|
2018-08-09 01:55:50 +01:00
|
|
|
this.addImage(new Image(new ImageParagraph(mediaData)));
|
2018-08-03 00:01:42 +01:00
|
|
|
}
|
|
|
|
|
2018-08-07 01:25:28 +01:00
|
|
|
public addImage(image: Image): FooterWrapper {
|
2018-08-09 01:55:50 +01:00
|
|
|
this.footer.addParagraph(image.Paragraph);
|
2018-08-03 00:01:42 +01:00
|
|
|
return this;
|
2018-01-31 00:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public get Footer(): Footer {
|
|
|
|
return this.footer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get Relationships(): Relationships {
|
|
|
|
return this.relationships;
|
|
|
|
}
|
2018-09-07 21:48:59 +01:00
|
|
|
|
|
|
|
public get Media(): Media {
|
|
|
|
return this.media;
|
|
|
|
}
|
2018-01-31 00:31:54 +00:00
|
|
|
}
|