diff --git a/demo/demo16.js b/demo/demo16.js new file mode 100644 index 0000000000..ea6308eb46 --- /dev/null +++ b/demo/demo16.js @@ -0,0 +1,14 @@ +const docx = require('../build'); + +var doc = new docx.Document(); + +var paragraph = new docx.Paragraph("Hello World").referenceFootnote(1); + +doc.addParagraph(paragraph); + +doc.createFootnote(new docx.Paragraph("Test")); + +var exporter = new docx.LocalPacker(doc); +exporter.pack('My Document'); + +console.log('Document created successfully at project root!'); diff --git a/src/file/content-types/content-types.ts b/src/file/content-types/content-types.ts index 9bb3837cb2..cbb078d058 100644 --- a/src/file/content-types/content-types.ts +++ b/src/file/content-types/content-types.ts @@ -32,5 +32,6 @@ export class ContentTypes extends XmlComponent { this.root.push(new Override("application/vnd.openxmlformats-package.core-properties+xml", "/docProps/core.xml")); this.root.push(new Override("application/vnd.openxmlformats-officedocument.extended-properties+xml", "/docProps/app.xml")); this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", "/word/numbering.xml")); + this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml", "/word/footnotes.xml")); } } diff --git a/src/file/file.ts b/src/file/file.ts index 5ee6c175b3..e3250d93a6 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -163,6 +163,10 @@ export class File { return hyperlink; } + public createFootnote(paragraph: Paragraph): void { + this.footNotes.createFootNote(paragraph); + } + public get Document(): Document { return this.document; } diff --git a/src/file/footnotes/footnotes.ts b/src/file/footnotes/footnotes.ts index d53ef4f02d..67f8e36022 100644 --- a/src/file/footnotes/footnotes.ts +++ b/src/file/footnotes/footnotes.ts @@ -1,6 +1,8 @@ import { XmlComponent } from "file/xml-components"; import { Paragraph } from "../paragraph"; import { FootNote } from "./footnote/footnote"; +import { ContinuationSeperatorRun } from "./footnote/run/continuation-seperator-run"; +import { SeperatorRun } from "./footnote/run/seperator-run"; import { FootnotesAttributes } from "./footnotes-attributes"; export class FootNotes extends XmlComponent { @@ -28,32 +30,30 @@ export class FootNotes extends XmlComponent { }), ); - const begin = new FootNote(-1); + const begin = new FootNote(-1, "separator"); begin.addParagraph( new Paragraph().spacing({ after: 0, line: 240, lineRule: "auto", - }), + }).addRun(new SeperatorRun()), ); this.root.push(begin); - const spacing = new FootNote(0); + const spacing = new FootNote(0, "continuationSeparator"); spacing.addParagraph( new Paragraph().spacing({ after: 0, line: 240, lineRule: "auto", - }), + }).addRun(new ContinuationSeperatorRun()), ); this.root.push(spacing); } - public createFootNote(): void { - // TODO - } - - public getFootNote(): void { - // TODO + public createFootNote(paragraph: Paragraph): void { + const footnote = new FootNote(1); + footnote.addParagraph(paragraph); + this.root.push(footnote); } } diff --git a/src/file/paragraph/paragraph.ts b/src/file/paragraph/paragraph.ts index 970c4bfae9..9a6e68065a 100644 --- a/src/file/paragraph/paragraph.ts +++ b/src/file/paragraph/paragraph.ts @@ -1,8 +1,8 @@ // http://officeopenxml.com/WPparagraph.php +import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run"; import { IMediaData } from "file/media"; import { Num } from "file/numbering/num"; import { XmlComponent } from "file/xml-components"; -import { PictureRun, Run, TextRun } from "./run"; import { Alignment } from "./formatting/alignment"; import { ThematicBreak } from "./formatting/border"; @@ -15,6 +15,7 @@ import { CenterTabStop, LeftTabStop, MaxRightTabStop, RightTabStop } from "./for import { NumberProperties } from "./formatting/unordered-list"; import { Hyperlink } from "./links"; import { ParagraphProperties } from "./properties"; +import { PictureRun, Run, TextRun } from "./run"; export class Paragraph extends XmlComponent { private properties: ParagraphProperties; @@ -181,4 +182,9 @@ export class Paragraph extends XmlComponent { this.properties.push(new KeepLines()); return this; } + + public referenceFootnote(id: number): Paragraph { + this.root.push(new FootnoteReferenceRun(id)); + return this; + } } diff --git a/src/file/paragraph/run/run.ts b/src/file/paragraph/run/run.ts index b913e49df4..c258c52702 100644 --- a/src/file/paragraph/run/run.ts +++ b/src/file/paragraph/run/run.ts @@ -13,7 +13,7 @@ import { Underline } from "./underline"; import { XmlComponent } from "file/xml-components"; export class Run extends XmlComponent { - private properties: RunProperties; + protected properties: RunProperties; constructor() { super("w:r");