Machine generation of PDF files the easy way – part IV

This fourth example will extend upon my previous XSL-FO script to convert the list from a table with a few boxes into more of a polished form. The final result will generate a form and will look like this.

data4You are only really limited to your imagination for a lot of XSL-FO. It is possible to change how the pages are laid out, types of headers, types of footers, orientation of the pages, various margins, add additional fonts or even add graphics.

One of the small things that really makes forms look like forms is the ability to put a small description in each of the cells. If the form is machine printed it will look good but if the form is for the user to fill in, it is a necessary description.

The only change is to add these small descriptions for each cell of this form. Conceptually, what you do is to have a table within each cell where the description is very small text and the field value is a normal sized text.

This isn’t the only way to achieve this result but to add this to an existing form is fairly mechanical in nature. This method causes all of the descriptions to look the same and be located the same spot in each cell.

You could fool around with fonts and sizes but getting things to line up the way you want without using an inner table would be challenging.

Simple cell

<xsl:template match="person">
    <fo:table-row >
       <fo:table-cell font-weight="bold" border-collapse="collapse" border-style="solid" border-width=".1mm" text-align="left" padding="1mm" >
           <fo:block>
           <xsl:value-of select="first"/>
           <xsl:value-of select="last"/>
           </fo:block>
       </fo:table-cell >
       <fo:table-cell>  

           ...
           second cell left off for clarity

       </fo:table-cell>
    </fo:table-row >
</xsl:template>

Cell with description

<xsl:template match="person">
    <fo:table-row >
       <fo:table-cell border-collapse="collapse" border-style="solid" border-width=".1mm" text-align="left" padding="1mm" >

           <fo:block font-family="Helvetica" font-size="10pt" >
            <fo:table table-layout="fixed" width="100%" >
              <fo:table-column column-width="proportional-column-width(100)" />
              <fo:table-body>
                  <fo:table-row>
                    <fo:table-cell >

                        <fo:block font-family="Courier" font-weight="bold" font-size="6pt" > Name
                        </fo:block>

                    </fo:table-cell>
                  </fo:table-row>

                  <fo:table-row>
                    <fo:table-cell >

                        <fo:block>
                        <xsl:value-of select="first"/>
                        <xsl:value-of select="last"/>
                        </fo:block>

                    </fo:table-cell>
                  </fo:table-row>
              </fo:table-body>
            </fo:table>
           </fo:block>

       </fo:table-cell >
       <fo:table-cell border-collapse="collapse" border-style="solid" border-width=".1mm" text-align="left" padding="1mm" >

           ...
           second cell left off for clarity

       </fo:table-cell >
    </fo:table-row >
</xsl:template>

There is virtually really no changes over the cell with border that was added in the previous step. Well one tiny attribute change. The attribute padding was added to to put a very tiny space between the values provided and the edges of their cell. Simply put adding padding=”.1mm” adds a .1mm margin around the innermost cell.

Adding niceties of this type do make for a polished product but the users cannot appreciate the effort put in. It will be quite visible when maintaining the xslt code.

 

Download source and pdf for this example

The next set of changes for this can be found in part V.

This entry was posted in programming and tagged , , , . Bookmark the permalink.