-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #239 Embedded fonts * Add boilerplate for font table * Fix linting * Fix linting * Fix odttf naming * Correct writing of fonts to relationships and font table new uuid function * Add font to run * Add demo Fix tests * Add character set support * Add tests * Write tests
- Loading branch information
Showing
28 changed files
with
794 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"iife", | ||
"Initializable", | ||
"iroha", | ||
"JOHAB", | ||
"jsonify", | ||
"jszip", | ||
"NUMPAGES", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Simple example to add text to a document | ||
|
||
import * as fs from "fs"; | ||
import { CharacterSet, Document, Packer, Paragraph, Tab, TextRun } from "docx"; | ||
|
||
const font = fs.readFileSync("./demo/assets/Pacifico.ttf"); | ||
|
||
const doc = new Document({ | ||
sections: [ | ||
{ | ||
properties: {}, | ||
children: [ | ||
new Paragraph({ | ||
run: { | ||
font: "Pacifico", | ||
}, | ||
children: [ | ||
new TextRun("Hello World"), | ||
new TextRun({ | ||
text: "Foo Bar", | ||
bold: true, | ||
size: 40, | ||
font: "Pacifico", | ||
}), | ||
new TextRun({ | ||
children: [new Tab(), "Github is the best"], | ||
bold: true, | ||
font: "Pacifico", | ||
}), | ||
], | ||
}), | ||
], | ||
}, | ||
], | ||
fonts: [{ name: "Pacifico", data: font, characterSet: CharacterSet.ANSI }], | ||
}); | ||
|
||
Packer.toBuffer(doc).then((buffer) => { | ||
fs.writeFileSync("My Document.docx", buffer); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Simple example to add text to a document | ||
|
||
import * as fs from "fs"; | ||
import { Document, Packer, Paragraph, Tab, TextRun } from "docx"; | ||
|
||
const font = fs.readFileSync("./demo/assets/Pacifico.ttf"); | ||
|
||
const doc = new Document({ | ||
styles: { | ||
default: { | ||
document: { | ||
run: { | ||
font: "Pacifico", | ||
}, | ||
}, | ||
}, | ||
}, | ||
sections: [ | ||
{ | ||
properties: {}, | ||
children: [ | ||
new Paragraph({ | ||
children: [ | ||
new TextRun("Hello World"), | ||
new TextRun({ | ||
text: "Foo Bar", | ||
bold: true, | ||
size: 40, | ||
}), | ||
new TextRun({ | ||
children: [new Tab(), "Github is the best"], | ||
bold: true, | ||
}), | ||
], | ||
}), | ||
], | ||
}, | ||
], | ||
fonts: [{ name: "Pacifico", data: font, characterSet: "00" }], | ||
}); | ||
|
||
Packer.toBuffer(doc).then((buffer) => { | ||
fs.writeFileSync("My Document.docx", buffer); | ||
}); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./", | ||
"paths": { | ||
"docx": ["../build"] | ||
} | ||
}, | ||
"include": ["../demo"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.