1
votes

I am generating pdf using FOP, and I want to include border for every page in pdf. I am using XSLT 2.0.

Is there any way or any attribute or any tags to create a border for every page in XSL?

1

1 Answers

1
votes

You can add a border attribute to the fo:region-* elements (and padding too, if needed).


Note that, strictly speaking, this is not allowed by the XSL recommendation:

The values of the padding and border-width traits must be "0".

and the standard behaviour of FOP would be to end with a validation error:

SEVERE: Exception javax.xml.transform.TransformerException: 
org.apache.fop.fo.ValidationException: Border and padding for fo:region-body 
"xsl-region-body" should be '0' (See 6.4.14 in XSL 1.1); non-standard values
are allowed if relaxed validation is enabled.  (See position ...)

However, as this is after all a common use case and other formatters allow this too, you can run FOP with relaxed validation and get the desired output:

  • adding the option -r if you are running FOP from the command line
  • using the FopFactoryBuilder.setStrictFOValidation() method in the Java code

You still get a warning about the non-standard behaviour, but the processing continues normally:

WARNING: Border and padding for fo:region-body "xsl-region-body" should be '0' 
(See 6.4.14 in XSL 1.1); non-standard values are allowed if relaxed validation
is enabled.  (See position ...)