Files
docx-js/src/file/core-properties/properties.ts

55 lines
1.9 KiB
TypeScript
Raw Normal View History

import { XmlComponent } from "file/xml-components";
2017-12-20 00:58:24 +00:00
import { DocumentAttributes } from "../document/document-attributes";
2019-10-04 01:20:41 +01:00
import { Styles } from "../styles";
2017-03-08 21:49:41 +00:00
import { Created, Creator, Description, Keywords, LastModifiedBy, Modified, Revision, Subject, Title } from "./components";
2016-04-03 20:00:30 +01:00
export interface IPropertiesOptions {
readonly title?: string;
readonly subject?: string;
readonly creator?: string;
readonly keywords?: string;
readonly description?: string;
readonly lastModifiedBy?: string;
readonly revision?: string;
readonly externalStyles?: string;
2019-10-04 01:20:41 +01:00
readonly styles?: Styles;
2016-04-03 20:00:30 +01:00
}
2018-02-04 01:43:03 +00:00
export class CoreProperties extends XmlComponent {
2017-03-08 21:49:41 +00:00
constructor(options: IPropertiesOptions) {
2016-04-09 20:16:35 +01:00
super("cp:coreProperties");
2018-01-23 01:33:12 +00:00
this.root.push(
new DocumentAttributes({
cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
dc: "http://purl.org/dc/elements/1.1/",
dcterms: "http://purl.org/dc/terms/",
dcmitype: "http://purl.org/dc/dcmitype/",
xsi: "http://www.w3.org/2001/XMLSchema-instance",
}),
);
if (options.title) {
this.root.push(new Title(options.title));
}
if (options.subject) {
this.root.push(new Subject(options.subject));
}
if (options.creator) {
this.root.push(new Creator(options.creator));
}
if (options.keywords) {
this.root.push(new Keywords(options.keywords));
}
if (options.description) {
this.root.push(new Description(options.description));
}
if (options.lastModifiedBy) {
this.root.push(new LastModifiedBy(options.lastModifiedBy));
}
if (options.revision) {
this.root.push(new Revision(options.revision));
}
2016-04-09 20:16:35 +01:00
this.root.push(new Created());
this.root.push(new Modified());
2016-04-03 20:00:30 +01:00
}
2017-03-08 21:49:41 +00:00
}