Tabs may show like a convenient and simple way to align content in a document and as such they are always a required component in any reasonably powerful text editor.

Docxpresso offers all the standard functionality of tabs via its tab method.

You may with the help of this method:

  • Insert left, center, right or char (aligned with respect to a certain character) aligned tabs.
  • Customize their leader char (the character that fill the tab space, if any).
  • Set the specific tab position.

The Public API of the tab method is given by:

Signature

public tab ([$options])

Parameters

  • $options (type: array). This array has the following available keys and values:
    • type (type: string, default: left). Specifies tab alignment: Insert left, center, right or char.
    • character (type: string, default: '.'). The character used for alignment (It is ignored if the type is not char).
    • leader (type: string, default: none). Specifies the leader char. The available options are: none, dash, dot-dash, dot-dot-dash, dotted, long-dash, solid and wave.
    • position (type: integer). Distance from the left margin or the left indent given in points (if not given the default value for each format will be used).

Let us construct an example that illustrates the different method options:

<?php
/**
 * This sample script inserts a few tabbed paragraphs
 */
require_once 'pathToDOCXPRESSO/CreateDocument.inc';
$doc = new Docxpresso\CreateDocument();
$format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf
$doc->paragraph(array('text' => 'First a few left tabbed paragraphs:'));
//insert a few runs of (left) tabbed text
for($j=0; $j < 6; $j++){
    $doc->paragraph(array('text' => 'Line : ' . $j))
            ->tab(array('position' => 200))
            ->text(array('text' => 'Data:' . $j));
}
$doc->paragraph(array('text' => 'Now some right tabbed paragraphs with a dotted leader:'));
//insert a few runs of (right) tabbed text with a dot as leader char
for($j=0; $j < 6; $j++){
    $doc->paragraph(array('text' => 'Line : ' . $j))
            ->tab(array('position' => 200, 'type' => 'right', 'leader' => 'dotted'))
            ->text(array('text' => 'Data:' . $j));
}
$doc->paragraph(array('text' => 'Now some tabbed paragraphs aligned with respect the decimal point:'));
//insert a few runs of (char: decimal point) tabbed text
for($j=0; $j < 6; $j++){
    $doc->paragraph(array('text' => 'Price : ' . $j))
            ->tab(array('position' => 200, 'type' => 'char', 'character' => '.'))
            ->text(array('text' => rand(1, 20) . '.'  . rand(0,9) . rand(0,9) . ' USD'));
}
//include in the render method the path where you want your document to be saved
$doc->render('tabs' . $format); 
//echo a link to the generated document
echo 'You may download the generated document from the link below:<br/>';
echo '<a href="' . 'tabs' . $format . '">Download document</a>';

DOWNLOAD:download pdfdownload docdownload docxdownload odtdownload rtf

MS Office Word does not have support for arbitrary char alignment but it is restricted to decimal points, so depending on your local configuration (commas or dots for decimal points) you may get different behaviours: always use the adequate decimal point char for your target audience.