Register Lost your password?
Full api documentation: full api documentation FREE version full api documentation PRO version

public function addText(string text, array paramsText = array())

public function addText(array text = array()) Version Pro

Parameters

text : Text to insert into the document
$paramsText

  • ‘b’ (bold): ’single’
  • ‘color’ (color RGB): FF0000, 000000, FFFFFF,…
  • ‘i’ (italic): ’single’
  • ‘jc’ (text alignment): ‘left’, ‘center’, ‘right’, ‘both’, ‘distribute’
  • ’sz’ (size): 1, 2, 3, 4,…
  • ‘u’ (underline): ’single’, ‘words’, ”double’, ‘dotted’, ‘dash’, ‘wave’
  • ‘pageBreakBefore’ (forces a page break before a paragraph) : on, off
  • ‘widowControl’ (prevents Word from printing the last line of a paragraph by itself at the top of the page (widow) or the first line of a paragraph at the bottom of a page (orphan)) : on, off
  • ’spaces’: number of spaces
  • ‘tabs’: add a tab
  • ‘wordWrap’ (breaks a line in the middle of a word) : on, off
  • ‘font’ (A specific size and style of font type within a type family. Example ‘Times New Roman’, ‘Arial’,…)

text : creating a multi-format text Version Pro

  • ‘b’ (bold): ’single’
  • ‘color’ (color RGB): FF0000, 000000, FFFFFF,…
  • ‘i’ (italic): ’single’
  • ‘jc’ (text alignment): ‘left’, ‘center’, ‘right’, ‘both’, ‘distribute’
  • ’sz’ (size): 1, 2, 3, 4,…
  • ‘u’ (underline): ’single’, ‘words’, ”double’, ‘dotted’, ‘dash’, ‘wave’
  • ‘pageBreakBefore’ (forces a page break before a paragraph) : on, off
  • ‘widowControl’ (prevents Word from printing the last line of a paragraph by itself at the top of the page (widow) or the first line of a paragraph at the bottom of a page (orphan)) : on, off
  • ’spaces’: number of spaces
  • ‘tabs’: add a tab
  • ‘wordWrap’ (breaks a line in the middle of a word) : on, off
  • ‘font’ (A specific size and style of font type within a type family. Example ‘Times New Roman’, ‘Arial’,…)
  • ‘text’ (Text string for multi-format)

Examples

Example 1


require_once 'classes/CreateDocx.inc';

$docx = new CreateDocx();

$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' .
    'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' .
    'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' .
    'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' .
    'in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' .
    'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui ' .
    'officia deserunt mollit anim id est laborum.';

$paramsText = array(
    'b' => 'single',
    'font' => 'Arial'
);

$docx->addText($text, $paramsText);

$docx->createDocx('example_text');

Example 2 Version Pro


require_once('classes/CreateDocx.inc');

$docx = new CreateDocx();

$text = array();

$text[] =
    array(
        'text' => 'Lorem ipsum',
        'u' => 'single',
);

$text[] =
    array(
        'text' => ' sed do eiusmod tempor incididunt',
        'b' => 'single',
);

$docx->addText($text);

$docx->createDocx('example_text');

    8 Responses

  • nico

    Hello,

    Is it possible possible to change the style of a part of a text in the same paragraph ?

    fAddText(’Start of the line without style’);
    $arrParamsText = array(
    ‘b’ => ’single’
    );
    $objDocx->fAddText(’ the line continue without return to line ?’,$arrParamsText);
    ?>

    If I write two fAddText methods, I have a return to line in my sentence :(

    Regards,

  • admin

    Hi,

    The next version of phpdocx will include this feature. We’re working actually on it.

  • bneal010

    how would I go about making text within a table cell bold?

  • Colin

    Cant get this to work with line feeds. What characters will it convert into line feeds?

  • Mutske

    This looks like a promising product. However, it would be good to have a users forum.
    I would be interested to buy a license if I would be able to get the example files to work.

    Even the simple ‘hello world’ example is not working. GEt the error :syntax error, unexpected T_STRING, expecting ‘)’. (error comes from $objDocx->fAddText)

    There is a big need for such a product but PLEASE PROVIDE A FORUM. I have been purchasing too many softwares that I never used. So, put us in a position to share experience between users and you will see your sales boosting !

    Support is maybe an important revenue source but make sure your cutomers can first have a good expecience with the product.

    Mutske

  • Keith

    Most of the examples appear to work fine - a most interesting product. Will the PRO version only work on one site? - the documentation is ambiguous as it says it will only work on one but then asks for a list of sites.

    Is there any way of altering the spacing between paragraphs? Generated documents have a 10pt space after every paragraph - this is not my default so it must be specified in one of your class scripts.

    At the moment fAddText always starts a new paragraph. Any way of changing this?

  • Paulius

    It’s possible to move the text by some distance away from the start?

  • sharath

    hey is there any option for line spacing???

Your comments