Forum


Replies: 3   Views: 1893
Replacevariablebywordfragment inline removes the font size of the rest of the text
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 droh10  · 06-12-2019 - 10:06

Hi,

I have a problem with replaceVariableByWordFragment (type: inline), when i replace the variables in my template document the text font size of the rest of the text is no longer the same.

Inside my template document will have something like this:

line text 1
line text 2 |mathml| and a text after.
line text 3

then i create a WordFragment and create a mathml throught addMathEquation().
when i run the replaceVariableByWordFragment and then create the file,

the  text, line  text 2 "replaced by mathml equation" and a text after, the "and a text after" portion is no longer the same font size with "line  text 2" portion

my code is like this

$pStylev2 = array(
    'font' => 'Times New Roman',
    'fontSize' => 15,
    'contextualSpacing' => true,
    'spacingBottom' => 0,
    'spacingTop' => 0,
    'lineSpacing' => 240,
);
$docx = new CreateDocx();
$docx->addText("line text 1", $pStylev2);
$docx->addText("line text 2 |mathml| and a text after.", $pStylev2);
$docx->addText("line text 3", $pStylev2);
$tmpfilename = "sampledoc";
$docx->createDocx($tmpfilename);
$docxtemplate = new CreateDocxFromTemplate($tmpfilename. ".docx");
$docxtemplate->setTemplateSymbol('|');
$keyfragmentarray = array();
$mathml[] = '<math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><mi>x</mi></math>';
foreach ($mathml as $key => $value) {
    $fragment = new WordFragment($docxtemplate);
    $fragment->addMathEquation($value, 'mathml', array('align' => 'left'));
    $keyfragmentarray["mathml"] = $fragment;
}
$docxtemplate->replaceVariableByWordFragment($keyfragmentarray, array('type' => 'inline'));
$docxtemplate->createDocxAndDownload("replacesample.docx");

basically, "line text 2" will be font size 15 but the text after the mathml, "and a text after", will be turned into font size 11 (i think it is the default);

any help will be greatly appreciated. thanks