Search code examples
phpphpword

PhpWord roman numeral for page number


I'm using this phpword library: https://github.com/PHPOffice/PHPWord

And I have a trouble about roman numeral in page number, Is it possible for phpword to show page number in roman numeral instead of standard numeral?

i found this line of code in the library:

protected $fieldsArray = array(
        'PAGE' => array(
           'properties' => array(
               'format' => array('Arabic', 'ArabicDash', 'alphabetic', 'ALPHABETIC', 'roman', 'ROMAN'),
           ),
           'options' => array('PreserveFormat'),
        ),
...
);

just wonder how i can get it.


Solution

  • You can achieve this as follows

    $phpWord = new PhpWord();
    $section = $phpWord->addSection();
    $footer = $section->addFooter();
    $textRun = $footer->addTextRun(array('alignment' => Jc::CENTER));
    $textRun->addField('PAGE', array('format' => 'ROMAN'));
    $textRun->addText(' of ');
    $textRun->addField('NUMPAGES', array('format' => 'ROMAN'));