Forum


Replies: 6   Views: 1955
Phpdocx_footnote
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 rapidtech  · 20-11-2019 - 10:53

Hi. When I put phpdocx_footnote not at the end of the HTML page then the generated DOCX is broken and I can't even open it. How to use the phpdocx_footnote if the anchor is in the middle of the text and the corresponding endnote/definition should be automatically placed at the end of the same page?

Posted by admin  · 20-11-2019 - 11:12

Hello,

This is a simple sample that add a text, a footnote and other text using HTML Extended (available in the package but adding more content types):

$html = '
    <head>
        <style>
            .italicc {font-style: italic;}
        </style>
    </head>
    <p>My text</p>
    <phpdocx_footnote>
        <p>Here <span class="italicc">comes</strong> the </p>
        <phpdocx_footnote_textdocument data-text="&nbsp;footnote" />
        <phpdocx_footnote_textfootnote>
            <p>Text <em>footnote</em></p>
        </phpdocx_footnote_textfootnote>
        <p>&nbsp;and some other text.</p>
    </phpdocx_footnote>
    <p>More text</p>
';
 
$docx->embedHTML($html, array('useHTMLExtended' => true));

The output is correct. Please, could you post the most simple script that illustrates your issue so we can test it?

Regards.

Posted by rapidtech  · 20-11-2019 - 11:35

Your example is working fine. In my case, I have a table on a page and it's not working fine. Check this one

<p>Text</p>

<phpdocx_footnote>
    <p>Here <span class="italicc">comes</strong> the </p>
    <phpdocx_footnote_textdocument data-text="&nbsp;footnote" />
    <phpdocx_footnote_textfootnote>
        <p>Text <em>footnote</em></p>
    </phpdocx_footnote_textfootnote>
    <p>&nbsp;and some other text.</p>
</phpdocx_footnote>

<p>Text</p>

<table border="0" width="100%">
    <tr valign="top">
        <td width="50%"></td>
        <td width="50%">
            <p>Text</p>
        </td>
    </tr>
</table>

<p>Text</p>

 

Posted by admin  · 20-11-2019 - 11:39

Hello,

We have run the same script but using your HTML and the output is correct as well:

$docx = new CreateDocx();

$html = '
<p>Text</p>

<phpdocx_footnote>
    <p>Here <span class="italicc">comes</strong> the </p>
    <phpdocx_footnote_textdocument data-text="&nbsp;footnote" />
    <phpdocx_footnote_textfootnote>
        <p>Text <em>footnote</em></p>
    </phpdocx_footnote_textfootnote>
    <p>&nbsp;and some other text.</p>
</phpdocx_footnote>

<p>Text</p>

<table border="0" width="100%">
    <tr valign="top">
        <td width="50%"></td>
        <td width="50%">
            <p>Text</p>
        </td>
    </tr>
</table>

<p>Text</p>
';
 
$docx->embedHTML($html, array('useHTMLExtended' => true));

$docx->createDocx('output');

The DOCX can be opened without error and all contents appear correctly (paragraphs, footnote and table). We have opened it using MS Word 2010, MS Word 2013, MS Word 2016 and LibreOffice.

Regards.

Posted by rapidtech  · 20-11-2019 - 12:05

Ok, I found what's happening. I have a wrapping DIV tag and it causing problems.

<?php
$docx = new CreateDocx();


$html = '
<div>
    <p>Text</p>
    
    <phpdocx_footnote>
        <p>Here <span class="italicc">comes</strong> the </p>
        <phpdocx_footnote_textdocument data-text="&nbsp;footnote" />
        <phpdocx_footnote_textfootnote>
            <p>Text <em>footnote</em></p>
        </phpdocx_footnote_textfootnote>
        <p>&nbsp;and some other text.</p>
    </phpdocx_footnote>
    
    <p>Text</p>
    
    <table border="0" width="100%">
        <tr valign="top">
            <td width="50%"></td>
            <td width="50%">
                <p>Text</p>
            </td>
        </tr>
    </table>
    
    <p>Text</p>
</div>
';
 
$docx->embedHTML($html, array('useHTMLExtended' => true));

$docx->createDocx('output');

But actually I need this DIV tag to be there.

Posted by admin  · 20-11-2019 - 12:41

Hello,

Some specific HTML Extended contents such as phpdocx_footnote and phpdocx_endnote doesn't allow being wrapped by other block contents (such as div or tables).

We always recommend adding them as the root of the HTML Extended contents, but if you need to wrap them you can use a p tag:

$html = '
<p>
    <p>Text</p>

    <phpdocx_footnote>
        <p>Here <span class="italicc">comes</strong> the </p>
        <phpdocx_footnote_textdocument data-text="&nbsp;footnote" />
        <phpdocx_footnote_textfootnote>
            <p>Text <em>footnote</em></p>
        </phpdocx_footnote_textfootnote>
        <p>&nbsp;and some other text.</p>
    </phpdocx_footnote>

    <p>Text</p>

    <table border="0" width="100%">
        <tr valign="top">
            <td width="50%"></td>
            <td width="50%">
                <p>Text</p>
            </td>
        </tr>
    </table>

    <p>Text</p>
</p>
';
 
$docx->embedHTML($html, array('useHTMLExtended' => true));

or a custom tag:

$html = '
<element>
    <p>Text</p>

    <phpdocx_footnote>
        <p>Here <span class="italicc">comes</strong> the </p>
        <phpdocx_footnote_textdocument data-text="&nbsp;footnote" />
        <phpdocx_footnote_textfootnote>
            <p>Text <em>footnote</em></p>
        </phpdocx_footnote_textfootnote>
        <p>&nbsp;and some other text.</p>
    </phpdocx_footnote>

    <p>Text</p>

    <table border="0" width="100%">
        <tr valign="top">
            <td width="50%"></td>
            <td width="50%">
                <p>Text</p>
            </td>
        </tr>
    </table>

    <p>Text</p>
</element>
';
 
$docx->embedHTML($html, array('useHTMLExtended' => true));

We move the request to the dev team to add support of wrapping that specific contents in divs and other block contents.

Regards.

Posted by rapidtech  · 20-11-2019 - 13:11

Ok, thank you. I'll try to find a way skip wrapping tag.

I have another question about phpdocx_section but I will create another topic for that.