Print Builder*

From PlcWiki

Jump to: navigation, search

Contents

Description

Web-based PDF creation based on the Apache Formatting Objects Processor (FOP) project.

svn+ssh://user@oko.clever.cz: java/PrintBuilder

The goal is to enable the creation of HTML forms whose items are only sent as URL parameters to the servlet and the "free" PDF document is ready and ready to be printed.

Integration

Examples of use

  • Call a servlet using the POST method, which is deployed separately on an available server
  • Forward integration - RequestDispatcher (both applications are deployed on the same Tomcat)

context.xml

<Context crossContext="true">

Creation PDF

  • Creating an XSL template and placing it in the directory referenced by web.xml with the "templatedir" parameter
  • The template name (file name) appears in the URL parameter "templatename" (without extension)
  • Data to fill in the template are sent either directly in the URL parameter "xmldata" in the form of an xml document, or all URL parameters are used, where the 'key is the tag and the value is'

Example URL:

localhost:8080/PrintBuilder/Untitled?templatename=my_template
&singleTAG=first&singleTAG=second
&food[0]=milk&food[0]=egg&vehicle[0]=renault&vehicle[0]=mercedes
&food[1]=onion&food[1]=potato&vehicle[1]=fiat&vehicle[1]=subaru

Illustration of what this URL would look like in Java:

map.put("singleTAG", new String[] { "first", "second" });
map.put("food[0]", new String[] { "milk", "egg" });
map.put("vehicle[0]", new String[] { "renault", "mercedes" });
map.put("food[1]", new String[] { "onion", "potato" });
map.put("vehicle[1]", new String[] { "fiat", "subaru" });

Resulting XML on the server:

<root>
  <list>
    <singleTAG>first</singleTAG>
    <part><vehicle>fiat</vehicle><food>onion</food></part>
    <part><food>milk</food><vehicle>renault</vehicle></part>
  </list>
  <list>
    <singleTAG>second</singleTAG>
    <part><vehicle>subaru</vehicle><food>potato</food></part>
    <part><food>egg</food><vehicle>mercedes</vehicle></part>
  </list>
</root>

'Tag "list" 'it represents one page in the PDF and the "part" tag is an enumeration of values.

The template would iterate approximately as follows:

<xsl:for-each select="list">
  <xsl:value-of select="singleTAG"/>
  <xsl:for-each select="part">
    <xsl:value-of select="vehicle"/>
    ...
  </xsl:for-each>
</xsl:for-each>

Fonts

For the Czech diacritics to work correctly, the configuration file fop.xconf '(referred to as web.xml) must contain the correct paths to the OS TTF fonts and a description of their metrics, including the appropriate xml files. http://corefonts.sourceforge.net/.

Example of link to FOP configuration- web.xml
 <init-param>
	        <param-name>fopconfig</param-name>
		<param-value>conf/fop.xconf</param-value>
 </init-param>

Example of font paths in MS Windows in fop.xconf

 <!ENTITY fop.home "file:///C:/Program Files/Apache Software Foundation/Tomcat 7.0/webapps/PrintBuilder/">
 <!ENTITY fonts.dir "file:///c:/Windows/Fonts">

The first line tells FOP where to look for the conf directory with the metric files.

Links

Personal tools