Hi guys!
Infortunally, there is no documentation in the Wiki for setting the document default styles.
Is it possible to do that? If yes, how can I do it? I will be glad to contribute to improve the documentation for that. If no, I will be glad to make a pull request for that.
Setting default styles is not documented, but it can be found here:
https://github.com/dolanmiu/docx/blob/master/demo/demo2.js
Or you can do this:
https://docx.js.org/#/usage/styling-with-xml
Is this what you mean?
The documentation says:
There are a few different ways of styling this content in DOCX, which somewhat resemble the HTML/CSS approach. In order of greatest to lowest priority:
I'm talking about item 3. There's no example of how to do that.
AFAIK, it is not implemented yet
Here is the default styles:
https://github.com/dolanmiu/docx/blob/master/src/file/styles/sample/index.ts
And here is where it adds document defaults to the document:
https://github.com/dolanmiu/docx/blob/master/src/file/styles/index.ts#L19-L21
If you can make a PR for number 3, that would be nice
I wasn't part of the development of this feature, so admittedly I don't know much about it
Was the above implemented? (Document defaults. [specifically font & size])
if so can you please explain how to use it?
Styles are set like so:
https://github.com/dolanmiu/docx/blob/master/demo/2-declaritive-styles.ts
Hello, I also try to use default styling on my document
No problem with declarative style, but I'd like to set a font family and font-size by default for ALL the paragraphs without applying a class on every paragraphs for the style to be applied...
As @sergiofm I'm trying to implement : Document defaults (similar to a * rule in CSS)...
Answer is really here but it's unclear, IMHO.
I've tried to change different props and found out that name should set to Normal if u want to override default styles.
For example, set default text color to red and make it bold:
const doc = new Document({
styles: {
paragraphStyles: [
{
// Only `name` prop required, `id` not necessary
name: 'Normal',
run: {
color: '#ff0000',
bold: true,
},
],
},
})
@dolanmiu, pls point this in docs.
Most helpful comment
The documentation says:
There are a few different ways of styling this content in DOCX, which somewhat resemble the HTML/CSS approach. In order of greatest to lowest priority:
I'm talking about item 3. There's no example of how to do that.