APEX + Cocoon = PDF (and more)

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.

43 Comments:

  1. Alex Gorbachev said...
    Looks cool. Thanks.
    Anonymous said...
    Great alternative Carl. Always love to see the viewlets as demos on how to do stuff - so much easier to follow.
    Regards,
    Jon.
    Anonymous said...
    Nice alternative.
    Is it possible to install Cocoon on the Oracle Application Server 10.1.2.0.2?
    Regards,
    Guido
    Anonymous said...
    Thank you, works like a charm!

    If you use JDK 1.6 instead of JDK 1.5, then you need to change the ExcaliburDataSourceFactory.java file. The changes that you need to make can be found here:
    http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/databases/java/org/apache/cocoon/databases/ibatis/ExcaliburDataSourceFactory.java?view=markup&pathrev=495744
    Anonymous said...
    Hey Carl,

    I have a problem with your cocoon solution!

    When I try to generate a pdf from Shared Components(Test Report) i receive this message:
    "Adobe reader could not open 'mistakes.pdf' because it is either not a supported file type or because the file has been damaged (for example it was sent as an email attachment and wasn't correctly decoded)"

    Can you help me with that?

    Thread in APEX Forum:
    http://forums.oracle.com/forums/thread.jspa?threadID=488120&tstart=0&start=15

    Thank you,
    Tim
    Rama Nalam said...
    Hi,
    Thank you very much for your alternative. This is very simple and the viewlet helped a lot. I tried to install it on Solaris. There was a problem with JMS installation with Tomcat. I tried to build the JMS according to Tomcat web site. It worked fine. Thanks again for your wonderful article.
    Anonymous said...
    Carl,

    I can get Tomcat and Cocoon working fine. However, the fop_post's sitemap.xmap is giving me some problems.

    org.apache.cocoon.ProcessingException: Unknown request object encountered named xml : null

    I think this error refers to the form-name parameter. What form-name does APEX post to Cocoon, when it sends the XML stream?
    Jason D. Aughenbaugh said...
    I am having problems with opening the pdf reports. It says there is an error. When I switch to the word outputs it only has the word 'unauthorized' on it.
    David said...
    Hi
    I want to print totallity of a page APEX in pdf. Is it possible ?
    Anonymous said...
    Any way to compile Cocoon 2.1.10 for JAVA 1.4.2?
    Carl Backstrom said...
    Hello,

    I've never tried with Java 1.42

    The Cocoon requirements say http://cocoon.apache.org/2.1/installing/requirements.html

    1.3 and up

    You also have to take the Tomcat requirements into account but it looks like most of those will run in 1.3 and up as well.

    http://tomcat.apache.org/whichversion.html

    Carl
    Unknown said...
    Thank you for the tut. After typing build war.. I get the following error
    Target "War" does not exist on this project. I took the fop.war file provide in the APEX directory and plugged it in the cocoon main directory and still got this error. Where do I put the war file and what do I name it prior to building cocoon?
    {PR}
    Karen said...
    My cocoon build fails with:
    ...
    cocoon-block-databases-patch:
    Processing: C:\APEX_FOP\cocoon-2.1.10\src\blocks\databases\conf\databases-trans.xmap
    Writing: C:\APEX_FOP\cocoon-2.1.10\build\webapp\sitemap.xmap

    BUILD FAILED
    C:\APEX_FOP\cocoon-2.1.10\tools\targets\webapp-build.xml:113: The following error ocurred while executing this line:
    C:APEX_FOP\cocoon-2.1.10\build\cocoon\temp\blocks-build.xml:1636:
    error occurred while executing this line:
    C:APEX_FOP\cocoon-2.1.10\build\cocoon\temp\blocks-build.xml:165:
    FileNotFoundException: java.io.FileNotFoundException: C:\APEX_FOP\cocoon-2.1.10\build\webapp\sitemap.xmap (The requested operation cannot be performed on a file with a user-mapped section open)

    sitemap.xmap was successfully written to several lines above with no problem. I have restarted twice and got a bit furthur each time.

    What to look for? Where to go?
    I am using jdk1.5.0_06.
    All else is the same.
    Carl Backstrom said...
    Hello,

    Pedro
    The fop.war solution that ships with APEX is different than this solution, and I'm not sure they would work together nicely.

    The Cocoon solution is an alternative to the fop solution.


    Karen
    That looks like it's a Cocoon build issue.

    I'd take a look at the cocoon forum here http://www.nabble.com/Cocoon-f111.html as you will probably get better information than I can give you. That section of my install has always just worked.
    Anonymous said...
    Is there any way to use cocoon in order to perform an Advanced printing like a master detail report ?
    Tks
    Tullio
    Anonymous said...
    Hi Carl,I've installed tomcat+cocoon by your way, all is running, but if i try print from apex application, in tomcat log (on screen) i can see conversion progress otherwise apex ends with "page not found"
    However APEX is runing on Oracle Apache web server, not on installed tomcat with cocoon. Can i to use apex application with this configuration(Oracle Apache+apex, tomcat+cocoon), or apex must be configured on tomcat web server ?
    (so how to "connect" apex on tomcat ?)
    Thanks !
    Wil.
    Tony said...
    Carl -

    I too am curious how to use Cocoon with Oracle's Application Server (10.1.3). I am currently using OAS as my Apex front-end and would like to take advantage of Cocoon. All signs seem to point to Tomcat/Cocoon and not OAS/Cocoon. Does it create any issues if you install Tomcat on the same server as OAS?
    Unknown said...
    This comment has been removed by the author.
    Unknown said...
    Tony,

    you should be able to install the war file into an existing OC4J container (which is part of the IAS 10.1.3). There is no need to install Tomcat as well.

    You could do it if you wanted to, but there is really no need to manage another J2EE container.

    You should give it a try.

    Regards,
    ~Dietmar.
    Tony said...
    I got Cocoon deployed to OAS and things are mostly working. It appears as though the XLS export doesn't work. I also haven't been able to get a RTF report template to work. I get an error during the generation of the document "C:\cocoon\styles\main.css" is missing. Why is it looking on my local machine for a css file when the RTF is in Apex?
    Anonymous said...
    Thank you Carl, it is a very usefull step by step installation guide, however
    I have the same problem as Tony:
    quote (I get an error during the generation of the document "C:\cocoon\styles\main.css" is missing.)

    although if I use the default layout it works but if I creat an RTF it doesn't.

    do you have a step by step guide for the layout creation ?

    Best Regards.
    Anonymous said...
    Great,

    I like your alternative Carl.

    Unfortunatly image, formating and others include clob are not include in PDF. :-(

    Thx for your stuff.

    Dave
    Anonymous said...
    Oupss.. Sorry.

    My condolences to Carl's friends and family

    Dave
    Anonymous said...
    For resolving Excel, HTML and XML output see here:

    http://rste.blogspot.com/2008/07/excel-export-from-apex-cocoon.html

    Dave
    Anonymous said...
    Apex + Cocoon works nicely for me. Except i cannot get dynamic images to work. I tried the technique provided at: http://marcsewtz.blogspot.com/2008/06/one-question-about-pdf-printing-feature.html
    I get not error message but the image is not showing in the pdf either. Is it possible to use base64 encoded images from xml with Apex + Cocoon?
    Anonymous said...
    Hello
    Great, averything working.
    However could you show how to get printing in custom RTF?
    Joel said...
    Hi Carl,

    This is cool.
    I got it to work for Word, PDF and XML. For Excel and HTML, it gave me

    < /Type /Info
    /Producer (FOP 0.20.5) >>
    endobj
    5 0 obj
    << /Length 2205 /Filter [ /ASCII85Decode /FlateDecode ]
    >>
    stream
    Gau129iE!$&;KZM'mkUdnU0c-NYi%5QUs2>E=O,s7:*o5l%;N"55ou]Cld*b2!T9OV,Cl@go9^jk/m1/UqE1UXsTo.7d@'S

    and so on ...

    Any idea?

    Thanks
    -Yoel
    Unknown said...
    I had the problem with empty reports, and found that it was caused by NOT typing the last slash in "/cocoon/fop_post/"
    when configuring APEX.
    Anonymous said...
    Hello Carl,
    I am trying to set-up the XLS FO printing engine on Apex 3.2 under Linux platform. I followed your instructions and I can not get the cocoon.war file. In Windows environment it worked very well, I entered build war and it created the war file. However in Linux that statement does not work. I would like to illustrate you the way I am doing it in other that you can help me.

    oracle@pablo-laptop:~/apache_fo/cocoon-2.1.11$ export JAVA_HOME=/u01/app/oracle/product/11.1.0/oraibex/jdk/jre

    oracle@pablo-laptop:~/apache_fo/cocoon-2.1.11$ build war
    No command 'build' found, did you mean:
    Command 'buildd' from package 'ubuntu-dev-tools' (universe)
    build: command not found

    Searching on the Internet about how to build a Cocoon web application in build/webapp and packages as a .war file, I found some information in the Web site: http://cocoon.apache.org/2.0/installing/index.html.

    I found the following statement:
    [unix] ./build.sh -Dinclude.installwar webapp
    It seems that it builds and installs Cocoon war package in a specified directory.

    So, I executed the statement:
    oracle@pablo-laptop:~/apache_fo/cocoon-2.1.11$ ./build.sh -Dinclude.installwar webapp

    Here the last part of the output:
    custom-conf:
    Processing: /home/oracle/apache_fo/cocoon-2.1.11/src/confpatch/enable-uploads.xweb
    Writing: /home/oracle/apache_fo/cocoon-2.1.11/build/webapp/WEB-INF/web.xml

    BUILD SUCCESSFUL
    Total time: 31 seconds

    As you see the command works, but it creates an xml file instead of the cocoon.war file.

    Could you please help me?

    Cordially,

    pablo.wandurraga@gmail.com
    Unknown said...
    Installed APEX and cocoon, all works fine but I need to also to write the pdf output to filesystem, how could i do this with cocoon or with apex ?
    Thanks
    Anant patel said...
    Hi I'm new to APEX, Very nice article...I've followed your viewlet and instlled Tomcat 5.5, JDK 1.5, and build cocoon.war...for pdf printing and was able to configure all envrionment. However, when I try to run the report I get error like "ADOBE READER COULD NOT OPEN "ORDER_DETAILS.PDF" BECAUSE IT IS EITHER NOT A SUPPORTED FILE TYPE OR BECASUE THE FILE HAS BEEN DAMAGED..

    Any help will be greatly appreciated...
    Anonymous said...
    Carl, did you remove the viewlet? We re no longer able to access it. Can you please fix the link or put it in YouTube if it's taking to much bandwidth.

    Thanks
    Nike mercurial soccer cleats said...
    Glad to see all the speakers, really wonderful content. Do not know if you like Nike mercurial soccer cleats or blackout nike vapor
    Anonymous said...
    here you have a free FOP server for Apex that can be installed on windows with just one click:

    Free FOP Server installer


    there is also an XSL-FO editor to create templates in a visual manner.
    Anonymous said...
    here you have a free FOP server for Apex that can be installed on windows with just one click:

    http://www.java4less.com/apache/fop.php


    there is also an XSL-FO editor to create templates in a visual manner
    Stirl said...
    very useful post thanks!
    pay per head call center said...
    Thank you very much for letting me comment, tell it is a pleasure for me to have the opportunity to read this article. Today I read a lot and I assure you that all day had not read anything as interesting as this, I found it very effective information. THANKS
    Anonymous said...
    Hi. This service here allows you to easily edit your PDF documents.
    http://goo.gl/tLrNhC

    You can fill out PDF form, save it, fax it, and email it.
    Furniture Interior Jepara said...
    mebel jati jepara said...
    Pusat bufet jati menjual berbagai macam produk furniture jepara murah

    terlengkap dan terpercaya produk kami seperti jual sangkar burung . Tidak hanya itu kami melayani

    perbaikan laptop anda yang rusak lagsung saja ke servis laptop semarang siap

    membantu anda dan bulu perindu pengasihan dapat membantu masalah asmara anda. kami juga melayani jual hijab terbaru.
    Unknown said...
    Farmhouse Furniture said...
    OBAT TELAT BULAN TERMANJUR said...

Post a Comment