Deprecate createParagraph in all demos

This commit is contained in:
Dolan
2019-06-13 01:07:00 +01:00
parent cb42c74a8d
commit 5497dabaf9
17 changed files with 284 additions and 125 deletions

View File

@ -1,7 +1,7 @@
// Generate a CV
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun } from "../build";
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build";
// tslint:disable:no-shadowed-variable
@ -135,7 +135,12 @@ class DocumentCreator {
const skills = data[2] as object[];
const achivements = data[3] as object[];
const document = new Document();
document.addParagraph(new Paragraph("Dolan Miu").title());
document.addParagraph(
new Paragraph({
text: "Dolan Miu",
heading: HeadingLevel.TITLE,
}),
);
document.addParagraph(this.createContactInfo(PHONE_NUMBER, PROFILE_URL, EMAIL));
document.addParagraph(this.createHeading("Education"));
@ -194,15 +199,18 @@ class DocumentCreator {
);
document.addParagraph(new Paragraph("More references upon request"));
document.addParagraph(
new Paragraph(
"This CV was generated in real-time based on my Linked-In profile from my personal website www.dolan.bio.",
).center(),
new Paragraph({
text: "This CV was generated in real-time based on my Linked-In profile from my personal website www.dolan.bio.",
alignment: AlignmentType.CENTER,
}),
);
return document;
}
public createContactInfo(phoneNumber: string, profileUrl: string, email: string): Paragraph {
const paragraph = new Paragraph().center();
const paragraph = new Paragraph({
alignment: AlignmentType.CENTER,
});
const contactInfo = new TextRun(`Mobile: ${phoneNumber} | LinkedIn: ${profileUrl} | Email: ${email}`);
const address = new TextRun("Address: 58 Elm Avenue, Kent ME4 6ER, UK").break();
@ -213,15 +221,26 @@ class DocumentCreator {
}
public createHeading(text: string): Paragraph {
return new Paragraph(text).heading1().thematicBreak();
return new Paragraph({
text: text,
heading: HeadingLevel.HEADING_1,
thematicBreak: true,
});
}
public createSubHeading(text: string): Paragraph {
return new Paragraph(text).heading2();
return new Paragraph({
text: text,
heading: HeadingLevel.HEADING_2,
});
}
public createInstitutionHeader(institutionName: string, dateText: string): Paragraph {
const paragraph = new Paragraph().maxRightTabStop();
const paragraph = new Paragraph({
tabStop: {
maxRight: {},
},
});
const institution = new TextRun(institutionName).bold();
const date = new TextRun(dateText).tab().bold();
@ -232,7 +251,7 @@ class DocumentCreator {
}
public createRoleText(roleText: string): Paragraph {
const paragraph = new Paragraph();
const paragraph = new Paragraph({});
const role = new TextRun(roleText).italics();
paragraph.addRun(role);
@ -241,12 +260,17 @@ class DocumentCreator {
}
public createBullet(text: string): Paragraph {
return new Paragraph(text).bullet();
return new Paragraph({
text: text,
bullet: {
level: 0,
},
});
}
// tslint:disable-next-line:no-any
public createSkillList(skills: any[]): Paragraph {
const paragraph = new Paragraph();
const paragraph = new Paragraph({});
const skillConcat = skills.map((skill) => skill.name).join(", ") + ".";
paragraph.addRun(new TextRun(skillConcat));
@ -259,7 +283,12 @@ class DocumentCreator {
const arr: Paragraph[] = [];
for (const achievement of achivements) {
const paragraph = new Paragraph(achievement.name).bullet();
const paragraph = new Paragraph({
text: achievement.name,
bullet: {
level: 0,
},
});
arr.push(paragraph);
}
@ -267,7 +296,7 @@ class DocumentCreator {
}
public createInterests(interests: string): Paragraph {
const paragraph = new Paragraph();
const paragraph = new Paragraph({});
paragraph.addRun(new TextRun(interests));
return paragraph;

View File

@ -1,7 +1,7 @@
// Setting styles with JavaScript configuration
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, Paragraph, Table } from "../build";
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, Table } from "../build";
const doc = new Document(undefined, {
top: 700,
@ -84,27 +84,75 @@ doc.Styles.createParagraphStyle("ListParagraph", "List Paragraph")
.basedOn("Normal");
doc.createImage(fs.readFileSync("./demo/images/pizza.gif"));
doc.createParagraph("HEADING")
.heading1()
.center();
doc.addParagraph(
new Paragraph({
text: "HEADING",
heading: HeadingLevel.HEADING_1,
alignment: AlignmentType.CENTER,
}),
);
doc.Footer.createParagraph("1")
.style("normalPara")
.right();
doc.Footer.addParagraph(
new Paragraph({
text: "1",
style: "normalPara",
alignment: AlignmentType.RIGHT,
}),
);
doc.createParagraph("Ref. :").style("normalPara");
doc.createParagraph("Date :").style("normalPara");
doc.addParagraph(
new Paragraph({
text: "Ref. :",
style: "normalPara",
}),
);
doc.addParagraph(
new Paragraph({
text: "Date :",
style: "normalPara",
}),
);
doc.createParagraph("To,").style("normalPara");
doc.createParagraph("The Superindenting Engineer,(O &M)").style("normalPara");
doc.addParagraph(
new Paragraph({
text: "To,",
style: "normalPara",
}),
);
doc.addParagraph(
new Paragraph({
text: "The Superindenting Engineer,(O &M)",
style: "normalPara",
}),
);
doc.createParagraph("Sub : ").style("normalPara");
doc.addParagraph(
new Paragraph({
text: "Sub : ",
style: "normalPara",
}),
);
doc.createParagraph("Ref. : ").style("normalPara");
doc.addParagraph(
new Paragraph({
text: "Ref. : ",
style: "normalPara",
}),
);
doc.createParagraph("Sir,").style("normalPara");
doc.addParagraph(
new Paragraph({
text: "Sir,",
style: "normalPara",
}),
);
doc.createParagraph("BRIEF DESCRIPTION").style("normalPara");
doc.addParagraph(
new Paragraph({
text: "BRIEF DESCRIPTION",
style: "normalPara",
}),
);
const table = new Table({
rows: 4,
@ -130,7 +178,12 @@ const arrboth = [
arrboth.forEach((item) => {
doc.createImage(fs.readFileSync(item.image));
doc.createParagraph(item.comment).style("normalPara2");
doc.addParagraph(
new Paragraph({
text: item.comment,
style: "normalPara2",
}),
);
});
const packer = new Packer();

View File

@ -1,7 +1,7 @@
// This example shows 3 styles using XML styles
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, Paragraph } from "../build";
import { Document, HeadingLevel, Packer, Paragraph } from "../build";
const styles = fs.readFileSync("./demo/assets/custom-styles.xml", "utf-8");
const doc = new Document({
@ -9,16 +9,24 @@ const doc = new Document({
externalStyles: styles,
});
doc.createParagraph("Cool Heading Text").heading1();
doc.addParagraph(new Paragraph({
text: "Cool Heading Text",
heading: HeadingLevel.HEADING_1,
}));
const paragraph = new Paragraph('This is a custom named style from the template "MyFancyStyle"');
paragraph.style("MyFancyStyle");
const paragraph = new Paragraph({
text: 'This is a custom named style from the template "MyFancyStyle"',
style: "MyFancyStyle",
});
doc.addParagraph(paragraph);
doc.createParagraph("Some normal text");
doc.addParagraph(new Paragraph("Some normal text"));
doc.addParagraph(new Paragraph({
text: "MyFancyStyle again",
style: "MyFancyStyle",
}));
doc.createParagraph("MyFancyStyle again").style("MyFancyStyle");
paragraph.style("MyFancyStyle");
doc.addParagraph(paragraph);
const packer = new Packer();

View File

@ -1,22 +1,32 @@
// Page numbers
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun } from "../build";
import { AlignmentType, Document, Packer, Paragraph, TextRun } from "../build";
const doc = new Document();
doc.createParagraph("First Page").pageBreak();
doc.createParagraph("Second Page");
doc.addParagraph(
new Paragraph({
text: "First Page",
}).pageBreak(),
);
doc.addParagraph(new Paragraph("Second Page"));
const pageNumber = new TextRun("Page ").pageNumber();
const pageoneheader = new Paragraph("First Page Header ").right();
const pageoneheader = new Paragraph({
text: "First Page Header ",
alignment: AlignmentType.RIGHT,
});
pageoneheader.addRun(pageNumber);
const firstPageHeader = doc.createFirstPageHeader();
firstPageHeader.addParagraph(pageoneheader);
const pagetwoheader = new Paragraph("My Title ").right();
const pagetwoheader = new Paragraph({
text: "My Title ",
alignment: AlignmentType.RIGHT,
});
pagetwoheader.addRun(pageNumber);
doc.Header.addParagraph(pagetwoheader);

View File

@ -6,7 +6,10 @@ import { Document, Packer, Paragraph } from "../build";
const doc = new Document();
const paragraph = new Paragraph("Hello World");
const paragraph2 = new Paragraph("Hello World on another page").pageBreakBefore();
const paragraph2 = new Paragraph({
text: "Hello World on another page",
pageBreakBefore: true,
});
doc.addParagraph(paragraph);
doc.addParagraph(paragraph2);

View File

@ -10,9 +10,9 @@ const paragraph = new Paragraph("Hello World").pageBreak();
doc.addParagraph(paragraph);
const header = doc.createHeader();
header.createParagraph("Header on another page");
header.addParagraph(new Paragraph("Header on another page"));
const footer = doc.createFooter();
footer.createParagraph("Footer on another page");
footer.addParagraph(new Paragraph("Footer on another page"));
doc.addSection({
headers: {
@ -25,7 +25,7 @@ doc.addSection({
pageNumberFormatType: PageNumberFormat.DECIMAL,
});
doc.createParagraph("hello");
doc.addParagraph(new Paragraph("hello"));
doc.addSection({
headers: {
@ -39,11 +39,11 @@ doc.addSection({
orientation: PageOrientation.LANDSCAPE,
});
doc.createParagraph("hello in landscape");
doc.addParagraph(new Paragraph("hello in landscape"));
const header2 = doc.createHeader();
const pageNumber = new TextRun("Page number: ").pageNumber();
header2.createParagraph().addRun(pageNumber);
header2.addParagraph(new Paragraph({}).addRun(pageNumber));
doc.addSection({
headers: {
@ -52,7 +52,7 @@ doc.addSection({
orientation: PageOrientation.PORTRAIT,
});
doc.createParagraph("Page number in the header must be 2, because it continues from the previous section.");
doc.addParagraph(new Paragraph("Page number in the header must be 2, because it continues from the previous section."));
doc.addSection({
headers: {
@ -62,9 +62,9 @@ doc.addSection({
orientation: PageOrientation.PORTRAIT,
});
doc.createParagraph(
doc.addParagraph(new Paragraph(
"Page number in the header must be III, because it continues from the previous section, but is defined as upper roman.",
);
));
doc.addSection({
headers: {
@ -75,7 +75,7 @@ doc.addSection({
orientation: PageOrientation.PORTRAIT,
});
doc.createParagraph("Page number in the header must be 25, because it is defined to start at 25 and to be decimal in this section.");
doc.addParagraph(new Paragraph("Page number in the header must be 25, because it is defined to start at 25 and to be decimal in this section."));
const packer = new Packer();

View File

@ -1,7 +1,7 @@
// Example on how to customise the look at feel using Styles
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer } from "../build";
import { Document, Packer, Paragraph, TextRun, HeadingLevel } from "../build";
const doc = new Document({
creator: "Clippy",
@ -46,30 +46,56 @@ doc.Styles.createParagraphStyle("ListParagraph", "List Paragraph")
const numberedAbstract = doc.Numbering.createAbstractNumbering();
numberedAbstract.createLevel(0, "lowerLetter", "%1)", "left");
doc.createParagraph("Test heading1, bold and italicized").heading1();
doc.createParagraph("Some simple content");
doc.createParagraph("Test heading2 with double red underline").heading2();
doc.addParagraph(
new Paragraph({
text: "Test heading1, bold and italicized",
heading: HeadingLevel.HEADING_1,
}),
);
doc.addParagraph(new Paragraph("Some simple content"));
doc.addParagraph(
new Paragraph({
text: "Test heading2 with double red underline",
heading: HeadingLevel.HEADING_2,
}),
);
const letterNumbering = doc.Numbering.createConcreteNumbering(numberedAbstract);
const letterNumbering5 = doc.Numbering.createConcreteNumbering(numberedAbstract);
letterNumbering5.overrideLevel(0, 5);
doc.createParagraph("Option1").setNumbering(letterNumbering, 0);
doc.createParagraph("Option5 -- override 2 to 5").setNumbering(letterNumbering5, 0);
doc.createParagraph("Option3").setNumbering(letterNumbering, 0);
doc.addParagraph(
new Paragraph({
text: "Option1",
numbering: {
num: letterNumbering,
level: 0,
},
}),
);
doc.addParagraph(new Paragraph("Option5 -- override 2 to 5").setNumbering(letterNumbering5, 0));
doc.addParagraph(new Paragraph("Option3").setNumbering(letterNumbering, 0));
doc
.createParagraph()
.createTextRun("Some monospaced content")
.font("Monospace");
doc.addParagraph(new Paragraph({}).addRun(new TextRun("Some monospaced content").font("Monospace")));
doc.createParagraph("An aside, in light gray italics and indented").style("aside");
doc.createParagraph("This is normal, but well-spaced text").style("wellSpaced");
const para = doc.createParagraph();
para.createTextRun("This is a bold run,").bold();
para.createTextRun(" switching to normal ");
para.createTextRun("and then underlined ").underline();
para.createTextRun("and back to normal.");
doc.addParagraph(
new Paragraph({
text: "An aside, in light gray italics and indented",
style: "aside",
}),
);
doc.addParagraph(
new Paragraph({
text: "This is normal, but well-spaced text",
style: "wellSpaced",
}),
);
const para = new Paragraph({});
doc.addParagraph(para);
para.addRun(new TextRun("This is a bold run,").bold());
para.addRun(new TextRun(" switching to normal "));
para.addRun(new TextRun("and then underlined ").underline());
para.addRun(new TextRun("and back to normal."));
const packer = new Packer();

View File

@ -1,7 +1,7 @@
// This demo shows how to create bookmarks then link to them with internal hyperlinks
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer } from "../build";
import { Document, HeadingLevel, Packer, Paragraph } from "../build";
const loremIpsum =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam mi velit, convallis convallis scelerisque nec, faucibus nec leo. Phasellus at posuere mauris, tempus dignissim velit. Integer et tortor dolor. Duis auctor efficitur mattis. Vivamus ut metus accumsan tellus auctor sollicitudin venenatis et nibh. Cras quis massa ac metus fringilla venenatis. Proin rutrum mauris purus, ut suscipit magna consectetur id. Integer consectetur sollicitudin ante, vitae faucibus neque efficitur in. Praesent ultricies nibh lectus. Mauris pharetra id odio eget iaculis. Duis dictum, risus id pellentesque rutrum, lorem quam malesuada massa, quis ullamcorper turpis urna a diam. Cras vulputate metus vel massa porta ullamcorper. Etiam porta condimentum nulla nec tristique. Sed nulla urna, pharetra non tortor sed, sollicitudin molestie diam. Maecenas enim leo, feugiat eget vehicula id, sollicitudin vitae ante.";
@ -17,18 +17,20 @@ const anchorId = "anchorID";
// First create the bookmark
const bookmark = doc.createBookmark(anchorId, "Lorem Ipsum");
// That has header styling
doc
.createParagraph()
.addBookmark(bookmark)
.heading1();
doc.createParagraph("\n");
doc.addParagraph(
new Paragraph({
heading: HeadingLevel.HEADING_1,
}).addBookmark(bookmark),
);
doc.createParagraph(loremIpsum);
doc.createParagraph().pageBreak();
doc.addParagraph(new Paragraph("\n"));
doc.addParagraph(new Paragraph(loremIpsum));
doc.addParagraph(new Paragraph({}).pageBreak());
// Now the link back up to the bookmark
const hyperlink = doc.createInternalHyperLink(anchorId, `Click me!`);
doc.createParagraph().addHyperLink(hyperlink);
doc.addParagraph(new Paragraph({}).addHyperLink(hyperlink));
const packer = new Packer();

View File

@ -1,14 +1,15 @@
// Custom styles using JavaScript configuration
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer } from "../build";
import { Document, HeadingLevel, Packer, Paragraph } from "../build";
const doc = new Document();
const myStyles = doc.Styles;
// The first argument is an ID you use to apply the style to paragraphs
// The second argument is a human-friendly name to show in the UI
myStyles.createParagraphStyle("myWonkyStyle", "My Wonky Style")
myStyles
.createParagraphStyle("myWonkyStyle", "My Wonky Style")
.basedOn("Normal")
.next("Normal")
.color("990000")
@ -16,7 +17,8 @@ myStyles.createParagraphStyle("myWonkyStyle", "My Wonky Style")
.indent({ left: 720 }) // 720 TWIP === 720 / 20 pt === .5 in
.spacing({ line: 276 }); // 276 / 240 = 1.15x line spacing
myStyles.createParagraphStyle("Heading2", "Heading 2")
myStyles
.createParagraphStyle("Heading2", "Heading 2")
.basedOn("Normal")
.next("Normal")
.quickFormat()
@ -25,8 +27,18 @@ myStyles.createParagraphStyle("Heading2", "Heading 2")
.underline("double", "FF0000")
.spacing({ before: 240, after: 120 }); // TWIP for both
doc.createParagraph("Hello").style("myWonkyStyle");
doc.createParagraph("World").heading2(); // Uses the Heading2 style
doc.addParagraph(
new Paragraph({
text: "Hello",
style: "myWonkyStyle",
}),
);
doc.addParagraph(
new Paragraph({
text: "World",
heading: HeadingLevel.HEADING_2,
}),
); // Uses the Heading2 style
const packer = new Packer();

View File

@ -1,7 +1,7 @@
// Example of how you would merge cells together
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, Paragraph, ShadingType, WidthType } from "../build";
import { Document, HeadingLevel, Packer, Paragraph, ShadingType, WidthType } from "../build";
const doc = new Document();
@ -13,7 +13,12 @@ let table = doc.createTable({
table.getCell(0, 0).addParagraph(new Paragraph("Hello"));
table.getRow(0).mergeCells(0, 1);
doc.createParagraph("Another table").heading2();
doc.addParagraph(
new Paragraph({
text: "Another table",
heading: HeadingLevel.HEADING_2,
}),
);
table = doc.createTable({
rows: 2,
@ -33,7 +38,12 @@ table
});
table.getRow(0).mergeCells(0, 2);
doc.createParagraph("Another table").heading2();
doc.addParagraph(
new Paragraph({
text: "Another table",
heading: HeadingLevel.HEADING_2,
}),
);
table = doc.createTable({
rows: 2,
@ -85,7 +95,7 @@ table
table.getRow(0).mergeCells(0, 3);
doc.createParagraph("hi");
doc.addParagraph(new Paragraph("hi"));
doc.createTable({
rows: 2,

View File

@ -12,7 +12,6 @@ const table = new Table({
});
table.getCell(1, 1).addParagraph(image.Paragraph);
// doc.createParagraph("Hello World");
doc.addTable(table);
// doc.Header.createImage(fs.readFileSync("./demo/images/pizza.gif"));

View File

@ -1,11 +1,11 @@
// Add images to header and footer
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Media, Packer } from "../build";
import { Document, Media, Packer, Paragraph } from "../build";
const doc = new Document();
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
doc.createParagraph("Hello World");
doc.addParagraph(new Paragraph("Hello World"));
doc.Header.addImage(image);
doc.Header.createImage(fs.readFileSync("./demo/images/pizza.gif"));

View File

@ -2,21 +2,21 @@
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
// import { Document, Packer, Paragraph } from "../build";
import { Document, Packer, TextWrappingSide, TextWrappingType } from "../build";
import { Document, Packer, Paragraph, TextWrappingSide, TextWrappingType } from "../build";
const doc = new Document();
doc.createParagraph(
doc.addParagraph(new Paragraph(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vehicula nec nulla vitae efficitur. Ut interdum mauris eu ipsum rhoncus, nec pharetra velit placerat. Sed vehicula libero ac urna molestie, id pharetra est pellentesque. Praesent iaculis vehicula fringilla. Duis pretium gravida orci eu vestibulum. Mauris tincidunt ipsum dolor, ut ornare dolor pellentesque id. Integer in nulla gravida, lacinia ante non, commodo ex. Vivamus vulputate nisl id lectus finibus vulputate. Ut et nisl mi. Cras fermentum augue arcu, ac accumsan elit euismod id. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed ac posuere nisi. Pellentesque tincidunt vehicula bibendum. Phasellus eleifend viverra nisl.",
);
));
doc.createParagraph(
doc.addParagraph(new Paragraph(
"Proin ac purus faucibus, porttitor magna ut, cursus nisl. Vivamus ante purus, porta accumsan nibh eget, eleifend dignissim odio. Integer sed dictum est, aliquam lacinia justo. Donec ultrices auctor venenatis. Etiam interdum et elit nec elementum. Pellentesque nec viverra mauris. Etiam suscipit leo nec velit fringilla mattis. Pellentesque justo lacus, sodales eu condimentum in, dapibus finibus lacus. Morbi vitae nibh sit amet sem molestie feugiat. In non porttitor enim.",
);
));
doc.createParagraph(
doc.addParagraph(new Paragraph(
"Ut eget diam cursus quam accumsan interdum at id ante. Ut mollis mollis arcu, eu scelerisque dui tempus in. Quisque aliquam, augue quis ornare aliquam, ex purus ultrices mauris, ut porta dolor dolor nec justo. Nunc a tempus odio, eu viverra arcu. Suspendisse vitae nibh nec mi pharetra tempus. Mauris ut ullamcorper sapien, et sagittis sapien. Vestibulum in urna metus. In scelerisque, massa id bibendum tempus, quam orci rutrum turpis, a feugiat nisi ligula id metus. Praesent id dictum purus. Proin interdum ipsum nulla.",
);
));
doc.createImage(fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
floating: {

View File

@ -1,7 +1,7 @@
// Example how to display page numbers
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, PageNumberFormat, TextRun } from "../build";
import { AlignmentType, Document, Packer, PageNumberFormat, Paragraph, TextRun } from "../build";
const doc = new Document(
{},
@ -11,20 +11,24 @@ const doc = new Document(
},
);
doc.Header.createParagraph("Foo Bar corp. ")
.addRun(new TextRun("Page Number ").pageNumber())
.addRun(new TextRun(" to ").numberOfTotalPages());
doc.Header.addParagraph(
new Paragraph("Foo Bar corp. ").addRun(new TextRun("Page Number ").pageNumber()).addRun(new TextRun(" to ").numberOfTotalPages()),
);
doc.Footer.createParagraph("Foo Bar corp. ")
.center()
doc.Footer.addParagraph(
new Paragraph({
text: "Foo Bar corp. ",
alignment: AlignmentType.CENTER,
})
.addRun(new TextRun("Page Number: ").pageNumber())
.addRun(new TextRun(" to ").numberOfTotalPages());
.addRun(new TextRun(" to ").numberOfTotalPages()),
);
doc.createParagraph("Hello World 1").pageBreak();
doc.createParagraph("Hello World 2").pageBreak();
doc.createParagraph("Hello World 3").pageBreak();
doc.createParagraph("Hello World 4").pageBreak();
doc.createParagraph("Hello World 5").pageBreak();
doc.addParagraph(new Paragraph("Hello World 1").pageBreak());
doc.addParagraph(new Paragraph("Hello World 2").pageBreak());
doc.addParagraph(new Paragraph("Hello World 3").pageBreak());
doc.addParagraph(new Paragraph("Hello World 4").pageBreak());
doc.addParagraph(new Paragraph("Hello World 5").pageBreak());
const packer = new Packer();

View File

@ -1,7 +1,7 @@
// Example of how to change page borders
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun } from "../build";
import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build";
const doc = new Document(undefined, {
top: 0,
@ -18,9 +18,12 @@ paragraph.addRun(dateText);
doc.addParagraph(paragraph);
doc.createParagraph("Hello World").heading1();
doc.createParagraph("Foo bar");
doc.createParagraph("Github is the best");
doc.addParagraph(new Paragraph({
text: "Hello World",
heading: HeadingLevel.HEADING_1,
}));
doc.addParagraph(new Paragraph("Foo bar"));
doc.addParagraph(new Paragraph("Github is the best"));
const packer = new Packer();

View File

@ -1,14 +1,14 @@
// Add text to header and footer
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer } from "../build";
import { Document, Packer, Paragraph } from "../build";
const doc = new Document();
doc.createParagraph("Hello World");
doc.addParagraph(new Paragraph("Hello World"));
doc.Header.createParagraph("Header text");
doc.Footer.createParagraph("Footer text");
doc.Header.addParagraph(new Paragraph("Header text"));
doc.Footer.addParagraph(new Paragraph("Footer text"));
const packer = new Packer();

View File

@ -1,11 +1,11 @@
// Add images to header and footer
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer } from "../build";
import { Document, Packer, Paragraph } from "../build";
const doc = new Document();
doc.createParagraph("Hello World");
doc.addParagraph(new Paragraph("Hello World"));
doc.Header.createImage(fs.readFileSync("./demo/images/pizza.gif"));
doc.Footer.createImage(fs.readFileSync("./demo/images/pizza.gif"));