Custom styles for pdf export

Hi everybody,

I am pretty new to pressbooks, so this is probably an easy question for you guys :wink:

I use a self-hosted version of pressbooks and use the McLuhan Theme right now. I also use mPDF for the pdf export. I want to style the head of a chapter with adding the page number and giving it a blue background.

So I navigated to Design -> Custom Styles -> PDF and added this lines:

@page chapter:right {
@top-right-corner {
	background-color: cmyk(1, .3, 0, .5);
	color: cmyk(0, 0, 0, 0);
	content: counter(page);


Unfortunately after exporting the book nothing happend to the styling, neither do I have the page numbers in the head of the page nor is anything blue.

Can you help me? Thanks!

1 Like

Hi @phellwig, as far as I know, CSS added via Custom Styles is not used by the mPDF export module (which is a community project maintained by @brad at BCcampus rather than the Pressbooks team); the PDF styles you’ve added to Custom Styles would be applied to PDF exports using the Prince PDF or DocRaptor PDF export modules that are included in Pressbooks core. @brad may have some insights into how you could add custom styles to your mPDF exports.

Hi @ned, thanks for this very useful information. I didn’t knew of these “restrictions”. I will give DocRaptor a try and wait if @brad can tell me more about mPDF.


mPDF does indeed support custom styles, though there are some limitations with what CSS is supported - mPDF inherits kneadCss() from prince/class-pdf.php which pulls in Custom Styles


Custom Styles:

The issue here is that the CSS that’s being declared creates undesirable behaviour in mPDF. @page when declared creates an unwanted page break each time it’s called. Unfortunately, if I don’t strip it out it creates really long documents with many blank pages.

mPDF support for CSS is documented here:

hope that helps


Hi @brad,

Thanks for this detailed explanation!