Docbkx Paper Size

2018-08-30

Tags:
Categories:

Problem

You just generated a PDF from Maven with the docbkx-maven-plugin, and everything is OK but the paper size is "US Letter". You want A4.

Solution

Method 1

Set the paper.type parameter in the XSL file:

<build>
	<plugins>
		<plugin>
			<groupId>com.agilejava.docbkx</groupId>
			<artifactId>docbkx-maven-plugin</artifactId>
			<version>${project.version}</version>
			<configuration>
				<foCustomization>src/docbkx/docbook-fo.xsl</foCustomization>
			</configuration>
		</plugin>
	</plugins>
</build>
<?xml version='1.0'?>
<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:import href="urn:docbkx:stylesheet" />
	<xsl:param name="paper.type" select="'A4'" />
</xsl:stylesheet>

Note

Instead of

<xsl:param name="paper.type" select="'A4'" />

you may also write

<xsl:param name="paper.type">A4</xsl:param>

which looks better because there's no need for the single quotes.

However, if you or your text editor inserts any whitespace, then it won't work:

<xsl:param name="paper.type">
	A4
</xsl:param>

So either take care and keep it on one line, or wrap the value in <xsl:text>:

<xsl:param name="paper.type">
	<xsl:text>A4</xsl:text>
</xsl:param>

Method 2

Set the `paperType` parameter in the plug-in configuration:

<build>
	<plugins>
		<plugin>
			<groupId>com.agilejava.docbkx</groupId>
			<artifactId>docbkx-maven-plugin</artifactId>
			<version>${project.version}</version>
			<configuration>
				<paperType>A4</paperType>
			</configuration>
		</plugin>
	</plugins>
</build>

Sources

Identification of the parameter
http://www.sagehill.net/docbookxsl/PrintOutput.html#PaperSize
Setting the parameter
http://www.sagehill.net/docbookxsl/SettingParams.html
Using <xsl:text>
https://stackoverflow.com/a/3637475
Parameter in the plug-in configuration
http://docbkx-tools.sourceforge.net/docbkx-samples/manual.html