Using PrinceXML from the command line


In SUNY, we use Lumen Learning’s Candela/Pressbooks system as a centralized, hosted space.

There are many positives of having a hosted environment with quality courses. One of the main drawbacks of using Lumen’s System is that they do not prioritize print versions. We only have access to mPDF, not Prince for PDF exports.

I was curious if there was a command I could use from the command line of my own dev Pressbooks server where I can use my own theme/stylesheet with the XHTML from their server.

Current workflow:
Use book cloning to move a book from Candela -> my dev server.
Use PDF export in the Pressbooks GUI.
Use find and replace to go through and change all of the automatically generated URLs that point to my dev server to point back to the production Candela server using Adobe Acrobat Pro.

What I am hoping is possible:
Export the XHTML from Candela (Lumen’s Pressbooks)
Upload that file to my dev server
From the command line, tell my server to do the same process that Pressbooks does through the export GUI, but using the XHTML from the other server.
Enjoy a print ready PDF without manually looking up all the URLs.

Is that possible?


@beckej For Prince exports, we use a PHP wrapper for the Prince CLI (see here and here). Basically we end up doing the functional equivalent of the following.

Print PDF:

prince path/to/book.xhtml --style path/to/book.css --pdf-profile=PDF/X-1a:2003 --pdf-output-intent=/usr/lib/prince/icc/USWebCoatedSWOP.icc --output book.pdf

NB: you ought to also add this snippet to the end of your stylesheet for print output:

:link { prince-link: none !important }

Digital PDF:

prince path/to/book.xhtml --style path/to/book.css --output book.pdf

I’m assuming Prince 11 for these instructions. See here for more info:


Hi Ned,

As always, I appreciate your help.

I tried to do what you suggested, and I did a command that looked like this:

prince /home/ubuntu/Virtual-Learning-Design-and-Delivery-1546455586.html --style /var/www/html/wp-content/themes/pressbooks-book/dist/styles/book.css --pdf-profile=PDF/X-1a:2003 --pdf-output-intent=/usr/lib/prince/icc/USWebCoatedSWOP.icc --output /home/ubuntu/VLDD3.pdf

In each of my attempts I ended up with a 2 page document where it looked like page 1 never broke to fill up page 2 and the content spilled off the page. I think it’s because I haven’t called the right stylesheets…

If I was trying to use the McLuhan theme, what stylesheets should I call? Do I need book.css AND lity.css AND web-house-style.css? Do I need to call to the buckram.scss?


You’d need to pull in the compiled stylesheet. Easiest way is probably: navigate to Custom Styles → PDF, copy the read-only content in the code area at the top, paste it into an empty CSS file on your dev machine and point Prince to that (Pressbooks normally compiles the SCSS during the export routine; that content on Custom Styles is what you’d get).


Hey thanks for all your help on this today!

I just got a mostly successful export just now. It double numbered a couple of my chapters, and the runnings heads and feet didn’t work (yet), but I’m feeling like this will be do-able.