Home » Php » php – How to insert PAGE_NUMBER and PAGE_COUNT in footer

php – How to insert PAGE_NUMBER and PAGE_COUNT in footer

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m looking for exemple of paragraph and element paragraph in footer.
I’d tried but i only can insert text in footer:

$requests = array (new \Google_Service_Docs_Request(array(
    'insertText' => array(
        'location' => array(
            'segmentId' => $segmentId,
                'index' => 0
            ),
            "text" => 'My Text'
        )
)),

I tried to implement new footers like this :

$footers = array(
        new \Google_Service_Docs_Footer(array(
            'footerId' => $segmentId,
            'content' => [
                'paragraph' => [
                    'element' => [
                        'textRun' => [
                            'content' => 'My Text - '
                        ]
                    ]
                ]
            ]
        )),
        new \Google_Service_Docs_Footer(array(
            'footerId' => $segmentId,
            'content' => [
                  'paragraph' => [
                      'element' => [
                          'AutoText' => [
                              'type' => 'PAGE_NUMBER'
                          ]
                      ]
                  ]
            ]
        )),
        new \Google_Service_Docs_Footer(array(
            'footerId' => $segmentId,
            'content' => [
                'paragraph' => [
                    'element' => [
                        'AutoText' => [
                            'type' => 'PAGE_COUNT'
                        ]
                    ]
                ]
            ]
        ))
    );
    $document->setFooters($footers);

Can we manage paragraph of Footer ?

How to&Answers:

I don’t think you can insert AutoText through the API. There is no valid request from batchUpdate that can be used for that (text inserted via InsertTextRequest has to be a string). As a result of this, PAGE_NUMBER and PAGE_COUNT can only be set through the UI: if you’re using the API, you can only retrieve them.

I’d suggest you to file a Feature Request in this Issue Tracker component regarding this issue.

Reference:

Answer:

Issue in progress https://issuetracker.google.com/issues/149275293
i keep you in touch when i have a feedback