Docxpresso allows for three different type of breaks, namely:

  • line breaks,
  • page breaks and
  • column breaks,

as well as any number of whitespaces within a run of text.

Let us go in more detail over all these possibilities.

Line breaks

The core method responsible of inserting a line break in the middle of a paragraph is the lineBreak method which public API is given by:

Signature

public lineBreak ()

Parameters

  • Accepts no parameters.

An example of use is given by:

<?php
/**
 * This sample script inserts a paragraph with a line break
 */
require_once 'pathToDOCXPRESSO/CreateDocument.inc';
$doc = new DocxpressoCreateDocument();
$format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf
//insert a paragraph with a line break
$doc->paragraph()
        ->text(array('text' => 'this is the first line'))
        ->lineBreak()
        ->text(array('text' => 'and this is the second one.'));
//include in the render method the path where you want your document to be saved
$doc->render('line_break' . $format); 
//echo a link to the generated document
echo 'You may download the generated document from the link below:<br/>';
echo '<a href="' . 'line_break' . $format . '">Download document</a>'; 

DOWNLOAD: download pdfdownload docdownload docxdownload odtdownload rtf

Page breaks

You may insert a page break anywhere in your document but it will be implemented by Docxpresso always before the next paragraph, table or table row that are the only accepted page breaking elements.

The core method responsible of inserting a page break is the pageBreak method which public API is given by:

Signature

public pageBreak ()

Parameters

  • Accepts no parameters.

An example of use is given by:

<?php
/**
 * This sample script inserts a page break between two paragraphs
 */
require_once 'pathToDOCXPRESSO/CreateDocument.inc';
$doc = new DocxpressoCreateDocument();
$format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf
//inserts a page break between two paragraphs
$doc->paragraph(array('text' => 'First paragraph.'));
$doc->pageBreak();
$doc->paragraph(array('text' => 'Second paragraph.'));
//include in the render method the path where you want your document to be saved
$doc->render('page_break' . $format); 
//echo a link to the generated document
echo 'You may download the generated document from the link below:<br/>';
echo '<a href="' . 'page_break' . $format . '">Download document</a>';

DOWNLOAD:download pdfdownload docdownload docxdownload odtdownload rtf

You could have obtained the same result by, for example, setting the page-break-before CSS style to always in the second paragraph.

Column breaks

You may insert a column break anywhere in your document but as in the previous case it will be implemented by Docxpresso
always before the next paragraph, table or table row that are the only accepted column breaking elements.

The core method responsible of inserting a column break is the
columnBreak method which public API is given by:

Signature

public columnBreak ()

Parameters

  • Accepts no parameters.

An example of use is given by:

<?php
/**
 * This sample script inserts a column break between two paragraphs
 */
require_once 'pathToDOCXPRESSO/CreateDocument.inc';
$doc = new DocxpressoCreateDocument();
$format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf
//set first a two column layout
$doc->pageLayout(array('style' => 'column-count: 2; column-gap: 1cm;'));
//inserts a column break betwen two paragraphs
$doc->paragraph(array('text' => 'First paragraph.'));
$doc->columnBreak();
$doc->paragraph(array('text' => 'Second paragraph.'));
//include in the render method the path where you want your document to be saved
$doc->render('column_break' . $format); 
//echo a link to the generated document
echo 'You may download the generated document from the link below:<br/>';
echo '<a href="' . 'column_break' . $format . '">Download document</a>';

DOWNLOAD:download pdfdownload docdownload docxdownload odtdownload rtf

You could have obtained the same result by, for example, setting the break-before CSS style to column in the second paragraph.

Whitespaces

You may easily insert an arbitrary number of whitespaces within a run of text with the help of the
whitespace method which public API is given by:

Signature

public whitespace ([$number])

Parameters

  • $number (type: integer, default: 1). The number of whitespaces that we wish to insert.

An example of use is given by:

<?php
/**
 * This sample script inserts some whitespace within a paragraph
 */
require_once 'pathToDOCXPRESSO/CreateDocument.inc';
$doc = new DocxpressoCreateDocument();
$format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf
//insert 5 whitespaces
$doc->paragraph()
        ->text(array('text' => 'Some text before 5 whitespaces'))
        ->whitespace(5)
        ->text(array('text' => 'some more text.'));
//include in the render method the path where you want your document to be saved
$doc->render('whitespace' . $format); 
//echo a link to the generated document
echo 'You may download the generated document from the link below:<br/>';
echo '<a href="' . 'whitespace' . $format . '">Download document</a>';  

DOWNLOAD:download pdfdownload docdownload docxdownload odtdownload rtf