Forum


Replies: 4   Views: 1048
Addtext end paragraph with carrige return and i want with break paragraph
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 admin  · 18-05-2021 - 18:14

Hello,

We have run the following code with phpdocx 6 and phpdocx 8.2 (and also phpdocx 9, 10 and 11):

$docx = new CreateDocx();

$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.';

$paragraphOptions = array(
    'bold' => true,
    'font' => 'Arial',
);

$docx->addText($text, $paragraphOptions);

$docx->addText($text, $paragraphOptions);

$content = new WordFragment($docx, 'document');

$content->addText(' New text.', array('fontSize' => 20, 'color' => '#0000ff'));

$referenceNode = array(
        'type' => 'paragraph',
    'occurrence' => 1,
    'contains' => 'Lorem',
);

$docx->insertWordFragment($content, $referenceNode, 'inlineAfter');

$docx->createDocx('example_insertWordFragment_1');

$docx = new CreateDocxFromTemplate('example_insertWordFragment_1.docx');

$content = new WordFragment($docx, 'document');
$content->addText('Question 1) ', array('fontSize' => 12, 'bold' => true));

$referenceNode = array(
   'type' => 'paragraph',
   'occurrence' => 1,
);

$docx->insertWordFragment($content, $referenceNode, 'inlineBefore', false);
$docx->createDocx('ResultDoc.docx' );

that uses your DOCXPath code (although with other template because you haven't sent the template you are using), and the output is correct in all cases: Question 1) is added at the beginning of the first paragraph and there's no soft line break added.

Please run the previous code standalone. If you send to contact[at]phpdocx.com the template you are using we'll test it too.

Regards.