Search code examples
node.jsgoogle-docs-apigoogle-apis-explorer

How to custom page margin in google docs api?


I try to custom my page size and margin but it doesn't working. I had try to used the auto API in the site but the result still not change the margin. Is there any change in the google docs api?

enter image description here


Solution

  • Unfortunately, in the current stage, it seems that documentStyle and content cannot be set with the method of documents.create. Ref I confirmed that this has still not been modified. So as the current workaround, how about the following flow?

    Flow:

    1. Create new Document using the method of documents.create. In this case, the title can be set.

    2. Set updateDocumentStyle using the method of documents.batchUpdate.

      • From your question, the request body for documents.batchUpdate is as follows.

        {
          "requests": [
            {
              "updateDocumentStyle": {
                "documentStyle": {
                  "marginTop": {
                    "magnitude": 100,
                    "unit": "PT"
                  },
                  "marginLeft": {
                    "magnitude": 500,
                    "unit": "PT"
                  }
                },
                "fields": "marginTop,marginLeft"
              }
            }
          ]
        }
        

    References:

    If this was not the direction you want, I apologize.