Practical phpdocx

Sections and properties

Introduction

When working with phpdocx, documents don't have to be strictly A4 size. phpdocx provides the necessary methods to modify the page size, as well as create new sections with different properties and set the internal properties such as author, description and keywords.

New sections

The method available for adding new sections is:

With this method, you count with the following parameters:

  • $sectionType: This string defines the type of section like nextPage, nextColumn or continuous.
  • $paperType: The paper size: A4, A3, letter-landscape, etc.
  • $options: It's an array of additional options such as width, height, number of columns, margin and orientation.

For example, you can create a section in a new document. After creating the document with a text, write this code:

Then, add the new section:

Now, add the new contents to that new section:

Document properties

Each document has internal properties such as subject, creator, description or categories. Besides, it counts with full-customizable properties in its name and value.

phpdocx provides addProperties to define the properties:

$values is an array of the properties to add. Besides its predefined properties like subject or creator, the custom key allows to add new properties.

For example, for inserting multiple properties in the document, use the code:

Setting the document layout

To modify the paper size without creating a new section, use modifyPageLayout:

The values of both parameters are similar to the ones of the addSection method.

For example, to define an A3-landscape page size with three columns, write this code:

Tips and tricks

Default page configuration. phpdocx uses the A4 paper size as default value. In order to set other size or orientation, modify the paper_size property in the file config/phpdocxconfig.ini.

The Trial package does not allow to define the properties of a document. This setting is only available in the paid versions of phpdocx.

Right to left: phpdocx is also fully compatible to use right-to-left languages.
Check the Right to left languages tutorial on our documentation.

Next - Styles