Forum


Replies: 1   Views: 1195
Adding link and comment on same word
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 neelamwad  · 15-07-2021 - 07:31

I have to show in word doc link and comment on same word.
For eg - hello is a word which has "a href tag" and same word has some "comments" on it.

How can i achieve it?

TIA

Posted by admin  · 15-07-2021 - 08:21

Hello,

You need to use a WordFragment and add it to the textDocument option. For example:

$docx = new CreateDocx();

$textFragment = new WordFragment($docx, 'comment');
$textFragment->addText('Text content.');

$linkFragment = new WordFragment($docx);
$linkFragment->addLink('Link to Google', array('url'=> 'http://www.google.com'));

$comment = new WordFragment($docx, 'document');
$comment->addComment(
    array(
        'textDocument' => array('text' => array($linkFragment)),
        'textComment' => $textFragment,
        'author' => 'PHPDocX Team',
    )
);
                    
$text = array();
$text[] = array('text' => 'Here comes the ');
$text[] = $comment;
$text[] = array('text' => ' and some other text.');

$docx->addText($text);

$docx->createDocx('output');

Regards.