Forum


Replies: 2   Views: 1988
Unable to insert footnote into the html-table
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 soglasie  · 30-07-2019 - 13:35

Hi!

We have strange issue while using embedHTML(): when we creating DOCX from HTML shown below

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <table>
        <tbody>
        <tr>
            <td>
                <phpdocx_footnote>
                    Some text here and ...
                    <phpdocx_footnote_textdocument data-text=" note" data-bold="false" />
                    <phpdocx_footnote_textfootnote>
                        <p>footnote data</p>
                    </phpdocx_footnote_textfootnote>
                </phpdocx_footnote>
            </td>
        </tr>
        </tbody>
    </table>
</body>
</html>

... using method embedHTML():

$options = [
    'isFile' => true,
    'baseURL' => dirname($url) . '/',
    'downloadImages' => true,
    'disableWrapValue' => true,
    'removeLineBreaks' => true,
    'useHTMLExtended' => true
];

$document = new CreateDocx();
$document->embedHTML($html, $options);
$structure = $document->createDocx('document_' . random_int(1, PHP_INT_MAX));
$structure->saveDocx('/path/to/root/' . $resource);

... we getting broken document (that document can`t be opened in MS Word).

How to properly insert into HTML-table footnote?

Posted by admin  · 30-07-2019 - 14:40

Hello,

phpdocx 11 added support to add block contents inside other block contents using HTML Extended. The following information is for phpdocx 10 and previous versions.

The problem is that you are trying to add a phpdocx block element (a footnote) into a block element, and using the current version of phpdocx they need to be added out of block elements (as sample_7.php illustrates).

You can accomplish this task easily doing two steps: add a placeholder where the footnote needs to be added and then load the DOCX as a template and replace the placeholder by the new footnote:

<?php

require_once 'classes/CreateDocx.php';

$docx = new CreateDocx();

$html = '
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <table>
        <tbody>
        <tr>
            <td>
                $FOOTNOTE$
            </td>
        </tr>
        </tbody>
    </table>
</body>
</html>
';
$docx->embedHTML($html, array('useHTMLExtended' => true));

$docx->createDocx('example_embedHTML_9');

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

$footnote_html = '
<phpdocx_footnote>
    Some text here and ...
    <phpdocx_footnote_textdocument data-text=" note" data-bold="false" />
    <phpdocx_footnote_textfootnote>
        <p>footnote data</p>
    </phpdocx_footnote_textfootnote>
</phpdocx_footnote>';
$footnote = new WordFragment($docx, 'document');
$footnote->embedHTML($footnote_html, array('useHTMLExtended' => true));

$docx->replaceVariableByWordFragment(array('FOOTNOTE' => $footnote), array('type' => 'block'));

$docx->createDocx('example_embedHTML_9_t.docx');

To get the best performance, as you are using a Premium license you can do all the previous steps using in-memory DOCX instead of saving the first DOCX as a new file to be loaded a template. Please check https://www.phpdocx.com/documentation/cookbook/improve-phpdocx-performance and Performance/returnDocxStructure/sample_1.php example.

phpdocx 11 added support to add block contents inside other block contents using HTML Extended. This information is for phpdocx 10 and previous versions.

Regards.

Posted by soglasie  · 30-07-2019 - 15:02

Thanks to reply!

We will try this variant a soon as possible.