Replies: 1   Views: 1561
Insert comments in existing .docx file
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 dev@ams  · 12-05-2020 - 12:58


Is it possible to insert a comment in an existing .docx file on a specified fragment?

Posted by admin  · 12-05-2020 - 13:21


You can generate the comment and use DOCXPath ( to insert it, for example:


require_once 'classes/CreateDocx.php';

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

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

        'textDocument' => 'comment',
        'textComment' => 'The comment we want to insert.',
        'initials' => 'PT',
        'author' => 'PHPDocX Team',
        'date' => '10 September 2000'
$referenceNode = array(
        'type' => 'paragraph',
    'occurrence' => 2,

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


at specific positions. Please note that insertWordFragment allows working with existing tags, so it can add the comment after any MS Word tag (in body (document), header, and footer targets), but it doesn't allow applying the comment to an existing string.