Forum


Replies: 4   Views: 1232
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 JacquesMarques  · 18-05-2021 - 14:13

Hi,

I upgrade from version 6.0 to 8.2 and in version 6.0 the addText method add a break paragraph (like when you press ENTER key on Word line), but in version 8.2 end with line break (like you press SHIFT + ENTER keys), and I need works like in version 6.0.

Can anyone help me with this?

Thanks,

Posted by admin  · 18-05-2021 - 14:40

Hello,

The addText method adds a paragraph content to the document; it doesn't use a soft line break. We have tested the following code with phpdocx 6.0, phpdocx 8.2, phpdocx 9, phpdocx 10 and phpdocx 11 and we get the same output:

$docx = new CreateDocx();
$text = 'Lorem ipsum dolor sit amet.';

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

$docx->createDocx('output');

There's no soft line break added, only paragraph contents. Please post or send to contact[at]phpdocx.com the most simple sample that illustrates your issue; phpdocx only adds soft line breaks when requested using some option such as parseLineBreaks in template methods.

Regards.

Posted by JacquesMarques  · 18-05-2021 - 16:47

Hello,

You are right, but I found out that my problem is with the CreateDocxFromTemplate in version 6.2 the code below works perfectly well its add, but in version 8.2 its add a soft line after addText 'Question 1)' text:

 

$docx = new CreateDocxFromTemplate('Doc1.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' );

Can you help me with this?

Reguards,

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.

Posted by JacquesMarques  · 18-05-2021 - 19:45

Ok I sent the template to your email. But please test the code like a pass in previous message.