Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the default document margins in docxjs

I'm using the DOCXJS library and was wondering if it was possible to reduce the default document margins.

I found that the docs briefly mention that you can alter margins of sections, though they don't explain how.

like image 787
Sjos Sivlingworkz Avatar asked Sep 15 '25 14:09

Sjos Sivlingworkz


1 Answers

Fixed it by checking out the demos. The syntax that should be used is:

const doc = new Document({
sections: [
    {
        properties: {
            page: {
                margin: {
                    top: 0,
                    right: 0,
                    bottom: 0,
                    left: 0,
                },
            },
        },
        children: [new docx.Paragraph({text:"Hello World!"})],
    },
],

});

like image 170
Sjos Sivlingworkz Avatar answered Sep 17 '25 05:09

Sjos Sivlingworkz