Forum


Replies: 4   Views: 3404
Font size ignored ?
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by Simco Nederland  · 08-01-2018 - 09:41

             $numbering = new \Phpdocx\Elements\WordFragment($docx, 'defaultHeader');
                $numberoptions = array(
                        'textAlign' => 'right',
                'bold' => true,
                'fontSize' => 9,
                'color' => '000000',
                'default' => 1
                );
                $numbering->addPageNumber('page-of', $numberoptions);
                $partialHeaderData2->addWordML($numbering);
                
                $tableData = new \Phpdocx\Elements\WordFragment($docx, 'defaultHeader');
                $values = array(
                        array(
                                array('value'=>$partialHeaderData1, 'width'=>3000), 
                                array('value'=>$partialHeaderData2, 'width'=>2000, 'float' => array('align' => 'right'))
                        )
                );
                
                $options = array(
                'border' => 'none',
                'tableAlign' => 'left',
                'borderWidth' => 0,
                'indent'=>0,
                'cellSpacing'=>0,
                'cellMargin'=>0,
                'columnWidths' => array(3000, 2000),
                'bold' => true,
                'textProperties'=>array('fontSize'=>9)
                );
                
                $tableData->addTable($values, $options);

have this code.
partialHeaderData1 is WordFragment with embedded html.
partialHeaderData2 is WordFragment with embedded html to which we add pagenumbering with addWordML

but no matter which font i set to pagenumbering it still shows it as 10pt in word.. tried even to set font size in code to 29 it still shows that at 10pt.

 

Posted by admin  · 08-01-2018 - 11:17

Hello,

The styles of page-of must be applied using a paragraph style and the pStyle option. You can use the paragraph styles from a template, imported from an external DOCX or created dynamically (https://www.phpdocx.com/api-documentation/layout-and-general/create-Word-custom-paragraph-style-with-PHP).

On the API page of the method (https://www.phpdocx.com/api-documentation/word-content/insert-page-number-Word-document-with-PHP) you can read about the options for numerical, alphabetical and page-of types (options for page-of type).

We also recommend you to check the included sample Core/addPageNumber/sample_2.php that illustrates how to set a custom style to page-of type using the addPageNumber method.

Regards.

Posted by WTO  · 12-02-2018 - 14:50

I just downloaded the latest 7.5 (licensed, advanced, so not a trial version), and the font size doesn't work. In fact, the official documentation example shown here: https://www.phpdocx.com/api-documentation/layout-and-general/create-Word-custom-paragraph-style-with-PHP doesn't work. The font size is set to 26, but the screenshot clearly shows a much smaller font. 

Executing the example found at examples/LayoutAndGeneral/createParagraphStyle/sample_2.php doesn't work either. The font will always remain at the default size.
 

Posted by admin  · 12-02-2018 - 17:00

Hello,

All samples are fully tested. In the sample you point out (https://www.phpdocx.com/api-documentation/layout-and-general/create-Word-custom-paragraph-style-with-PHP , example #2), the fontSize option is set to 26, that is the equivalent to 13 (MS Word font size units: value / 2) as you can see in the screenshot of the example.

We have run it setting others fontSize values to the paragraph style and the output is the expected (we have opened the DOCX with MS Word 2007, MS Word 2013, MS Word 2016, LibreOffice 5 and LibreOffice 6).

What program and version are you using to open the DOCX?

Regards

Posted by WTO  · 13-02-2018 - 09:24

Ok, fair enough. I suggest you put a warning about that in the doc, as it's not immediately obvious that it will be half of what you define. Furthermore, if I put the font-size explicitly when adding something, like so:

$docx->addHeading('My heading', 1, array(
  'fontSize' => 26,
));
$docx->addText($text, array('pStyle' => 'myStyle', 'fontSize' => 32));

It doesn't divide it by 2; the font size is 26 for the heading, and 32 for the text, and not 13 and 16. So it's not very intuitive.