formatting.txt 5.9 KB
Formatting
***************

Fonts
---------------

Size, Font family, Font color, Background color
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To format text, you can use the ``PHPRtfLite_Font``.

Example sets size to 12pt, font family to Arial, font color to red, and background color to blue:

.. code-block:: php

    <?php
    // some bootstraping here
    
    $section = $rtf->addSection();
    $font = new PHPRtfLite_Font(12, 'Arial', '#FF0000', '#0000FF');
    $section->writeText('Lorem ipsum', $font);
    

Text formatting
~~~~~~~~~~~~~~~

.. code-block:: php

    <?php
    // some bootstraping here
    
    $section = $rtf->addSection();
    $font = new PHPRtfLite_Font();
    $font->setBold();           // bold font
    $font->setItalic();         // italic font
    $font->setUnderline();      // underline font
    $font->setStriked();        // strike text
    $font->setDoubleStriked();  // double strike text
    $section->writeText('Lorem ipsum', $font);

    
HTML-Tags as text formatting
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can use HTML-Tags in your text to format text:

.. code-block:: php

    <?php
    // some bootstraping here
    
    $section = $rtf->addSection();
    
    // text will be displayed as bold
    $section->writeText('<strong>text</strong>');
    $section->writeText('<b>text</b>');             
    
    // text will be displayed as italic
    $section->writeText('<em>text</em>');
    $section->writeText('<i>text</i>');
    
    // text will be displayed as underlined
    $section->writeText('<u>text</u>');
    
    // text will start with a bullet
    $section->writeText('<bullet> text');
    
    // text will have a line break after
    $section->writeText('text<br>');
    
    // text will have a horizontal rule after
    $section->writeText('text<hr>');
    
    // tabulator will be displayed between text
    $section->writeText('text<tab>text');
    
    // will display section number before "hello world"
    $section->writeText('<sectnum> hello world');
    
    // will display page number before "hello world"
    $section->writeText('<pagenum> hello world');


Text animation
~~~~~~~~~~~~~~

Class constants for text animation:

- ``ANIMATE_LAS_VEGAS_LIGHTS``
- ``ANIMATE_BLINKING_BACKGROUND``     
- ``ANIMATE_SPARKLE_TEXT``
- ``ANIMATE_MARCHING_BLACK_ANTS``
- ``ANIMATE_MARCHING_RED_ANTS``
- ``ANIMATE_SHIMMER``

.. code-block:: php

    <?php
    // some bootstraping here
    
    $section = $rtf->addSection();
    $font = new PHPRtfLite_Font();
    // text with marching black ants around
    $font->setAnimation(PHPRtfLite_Font::ANIMATE_MARCHING_BLACK_ANTS);
    $section->writeText('Lorem ipsum', $font);


Paragraph formatting
--------------------

Text alignment
~~~~~~~~~~~~~~~~~~~~

Class constants for text alignment:

- ``TEXT_ALIGN_LEFT``
- ``TEXT_ALIGN_RIGHT``
- ``TEXT_ALIGN_CENTER``
- ``TEXT_ALIGN_JUSTIFY``

.. code-block:: php

    <?php
    // some bootstraping here
    
    $section = $rtf->addSection();
    // centered text
    $parFormat = new PHPRtfLite_ParFormat(PHPRtfLite_ParFormat::TEXT_ALIGN_CENTER);
    $section->writeText('Lorem ipsum', null, $parFormat);


Paragraph indention
~~~~~~~~~~~~~~~~~~~~

First line indention:

.. code-block:: php

    <?php
    // some bootstraping here
    
    $section = $rtf->addSection();
    $parFormat = new PHPRtfLite_ParFormat();
    // first line of paragraph will be indented by 1cm
    $parFormat->setIndentFirstLine(1);
    $section->writeText('Lorem ipsum', null, $parFormat);

    
Indent the whole paragraph left or/and right:

.. code-block:: php

    <?php
    // some bootstraping here
    $parFormat = new PHPRtfLite_ParFormat();
    // paragraph will be indented by 1cm from the left and right
    $parFormat->setIndentLeft(1);
    $parFormat->setIndentRight(1);


Space between paragraphs
~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: php

    <?php
    // some bootstraping here
    $parFormat = new PHPRtfLite_ParFormat();
    // spaces in lines after the paragraph
    $parFormat->setSpaceAfter(1);
    // spaces in lines before the paragraph
    $parFormat->setSpaceBefore(1);

    
Space between lines
~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: php

    <?php
    // some bootstraping here
    $parFormat = new PHPRtfLite_ParFormat();
    // spaces between lines
    $parFormat->setSpaceBetweenLines(1);

    
Background color
~~~~~~~~~~~~~~~~~~~~~~~~

Paragraph background color:

.. code-block:: php

    <?php
    // some bootstraping here
    $parFormat = new PHPRtfLite_ParFormat();
    $parFormat->setBackgroundColor('#FF0000');


.. _borders:
    
Borders
~~~~~~~~~~~~~~~~

.. code-block:: php

    <?php
    // some bootstraping here
    
    $border = new PHPRtfLite_Border(
        $rtf,                                       // PHPRtfLite instance
        new PHPRtfLite_Border_Format(2, '#00FF00'), // left border: 2pt, green color
        new PHPRtfLite_Border_Format(1, '#FFFF00'), // top border: 1pt, yellow color   
        new PHPRtfLite_Border_Format(2, '#FF0000'), // right border: 2pt, red color
        new PHPRtfLite_Border_Format(1, '#0000FF')  // bottom border: 1pt, blue color
    );
    $parFormat = new PHPRtfLite_ParFormat();
    $parFormat->setBorder($border);

    
There are some alternative ways to create borders:    
    
.. code-block:: php
   
    <?php
    // some bootstraping here

    // creating border in a different way: 1pt dotted red border with 0.5cm space
    $border = PHPRtfLite_Border::create($rtf, 1, '#FF3333', PHPRtfLite_Border_Format::TYPE_DOT, 0.5);


.. code-block:: php
   
    <?php
    // some bootstraping here

    // creating border in a different way: 1pt dotted red border
    $border = new PHPRtfLite_Border($rtf);
    // 2pt border in green color
    $border->setBorders(new PHPRtfLite_Border_Format(2, '#00FF00'));
    

Border style types
^^^^^^^^^^^^^^^^^^

Border style types represented as class constants of ``PHPRtfLite_Border_Format`` are:

- ``TYPE_SINGLE`` 
- ``TYPE_DOT``
- ``TYPE_DASH``
- ``TYPE_DOTDASH``