Building Pdf Documents Without Adobe Indesign Server

What is PDFz ?

PDFz is a technology included in the Wedia server that using Apache:FOP to generate PDF from JSP pages.

There is no need to use or install an InDesign Server.

This technology is very suited for generating reports, contact sheets…​

Getting started

PDFz starts with a regular JSP page. By changing the .jspz url termination to pdfz it triggers the PDF rendering and output a PDF.

This first example is to create a basic PDF, to understand the overall operation.

For that, we will create in directory $SAN/perso a directory named "tutorial".

In this directory $ SAN/perso/tutorial, create a file named tutorial_1.jsp and copy and paste the following code:

<%@page pageEncoding="ISO-8859-15"%> <%@taglib prefix="pdf" uri="/WEB-INF/pdf.tld" %> <pdf:section> <pdf:content>This is your first PDF content</pdf:content> </pdf:section>

Assuming that our server is accessible on the url http://localhost/wedia/, we can consult the page by going to http://localhost/wedia/tutorial/tutorial_1.jspz.

This page will return us in HTML mode the content: "This is your first PDF content".

Now we will turn this content into PDF.

Just change the url to http://localhost/wedia/tutorial/tutorial_1.pdfz.

Note the final "pdfz" instead of "jspz".

This has the effect of allowing us to directly receive the generated PDF.

Troubleshooting issues with PDF

PDFz is based on xsl:fo technology, and you will learn a lot about PDFz by reading tutorials about xsl:fo.

When the causes of rendering problems are difficult to identify, it is possible in development mode to add the pdf.debug=true parameter to the pdfz url.

The rendering will no longer be pdf but fo which is the intermediate step before the pdf rendering.

This allows the advanced user with knowledge of the xsl-fo format to find the causes of the errors.

Setting the DPI of a PDFz

By default, the generated pdf are in 96 dpi.

To generate pdfs in higher definition, just add the pdf.dpi = <dpi> parameter to the generation url (* .pdfz).

For example, to generate a pdf in 300 dpi, just add pdf.dpi = 300.

Using print measurements in HTML

You can use "cm" in replacement for "px" or "em" to more precisely define your layout :

<img src="${src}" style="max-width: 4cm; max-height: 4cm" >

Setting page height and width

You can use the following properties :

<pdf:section pageWidth="21cm" pageHeight="29.7cm">

Margins

You can set margins for each section :

<pdf:content margin="2cm">

Troubleshooting issues

It is common to have issues with rendering, mostly due to fonts not being installed.

In that case, adding the pdf.debug=true parameter, like : my-document.pdfz?pdf.debug=true returns additional information:

  • flux fo: gets the “fo” generated document

  • config: gets the complete config of “fop”

  • fonts: lists all the fonts used by fop

Fop, since 11.29.0 , uses all fonts preset in the san “fonts” directory, that can be targeted by backup / restore.