Showing posts with label fop. Show all posts
Showing posts with label fop. Show all posts

F stands for FOP and Fun

So as I've stated before I almost always deal with static XSL files when building my XML/XSL to FOP transformations.

When I do almost always start with one of two generic XSL files as a starter. One is a Generic Report XSL and another is a Generic Name Value Pair XSL , I've cleaned them up a bit and some commenting and put them up for everybody to try out.

To use them just upload them as a Named Column Template XSL and then apply to any APEX report, the named value pair page breaks after each row because I usually use it to create pages where there is one item with lots of detail.





You will get a very generic PDF but it can used as a base for other XSL files.






These templates also show some extra XSL features, like xsl:if or xsl:choose and xsl:attribute-set. I'll be posting some more specifics on XML+XSL=FOP transforms over the next couple weeks using these two files as examples but for you people that like reverse engineering stuff these files will immediately be useful.

A working example and files for download can be found here.

http://apex.oracle.com/pls/otn/f?p=11933:139

I suggest this site for people unfamiliar with XSL and FOP
http://www.w3schools.com/xsl/default.asp
http://www.w3schools.com/xslfo/default.asp

And I personally use XMLSpy ,one of the few Windows programs I use , for working with XML and XSL files it can directly create PDF's from an XML+XSL transform.
http://www.altova.com/products/xmlspy/xml_editor.html

The UGLY side of FOP

I tracked down an issue for a customer with the default FOP PDF output from APEX. When you change the page to portrait layout the table would extended off the right side of the page.

What causes this issue is a hardcoded width for the table, width="658.8pt"

So how do you get around this, well simple you just remove it.


  1. Go to the Report Layout page

  2. Home > Application Builder > Application NNN > Shared Components > Report Layouts

  3. Choose Create Button

  4. Choose Generic Columns (XSL-FO)

  5. In Report Layout look for and remove this string width="658.8pt"

  6. Save the template and then apply it to your report in it's printing options tab.



It's pretty simple but can cause people some definite pain if you don't know where to look, and it will be removed in next version.

As you get more advanced another thing to look for is the page declaration in that same section.

Right now it is listed as this.

<:fo:simple-page-master master-name="master0" margin-left="66.6pt" margin-right="66.6pt" page-height="#PAGE_HEIGHT#pt" page-width="#PAGE_WIDTH#pt" margin-top="36.0pt" margin-bottom="36.0pt">


But if you need more exacting you can change to something like this.

<fo:simple-page-master master-name="master0" margin-left=".5in" margin-right=".5in" page-height="11in" page-width="8.5in" margin-top=".5in" margin-bottom=".5in">


As you can see I've hardcoded the widths and margins in instead of using the substitution variables. At the moment I'm a big fan of just creating your own edited default portrait and landscape templates as starters templates.

Plus it's a first step into getting into the UGLY world of editing raw FOP and XSL, and won't that be fun.

2 Words for Cocoon.

>>
Hi Carl,
I am new to APEX so my question is probably too simple but if you could describe in 2 words the major benefit of using Cocoon as opposed to just FOP.

Thanks in advance,

Vadim
>>

Well lucky for you Vadim I just happened to be playing around with my Cocoon instance today and am absolutely even more thrilled with the APEX + Cocoon combo than before. So my 2 words if I had to pick them would be XML and Pipelines!

XML for two reasons.
Once Cocoon is setup most of it's configuration is controlled by the sitemap.xmap file which is an XML file , no java libraries, no crazy .conf files, just nice clean XML. For me who has a rational hatred towards all things java this is awesome.

Also the mechanics behind the PDF printing no matter if you using BI Publisher or the Apache FOP solution or my Cocoon example is XML + XSL > FOP = PDF.
Cocoon is made to deal with XML and XSL in hundreds of ways, just using the sitemap.xmap file which gets us to the next word......

Pipelines the cornerstone of Cocoon.

http://cocoon.apache.org/2.1/userdocs/concepts/sitemap.html


Now the dirty little secret I have is that I never use the XSL that is posted from the APEX engine. I use XSL from the filesystem.

In Cocoon once you have your XML you can look into it for certain values and pipeline the XML to different transformations. This can easily give you different report formats for the same Apex Report depending on near any value in the report , page or session.

One of the things I hope to make facilitating this in the future is to allow for each report (via the APEX Builder) to have an individual FOP posting endpoint.

Finally two more points , though it goes over my two word limit it's my blog, in Cocoon you also have the ability for RTF output which you don't get from standard FOP and also the ease of setup which I find amazingly easy.

So you want your PDF printing but playing with JSP's and java libraries isn't your thing. Well there is another way to setup PDF and RTF output. The key is in the cryptic last paragrach of the APEX + PDF howto

>>
Other XSL-FO Processing Engines

If you prefer to use another XSL-FO Processing Engine, you will need to create an endpoint that provides similar functionality to the example JSP provided for the Apache FOP example above.
>>

Well I do prefer another XSL-FO Processing engine which is Apache Cocoon and Apache Tomcat. Cocoon is my favorite web framework other than APEX of course and I've used them together on many occasions.

Instead of a long drawn out howto I instead created this viewlet to show you the steps of the process.

The files you will need can be found through these links.

Cocoon


Tomcat


fop_post.zip


APEX and Cocoon Viewlet

If you have any questions please feel free to leave some comments but I think the setup and usage is very simple.