A PageStyle let us change the properties of the pages in a document.
To create a PageStyle, we call the constructor with the name of this page style.
$pageStyle = new PageStyle('myPageStyle');
The method setPageSize($width, $height)
specify the physical size of the page. The width must correspond to the orientation of the page. For example, if a page is in portrait, the width specifies the width of the shorter page side. If the page is in landscape, the width attribute specifies the width of the longer page side.
$pageStyle = new PageStyle('myPageStyle'); $pageStyle->setPageSize('18cm', '26cm');
We can specify the orientation of the printed page using setOrientation($orientation)
. The two possible orientations are portrait StyleConstants::PORTRAIT
and landscape StyleConstants::LANDSCAPE)
.
$pageStyle = new PageStyle('myPageStyle'); $pageStyle->setOrientation(StyleConstants::LANDSCAPE);
We can specify the left & right margin for the page using setHorizontalMargin($leftMargin, $rightMargin)
.
$pageStyle = new PageStyle('myPageStyle'); $pageStyle->setHorizontalMargin('2cm', '2cm');
We can specify the top & bottom margin for the page using setVerticalMargin($topMargin, $bottomMargin)
.
$pageStyle = new PageStyle('myPageStyle'); $pageStyle->setVerticalMargin('2cm', '2cm');
We can set a border to the pages using setBorder($borderColor, $borderStyle, $borderWidth)
.
$borderColor
(optional): The border color. It is black by default.$borderStyle
(optional): Is it a single or double line StyleConstants::(SOLID|DOUBLE).$borderWidth
(optional): Can be a length, or one of these values: StyleConstants::(THIN|THICK|MEDIUM).$pageStyle = new PageStyle('myPageStyle'); $pageStyle->setBorder('#ff0000', StyleConstants::SOLID, StyleConstants::THIN);
We can also apply the border to only one side of the page, using one of these methods:
setTopBorder($borderColor, $borderStyle, $borderWidth)
setBottomBorder($borderColor, $borderStyle, $borderWidth)
setLeftBorder($borderColor, $borderStyle, $borderWidth)
setRightBorder($borderColor, $borderStyle, $borderWidth)
We can set the padding (spacing around the page) using setPadding($padding)
.
Note that this property won't apply unless there is a border at the same side of the padding.
$pageStyle = new PageStyle('myPageStyle'); $pageStyle->setBorder('#ff0000'); $pageStyle->setPadding('1cm');
Like borders, we can set a padding to one side of the page only, using one of these methods:
setTopPadding($padding)
setBottomPadding($padding)
setLeftPadding($padding)
setRightPadding($padding)
We can set the background color of the pages using setBackgroundColor($color)
.
$pageStyle = new PageStyle('myPageStyle'); $pageStyle->setBackgroundColor('#ff22cc');
We can set an image as the background of the pages using setBackgroundImage($image, $repeat, $position)
.
$image
: path of the image.$repeat
(optional): whether the image should be repeated or not, or stretched. default value is repeated. This can be set using one of these values StyleConstants::(REPEAT, NO_REPEAT, STRETCH).$pageStyle = new PageStyle('myPageStyle'); $pageStyle->setBackgroundImage('image.jpeg', StyleConstants::STRETCH);
We specify the maximum amount of space on the page that a footnote can occupy using setMaximumFootnoteHeight($height)
. Footnotes are created in paragraphs using addNote
.
$pageStyle = new PageStyle('myPageStyle'); $pageStyle->setMaximumFootnoteHeight('5cm');
We can add content to the header or footer using setHeaderContent($content)
or setFooterContent($content)
.
The value of $content
can be either StyleConstants::PAGE_NUMBER
to add page number, StyleConstants::CURRENT_DATE
to add the current date, or some text.
$pageStyle = new PageStyle('myPageStyle'); $pageStyle->setFooterContent(StyleConstants::PAGE_NUMBER);
We can specify the height of the header or the footer using setHeaderHeight($height)
and setFooterHeight($height)
.
We can also specify the minimum height of the header or the footer using setHeaderMinHeight($minHeight)
and setFooterMinHeight($minHeight)
.
We can set horizontal margins using setHeaderHMargins($leftMargin, $rightMargin)
, and vertical margins using function setHeaderVMargins($topMargin, $bottomMargin)
.
Like for the header, we can set horizontal margins using setFooterHMargins($leftMargin, $rightMargin)
, and vertical margins using setFooterVMargins($topMargin, $bottomMargin)
.
$pageStyle = new PageStyle('myPageStyle'); $pageStyle->setFooterHMargins('3cm', '3cm'); $pageStyle->setFooterContent(StyleConstants::PAGE_NUMBER);
We can set a border to the header and footer using respectively setHeaderBorder($borderColor, $borderStyle, $borderWidth)
and setFooterBorder($borderColor, $borderStyle, $borderWidth)
.
$borderColor
(optional): The border color. It is black by default.$borderStyle
(optional): Is it a single or double line StyleConstants::(SOLID|DOUBLE).$borderWidth
(optional): Can be a length, or one of these values: StyleConstants::(THIN|THICK|MEDIUM).$pageStyle = new PageStyle('myPageStyle'); $pageStyle->setFooterBorder(); $pageStyle->setFooterContent(StyleConstants::PAGE_NUMBER);
We can also apply the border to only one side of the header or footer, using one of these methods:
setHeaderTopBorder($borderColor, $borderStyle, $borderWidth)
setFooterTopBorder($borderColor, $borderStyle, $borderWidth)
setHeaderBottomBorder($borderColor, $borderStyle, $borderWidth)
setFooterBottomBorder($borderColor, $borderStyle, $borderWidth)
setHeaderLeftBorder($borderColor, $borderStyle, $borderWidth)
setFooterLeftBorder($borderColor, $borderStyle, $borderWidth)
setHeaderRightBorder($borderColor, $borderStyle, $borderWidth)
setFooterRightBorder($borderColor, $borderStyle, $borderWidth)
We can set the padding of the header and footer using respectively setHeaderPadding($padding)
and setFooterBorder($padding)
.
$pageStyle = new PageStyle('myPageStyle'); $pageStyle->setFooterBorder(); $pageStyle->setFooterPadding('1cm'); $pageStyle->setFooterContent(StyleConstants::PAGE_NUMBER);
We can also apply the padding to only one side of the header or footer, using one of these methods:
setHeaderTopPadding($padding)
setFooterTopPadding($padding)
setHeaderBottomPadding($padding)
setFooterBottomPadding($padding)
setHeaderLeftPadding($padding)
setFooterLeftPadding($padding)
setHeaderRightPadding($padding)
setFooterRightPadding($padding)
We can change the background color of the header or the footer by using setHeaderBackground($color)
and setFooterBackground($color)
.
We can set a background image to the header or the footer by using setHeaderBackgroundImage($image, $repeat, $position)
and setFooterBackgroundImage($image, $repeat, $position)
.
$image
: The image's path.$repeat
: Specifies whether a background image is repeated or stretched. Valid values are StyleConstants::(REPEAT|NO_REPEAT|STRETCH).$position
: Specifies where to position a background image in a paragraph. Valid values are StyleConstants::(LEFT|RIGHT|CENTER|TOP|BOTTOM).We can change the format of page numbers using setPageNumberFormat($prefix, $suffix, $format)
.
$prefix
: Prefix of the number.$suffix
: Suffix of the number.$prefix
: The format of the number. There are five possible formats: "1", "a", "A", "i", or "I", which respectively mean: numeric, lowercase alphabetic, uppercase alphabetic, lowercase roman, uppercase roman.