Question

I'm interested in creating a custom cover page for a DocBook 4.5. Is it possible to tell the toolchain to use a prebuilt PDF page for the cover page? In this case, I would simply create it in Word or Writer, and then add something to the customization layer to use it as the first page of the book.

Its important to have the DocBook toolchain incorporate the prebuilt cover page to keep page numbering and style consistent (i.e., cover-front is 'i', cover-back is 'ii', table of contents is 'iii', etc). So PDFedit and friends are out of the question.

Related (but not required for the question): for those who are interested, I've tried making sense of documents like this. But they ramble on without telling me succinctly what I should do. And adding the following to the customization layer does not change the space before the title, does not change the font size of the title and lacks the logo.

<xsl:attribute-set name="book.titlepage.recto.style">
  <xsl:attribute name="space-before">2in</xsl:attribute>
  <xsl:attribute name="font-size">32pt</xsl:attribute>
</xsl:attribute-set>

If I change it to book.titlepage.verso.style, then the font size on the second page will change (but not the leading space before the text). Its totally baffling to me, and I'm tired of trying to figure these ill-logical details out.

Was it helpful?

Solution

You can use a pre-created PDF file as a book cover. But in order to merge that cover and the PDF built from DocBook sources, you would need a program such as PDFedit or Adobe Acrobat. There is nothing that you can add to a DocBook-XSL customization layer to accomplish this.

It is possible to incorporate a cover (where a prebuilt PDF might be incuded by reference, as an image) when building the PDF from DocBook sources, but the stock DocBook-XSL stylesheets provide very little support for this.

A cover element was introduced in DocBook 5.0. But in order to do something useful with it, you would have to write the needed XSLT templates from scratch. See the Book covers section in Bob Stayton's book for some more information.

The latter half of the question is about title pages which are different beasts. If you need help with title pages, please ask a separate question (btw, you can also ask at the docbook-apps mailing list; see http://docbook.org/help).

OTHER TIPS

In addition to mzjn's answer, here's what I found that works great from a script (assuming the book is being built from a script). It works great and does not require you to fight Docbook on adding a figure or other layout elements. Thanks to Sid Steward for the page numbering suggestion.

You will need the following:

  • book.pdf - your book with the Dockbook generated cover without graphics
  • cover.pdf - the one page cover you want to use created with Microsoft Word, OpenOffice Writer, etc
  • pdftk - toolkit for manipulating PDFs (http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/).

The following script will automate the 'fixup' of the book cover and numbering. Add them after the standard xsltproc and fop (or xep) commands.

# xsltproc and fop commands omitted
...

# First, remove the Docbook cover
pdftk book.pdf cat 2-end output temp1.pdf

# Second, concatenate the desired cover and remaining book
pdftk cover.pdf temp1.pdf output temp2.pdf

# Third, clean up the book's output
pdftk temp2.pdf output book.pdf

# Cleanup temp files
rm temp1.pdf temp2.pdf

At this point, book.pdf has the desired cover with images and other items such as a date, version, etc. But the page numbers are probably off.

The page numbers are off because Docbook numbers the cover as i, the legal notice as ii, the Table of Contents as iii, iv, iv, etc. That is, they use Roman Numerals before the content and then Decimal numbering of 1, 2, 3, etc. However, pdftk does not accept numbering schemes at this time.

To fix the numbering scheme, use sed to add the numbering scheme as follows. sed will search for /Type /Catalog. Once found, it will add a new line (\n&). After the new line, the following is inserted to add the roman/decimal numbering: /PageLabels << /Nums [ 0 << /S /r >> 4 << /S /D >> ]

# Fix the page numbering
TMP_FILE=`mktemp /tmp/book.XXXXXXXXXX`
sed -e "s|/Type /Catalog|/Type /Catalog \n& /PageLabels << /Nums [ 0 << /S /r >> 4 << /S /D >> ] >>|" book.pdf > $TMP_FILE
mv $TMP_FILE book.pdf

0 << /S /r >> means use lower case roman numerals starting at page 0 (its 0-based).

4 << /S /D >> means use decimal numbers starting at page 5 (its 0-based). It should be changed to reflect page 1 of the book in question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top