Can Google Docs API be used to begin page numbering on the third page?

Hey everyone! I’m trying to figure out how to make the page numbers in my Google Doc start on the third page instead of the second. Right now, they’re showing up on the Table of Contents page, but I want them to begin in the actual content section.

I tried a workaround by making a template with three blank pages at the start. On the third page, I put a footer and set the page number to 1. But it didn’t work out like I hoped.

Does anyone know if there’s a way to do this with the Google Docs API? I’m not sure if it’s even possible or if I’m missing something obvious. Any tips or tricks would be super helpful!

Here’s a quick example of what I tried in code:

def set_page_numbering(doc_id):
    service = build('docs', 'v1', credentials=creds)

    requests = [
        {
            'insertPageBreak': {
                'location': {
                    'index': 0
                }
            }
        },
        {
            'insertPageBreak': {
                'location': {
                    'index': 1
                }
            }
        },
        {
            'createFooter': {
                'sectionBreakLocation': {
                    'index': 2
                }
            }
        },
        {
            'insertPageNumber': {
                'location': {
                    'segmentId': 'footer'
                },
                'index': 1
            }
        }
    ]

    service.documents().batchUpdate(documentId=doc_id, body={'requests': requests}).execute()

This didn’t quite do what I wanted. Any ideas on how to make it work?

hey there, i’ve played around with the docs API too and it’s a bit tricky for page numbers. have you tried using section breaks? you could add two breaks, one after the title and another after contents. then set up a footer just for the third section with page numbers. it’s not perfect but might work. good luck!

I have used the Google Docs API on several occasions, and based on my experience there isn’t a native method to set the page numbering to begin on a specific page such as the third one. The API does not offer the fine-grained control over page numbering settings that desktop applications might allow. A practical solution involves separating the document into sections. You can insert a section break after the second page and then configure the first section without numbering while setting up the footer in the subsequent section to display page numbers. This method requires careful formatting and may need minor manual adjustments afterwards.

As someone who’s worked extensively with Google Docs API, I can tell you that controlling page numbering isn’t straightforward. Your approach with the template is creative, but the API doesn’t handle it well. In my projects, I’ve found a workaround that might help. Instead of trying to manipulate page numbers directly, focus on creating distinct sections in your document.

Try inserting two section breaks - one after your title page and another after the table of contents. Then, in your API calls, you can apply different footer settings to each section. The tricky part is getting the indices right for each section. It took me a few attempts to get it working consistently.

Here’s a rough idea of how to structure your API requests:

  1. Insert section breaks
  2. Create a footer for the third section
  3. Insert page numbering in that footer

It’s not perfect, but it’s the closest I’ve gotten to achieving what you’re after. Just be prepared for some trial and error with the exact placement of elements.