Replies: 4   Views: 893
How do i create a two columns document with different background color/image..
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by Diaa  · 07-11-2021 - 08:14


I'm trying to create a two columns document with different background color/image to acheive something similar to this

Using embedHTML

My first thought was to create a table with two columns and work from there, however the table doesn't extend to the end of the document, and as the two columns have different background colors it doesn't work.. tried setting min-height, height for the table but nothing works..

My next approach was to set the document background image and use the table for content only, however I can't get the image properly aligned with the document as I don't know what converts the document size to pixels..

Anyone has any ideas? Thank you,,


Posted by admin  · 07-11-2021 - 09:28


The easiest approach to accomplish that task is generating a DOCX document using MS Word, LibreOffice or any other DOCX editor with the layout you want to use and load it as template. Then use the template methods included in phpdocx to replace and add contents, and customize styles if needed (for example changing the background color dynamically) using DOCXCustomizer.

If you need to generate it from scratch you should use a layout with custom margins using modifyPageLayout, or phpdocx_modifypagelayout using HTML Extended; and then add a fixed table that fills the whole page using embedHTML (height style applied to tr tags and table-layout style applied to table tags) or addTable (tableLayout and height options). On you can read all attributes and styles supported when adding tables using HTML.


Posted by Diaa  · 08-11-2021 - 06:30

Deleted by Diaa · 08-11-2021 - 06:36

Posted by Diaa  · 08-11-2021 - 06:37

I tried setting TR height to 100% but still it doesn't fill the entire page, it's larger but nearly stops on half of the page..

Is there a way to know what background image size will exactly fit the page? also is there a way to prevent the background image from repeating?

Thank you,

Posted by admin  · 08-11-2021 - 07:36


Please note that the allowed values when applying height to tr tags (as explained on, are the following:

height     length: em, pt, px

You need to use a fixed size to apply a tr height.

About your question, there's no way to prevent repeating a background image, MS Word repeats it automatically. You can get section sizes using the Indexer class ( For your reference A4 has the following size: 

'width' => '11906',
'height' => '16838',

set as twentieths of a point (

HTML Extended, available in Premium licenses, includes the phpdocx_image tag ( that supports extra options such as relativeToHorizontal, relativeToVertical, textWrap and others). This tag may be useful for your needs.