Forum


Replies: 7   Views: 4110
Extra space on the beginning of every paragraph on html to doc
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  · 02-01-2019 - 13:22

Hello,

That blank spaces may be due to the vertical-space option from Tidy (https://stackoverflow.com/questions/2491657/how-do-i-get-html-tidy-to-not-put-newline-before-closing-tags), but some versions of Tidy may cause this issue.

The next relase of phpdocx will include a new option to clean these breaks that come from some Tidy versions/configurations (line breaks after closing tags). We recommend you to edit the classes/CreateDocx.php file, and change the following lines (in the embedHTML method):

if ($class == 'WordFragment') {
    if (isset($options['removeLineBreaks']) && $options['removeLineBreaks'] == true) {
        $this->wordML .= (string) str_replace(array("\n", "\r\n"), '', $sFinalDocX[0]);
    } else {
        $this->wordML .= (string) $sFinalDocX[0];
    }
} else {
    if (isset($options['removeLineBreaks']) && $options['removeLineBreaks'] == true) {
        $this->_wordDocumentC .= (string) str_replace(array("\n", "\r\n"), '', $sFinalDocX[0]);
    } else {
        $this->_wordDocumentC .= (string) $sFinalDocX[0];
    }
}

with:

if ($class == 'WordFragment') {
    if (isset($options['removeLineBreaks']) && $options['removeLineBreaks'] == true) {
        $this->wordML .= (string) str_replace(array(">\n", ">\r\n"), '>', $sFinalDocX[0]);
    } else {
        $this->wordML .= (string) $sFinalDocX[0];
    }
} else {
    if (isset($options['removeLineBreaks']) && $options['removeLineBreaks'] == true) {
        $this->_wordDocumentC .= (string) str_replace(array(">\n", ">\r\n"), '>', $sFinalDocX[0]);
    } else {
        $this->_wordDocumentC .= (string) $sFinalDocX[0];
    }
}

And set removeLineBreaks as true. This change removes the line breaks after start tags and should fix your issue. If you are not using the classic package but the namespaces one, please keep the namespaces in the same code.

Regards.