Forum


Replies: 5   Views: 190
Roman page number in footer

Posted by hotspot22  · 10-06-2020 - 12:16

Hi,

I've changed the page number type with addSection() to array('fmt'=>'upperRoman'). How do I get this numbering shown in the document footer?

There is already an example for this (changing header to footer and it works):

// create a Word fragment to insert in the default header
$numbering = new WordFragment($docx, 'defaultHeader');

// set some formatting options
$options = array(
        'textAlign' => 'right',
        'bold' => true,
        'sz' => 14,
        'color' => 'B70000',
);
$numbering->addPageNumber('numerical', $options);
$docx->addHeader(array('default' => $numbering));

But the problem is that addPageNumber() only accepts 'numerical', 'alphabetical' and 'page-of'. So there is no way that the page number is Roman.

Please give me an advice, thanks!

Posted by admin  · 10-06-2020 - 12:28

Hello,

What version and license of phpdocx are you using?

The included sample LayoutAndGeneral/addSection/sample_2.php illustrates how to add a page number using lowerRoman number format in a footer. The fmt option is used to change the page numbering type; lowerRoman type isn't set in addPageNumer.

Regards.

Posted by hotspot22  · 10-06-2020 - 12:57

Thanks for the fast reply! It was my fault not checking it in detail before asking :(

License is Premium 9.5.

The shown example in my first post is working perfectly even with sections with different number format types.

I was only checking the first pages having a (unwanted) decimal numbering and not the following pages which are defined with Roman numbering, sorry.

Here is my working example with TOC, page numbering in footer and different page number types:

$docx = new CreateDocx();

// create a Word fragment to insert in the default footer
$numbering = new WordFragment($docx, 'defaultFooter');

// set some formatting options
$options = array(
        'textAlign' => 'right',
        'bold' => true,
        'sz' => 14,
        'color' => 'B70000',
);
$numbering->addPageNumber('numerical', $options);
$docx->addFooter(array('default' => $numbering));

$docx->addText('TOC', array('bold' => true, 'fontSize' => 14));
$legend = array('text' => 'Update TOC',
                'color' => 'B70000',
                'bold' => true,
                'fontSize' => 12);
$docx->addTableContents(array('autoUpdate' => true), $legend);

$docx->addSection('nextPage', 'A4', ['pageNumberType' => ['fmt' => 'upperRoman', 'start' => 2]]);
$docx->addText('Part One', array('pStyle' => 'Heading1PHPDOCX'));
$docx->addText('Lorem ipsum...');
$docx->addText('Heading 1', array('pStyle' => 'Heading2PHPDOCX'));
$docx->addText('Lorem ipsum...');

$docx->addBreak(array('type' => 'page'));
$docx->addText('Heading 2', array('pStyle' => 'Heading2PHPDOCX'));
$docx->addText('Lorem ipsum...');

$docx->addSection('nextPage', 'A4', ['pageNumberType' => ['fmt' => 'decimal', 'start' => 1]]);
$docx->addText('Part Two', array('pStyle' => 'Heading1PHPDOCX'));
$docx->addText('Lorem ipsum...');
$docx->addText('Heading 1', array('pStyle' => 'Heading2PHPDOCX'));

$docx->addBreak(array('type' => 'page'));
$docx->addText('Heading 2', array('pStyle' => 'Heading2PHPDOCX'));
$docx->addText('Lorem ipsum...');

Is it possible to have the TOC items with style Heading1PHPDOCX without a page number in TOC like it's described here: https://support.microsoft.com/en-us/help/319821/how-to-create-table-of-contents-entries-without-a-page-number-in-word ?

And is it possible to remove the page number in footer for specific pages? I want to add a summary page before the TOC and these two pages should have no page number in footer.

Posted by admin  · 10-06-2020 - 13:38

Hello,

Please check the documentation available on https://www.phpdocx.com/documentation/cookbook/headers-and-footers-for-sections . You need to generate a DOCX for each section and merge them; as you are using a Premium package, you can accomplish this task using in-memory documents too (please check the included samples in the package, DocxUtilities/mergeDocx folder).

Regards.

Posted by hotspot22  · 10-06-2020 - 14:13

I think this won't work?!

First document without numbering: summary & TOC
Second document with mixed numbering: Content pages

So how does the TOC get generated when the documents are separated?

Posted by admin  · 10-06-2020 - 14:18

Hello,

TOC content is not updated automatically, after the content has been merged, TOC needs to be updated: https://www.phpdocx.com/documentation/cookbook/tables-of-contents (It is possible to update the TOC automatically when opening the document? section). Updating the TOC is needed in all cases: a single DOCX or multiple DOCX merged into a single document.

Regards.