Docx: [question] how do I configure default page size for printing?

Created on 4 Apr 2019  路  5Comments  路  Source: dolanmiu/docx

I'm digging through the code but cannot seem to find how to configure the default page setup for printing:
Screen Shot 2019-04-04 at 15 56 26

docx seems to have a default of A4, but I am trying to set it to US Letter format. Do you know where I can configure this programmatically?
I think this is different from page margins (e.g. https://github.com/dolanmiu/docx/issues/50) but could be wrong.

Most helpful comment

It looks the pgSz in word/document.xml controls this setting:

<sectPr rsidR="0091789E" rsidSect="00A53414">
    <headerReference type="default" id="rId17"/>
    <footerReference type="default" id="rId18"/>
    <pgSz w="12240" h="15840"/>
    <pgMar top="1440" right="714" bottom="1252" left="714" header="708" footer="708" gutter="0"/>
    <cols space="708"/>
    <docGrid linePitch="360"/>
</sectPr>

I would be interested in setting this programmatically once for the entire document.

All 5 comments

It looks the pgSz in word/document.xml controls this setting:

<sectPr rsidR="0091789E" rsidSect="00A53414">
    <headerReference type="default" id="rId17"/>
    <footerReference type="default" id="rId18"/>
    <pgSz w="12240" h="15840"/>
    <pgMar top="1440" right="714" bottom="1252" left="714" header="708" footer="708" gutter="0"/>
    <cols space="708"/>
    <docGrid linePitch="360"/>
</sectPr>

I would be interested in setting this programmatically once for the entire document.

There is the Page Size function, but I can't seem to get it to work and haven't found any examples of its use.

@LSchaming I think you can control it when you initialize the document:

            const doc = new docx.Document(
                {

                    title: 'my document',

                },
                {
                    right: 714,
                    bottom: 1252,
                    left: 714
                }
            );

The second argument above is a ipagemarginattributes object. You may have to explore the definitions a bit more to fine tune those options (using visual studio code to jump to definitions). Nonetheless, I think better documentation is needed.

@dolanmiu Any help on this?

There's still no support for entire page margins, and the documentation isn't clear about that

This is how I create a US Letter sized page in landscape with small margins using [email protected]:

const doc = new docx.Document();

doc.addSection({
    size: {
        width: 12240, // width and height transposed in LANDSCAPE
        height: 15840,
        orientation: docx.PageOrientation.LANDSCAPE
    },
    margins: {
        top: 720,
        right: 720,
        bottom: 720,
        left: 720
    },
    children: [new docx.Paragraph('some text')]
});

Units in Word are often in DXAs

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brunogaleski picture brunogaleski  路  6Comments

madarche picture madarche  路  5Comments

zeco2309 picture zeco2309  路  5Comments

jacwright picture jacwright  路  6Comments

davideickhoff picture davideickhoff  路  6Comments