Footnotes and endnotes are a useful tool to add additional information to a document without breaking the argumental flow of the presentation or as a mean to redirect the reader to another document or any auxiliary source of information (references, citations, etcetera).

Footnotes

The core method responsible of inserting a footnote in the document is the field method which public API is given by:

Signature

public footnote ([$options])

Parameters

  • $options (type: array). This array has the following available keys and values:
    • label (type: string). The footnote label. You should not declare this option if you (reasonably) prefer automatic labelling.
    • note (type: mixed string or DocumentFragment object). The footnote content. This parameter is optional because the content can also be included via chaining.
    • style (type: string). A string of styles in CSS format.

The relevant CSS style type styles that one may apply concide with the ones of the text method and we refer to them for further details (see Text).

The footnote content can be introduced in quite a few different ways:

  • Via a string of text whenever we want to include a simple text footnote.
  • With the help of a Document Fragment that includes the required content.
  • Via chaining.

In case you use chaining do not forget to call the end method with the footnote parameter to avoid that unwanted content gets added to your footnote.

Let us first start with a very simple example:

<?php
/**
 * This sample script inserts a paragraph with a simple footnote
 */
require_once 'pathToDOCXPRESSO/CreateDocument.inc';
$doc = new Docxpresso\CreateDocument();
$format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf
//insert a paragraph with a simple footnote
$doc->paragraph()
        ->text(array('text' => 'Just include a footnote'))
        ->footnote(array('note' => 'This is the footnote text.'))
            ->end('footnote')
        ->text(array('text' => ' and finish the paragraph.'));
//include in the render method the path where you want your document to be saved
$doc->render('simple_footnote' . $format); 
//echo a link to the generated document
echo 'You may download the generated document from the link below:<br/>';
echo '<a href="' . 'simple_footnote' . $format . '">Download document</a>';   

DOWNLOAD:download pdfdownload docdownload docxdownload odtdownload rtf

Let us now push a little further the previous example and insert directly some more complex content in out footnote rather than some simple text:

<?php
/**
 * This sample script inserts a paragraph with a footnote
 */
require_once 'pathToDOCXPRESSO/CreateDocument.inc';
$doc = new Docxpresso\CreateDocument();
$format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf
//insert a paragraph with a footnote
$noteStyle = 'margin-left: 0.5cm; text-indent: -0.5cm; font-style: italic; font-size: 11pt; margin-bottom: 0cm';
$doc->paragraph()
        ->text(array('text' => 'This footnote'))
        ->footnote()
            ->paragraph()->style($noteStyle)
                ->text(array('text' => 'This footnote enjoys some additional format and '))
                ->text(array('text' => 'some text in bold.'))->style('font-weight: bold')
            ->paragraph()->style($noteStyle)->style('margin-top: 0cm')
                ->text(array('text' => 'This is a second footnote paragraph with a '))
                ->link(array('url' => 'http://www.google.com', 'text' => 'link to Google'))->end('link')
                ->text(array('text' => '.'))
            ->end('footnote')
        ->text(array('text' => ' is slightly more complex.'));
//include in the render method the path where you want your document to be saved
$doc->render('footnote' . $format); 
//echo a link to the generated document
echo 'You may download the generated document from the link below:<br/>';
echo '<a href="' . 'footnote' . $format . '">Download document</a>';

DOWNLOAD:download pdfdownload docdownload docxdownload odtdownload rtf

Notice that there are slight differences in format depending on the document type so you should adequate your styling to your target document extension.

Endnotes

An endnote is similar to a footnote but it is rendered at the end of the document. Everything said for footnotes apply also to endnotes so we will not ellaborate much further on it.

The core method responsible of inserting an endnote in the document is the endnote method which public
API is given by:

Signature

public endnote ([$options])

Parameters

  • $options (type: array). This array has the following available keys and values:
    • label (type: string). The endnote label. You should not declare this option if you (reasonably) prefer automatic labelling.
    • note (type: mixed string or DocumentFragment object). The endnote content. This parameter is optional because the content can also be included via chaining.
    • style (type: string). A string of styles in CSS format.

Let us now reproduce the latest footnote example with the minimum required changes for this case (notice that
we have also included a custom label to illustrate its use):

<?php
/**
 * This sample script inserts a paragraph with an endnote
 */
require_once 'pathToDOCXPRESSO/CreateDocument.inc';
$doc = new Docxpresso\CreateDocument();
$format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf
//insert a paragraph with an endnote
$noteStyle = 'margin-left: 0.5cm; text-indent: -0.5cm; font-style: italic; font-size: 11pt; margin-bottom: 0cm';
$doc->paragraph()
        ->text(array('text' => 'This endnote'))
        ->endnote(array('label' => '[1]'))
            ->paragraph()->style($noteStyle)
                ->text(array('text' => 'This endnote enjoys some additional format and '))
                ->text(array('text' => 'some text in bold.'))->style('font-weight: bold')
            ->paragraph()->style($noteStyle)->style('margin-top: 0cm')
                ->text(array('text' => 'This is a second endnote paragraph with a '))
                ->link(array('url' => 'http://www.google.com', 'text' => 'link to Google'))->end('link')
                ->text(array('text' => '.'))
            ->end('endnote')
        ->text(array('text' => ' is pretty complex.'));
//include in the render method the path where you want your document to be saved
$doc->render('endnote' . $format); 
//echo a link to the generated document
echo 'You may download the generated document from the link below:<br/>';
echo '<a href="' . 'endnote' . $format . '">Download document</a>';

DOWNLOAD:download pdfdownload docdownload docxdownload odtdownload rtf

Notice that in MS Word the endnotes are not located in an additional last page but just at the end of the document. Notice also that the .docx format does not supports correctly the label option so for optimum rendering it should be left automatic.

Endnotes are not fully supported in RTF document format so you may obtain unexpected results.