Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
ttrapp
Active Contributor
0 Kudos

In one of my last blogs I showed how to create Word documents using XSLT. But what about PDF? PDF generation without Adobe Forms or other commercial tools is much more difficult. This holds even for XSL-FO formatters because the standard is so complicated that only commercial tools support every feature. Nevertheless I suggest to use the Open Source Apache FOP framework written in Java. You can run under the Java stack or use the virtual machine of the application or even the presentation server.

Form a conceptual point of view the Extensible Stylesheet Language consists of two parts:

  • SLT for transforming XML documents to other XML documents (indeed XSLT can produce any computable Unicode stream) and
  • XSL-FO (FO stands for “formatting objects”) which is a kind of XML based language comparable to LaTeX.

There are rendering engines (think of above mentioned Apache FOP) that can generate LaTeX or even PDF from an XSL-FO document. Of course it is a matter of taste but I think LaTeX is much more fun compared to XSL-FO.  But XSL-FO has a big advantage: We can use the “XML infrastructure” to generate XSL-FO from XML documents using transformation languages like XSLT or Simple Transformations.

A Simple but Instructive Example

ABAP programming is easy – but getting access to the whole ABAP development infrastructure is hard. ABAP developers spend most of their time to get access to transactions like SM58, SM59 or SCIF on their development systems. One might think the “Basis” knows that we need SICF for BSP and Web Dynpro programming and that every 1/2K SDN member knows how to get SAP_ALL within seconds but they defend access to certain profiles and roles like their own life. Usually developers make mistakes when talking to Basis people by saying that we "know what we're doing" and that "there are more subtle ways to ruin the development system without access to ‘critical’ transactions" and so on. Even sending SU53 spools to the admin won't help you. I learned the only chance is to print out a paper like the following and put it on the admin's desk:

Let's consider creating this document as PDF. \ In the following I'll present a report and a Simple Transformation that generates an XSL-FO stylesheet that will generate the PDF document shown above. At first we need the information from the last authority check in a structure of type usr07. Then we pass those structure to the Simple Transformation Z_SU53. This can be done with the following hack:

The Simple Transformation Z_SU53 consist of XSL-FO statements and adds values of the usr07 structure to the output:

Let's try to start transaction SICF but instead of looking at SU53 we start the ABAP report above and get the following result:

Now we have to process this XSL-FO document with Apache FOP and we are ready.

Let's look at the example in detail. At first we define a layout master using the element fo:layout-master-set and then a sequence of pages using fo:page-sequence. The content elements (text, graphic and so on) are children of the fo:flow element. This element contains a definition for the standard font defined by the attribute font-family.

Within the element fo:flow  we define several fo:block elements containing paragraphs of text. The attribute space-after.optimum="6pt" defines space after each block.  Within each block we change the standard font (see fo:inline element).

Summary

In this blog entry I introduced XSL-FO and Apache's FOP framework and showed how to use Simple Transformations to generate XSL-FO documents from ABAP data. And last but not least I gave a hint for a better communication with Basis people.

6 Comments