I have a template that uses only one font, Helvetica.
Can I change the template font with the API?
I'm not talking about setting the default font. I'm talking about changing the font of the text written in the template.
I have a template that uses only one font, Helvetica.
Can I change the template font with the API?
I'm not talking about setting the default font. I'm talking about changing the font of the text written in the template.
Hello,
You can change styles on the fly, such as font families and many other styles, using DOCXCustomizer, available in Premium licenses:
https://www.phpdocx.com/documentation/introduction/docxcustomizer
Regards.
OK it works with Premium Edition.
One thing that doesn't work though is 'type' => '*' in order to apply the new font to all the document.
The following doesn't work:
$docx->customizeWordContent(['target' => 'document', 'type' => '*', 'contains' => '',], ['font' => 'Calibri']);
So I have to loop throught all possible types, like this:
foreach (array('break', 'image', 'list', 'paragraph', 'run', 'section', 'style', 'table', 'table-row', 'table-cell') as $type)
$docx->customizeWordContent(['target' => 'document', 'type' => $type, 'contains' => '',], ['font' => 'Calibri']);
Hello,
* wildcard doesn't apply to internal contents, so we recommend you to use your second approach but applying it only to content types that support font styles:
foreach (array('paragraph', 'run', 'list', 'style') as $type) {
$docx->customizeWordContent(['target' => 'document', 'type' => $type, 'contains' => '',], ['font' => 'Calibri']);
}
On https://www.phpdocx.com/api-documentation/docxcustomizer/customize-docx-Word-documents-PHP you can read the supported styles for each content type.
Regards.