OFBiz Tutorial – Implementing a Product PDF export

Jacopo CappellatoPublished: Updated:

In our last post of the tutorial series OFBiz Tutorial – Implementing a Product CSV export we have learned how to quickly implement a CSV export of a list of rows.

In this post we will perform similar steps in order to create a PDF version of the “Product List” screen.
PDF exports are supported out of the box by the OFBiz widgets.
In this excercise we will:

  1. add to the product list screen a link, close to the CSV export link we have created in our last post, that will generate the PDF export
  2. add to the controller.xml file the request and view entries for the new PDF export screen
  3. implement the new screen definition for the PDF export screen; the screen will reuse the same form used by html screen but with a different decorator (more suited for PDF output)

Adding a link element

We have already learned how to create a link in a screen. We add it after the “CSV Export” link:

  • the new link is inside of the same “container” element of the “CSV Export” link; we want the two links rendered close to each other
  • the link element is defined in the same way we have defined the other link

Controller entries for a PDF export screen

The entries are very similar to the ones we have implemented in a previous post for the product list screen. There are just a couple of things to notice:

  • as usual, the request-map uri must match with the target of the link element in the screen (“ProductListPDF”)
  • in the view-map, the type is now “screenfop” (instead of “screen”) because we have to invoke the “fop screen renderer” to generate a PDF output
  • in the view-map we have also set the content-type to “application/pdf” as useful metadata information for the browser

Screen definition for PDF export screens

There isn’t anything special in a screen definition for a PDF export; the screen is defined in the same way of a normal screen, except for a couple of details:

  • the screen definition is mostly identical to the “product list screen” except for the decorator element: we are now using the FoReportDecorator that is one of the screen decorators available out of the box in OFBiz (it renders simple PDF reports with a page-of-pages footer, logo etc.)
  • in particular, the entity-condition element is the same and it is used to select the list of products for the export
  • the form that is included is the same of the “product list screen”: we will not have to re-implement it because the widget renderer will take care of rendering it into the proper output (PDF or CSV or html)
  • as we already did for the CSV screen, the “set” field operation, where we set “viewSize” to “10000”, is an easy way to “disable” pagination; we actually define the top limit of our product export to 10000 records here, but of course we can use a different value
  • there is an additional set operation here (for “pageLayoutName”), to set the PDF layout to landscape


The exercise is complete and we can test the product PDF by clicking the “PDF Export” link (there is no need to restart OFBiz).

Implementing the PDF report ended up being very similar to implementing the CSV export (or HTML screen): in OFBiz the same patterns, tools and languages can be reused to dramatically improve productivity.

– Jacopo

Jacopo Cappellato About Jacopo Cappellato
Jacopo Cappellato is VP of Technology at HotWax Media and has been involved with the OFBiz project since 2003. He is an OFBiz Project Committer and a member of both the OFBiz Project Management Committee and the Apache Software Foundation.

Comments 8

  1. Avatar for Jacopo Cappellato
    1. Avatar for Jacopo Cappellato

      Hi Hans,

      you can actually use the “screenxml” (in the controller’s view-entry) and you will get a xml based output that can be imported nicely in Excel; or you can use the CSV export that is accepted by Excel as well (see my previous post on this).
      Kind regards,

  2. Avatar for Jacopo Cappellato

    Hi Jacopo,

    can you tell me some way i can set a list which is coming out of a service called on a screen…and the service is invoking java that returns an Util List…please revert back ASAP.

    Thanks & Rergards

    -Prince Sewani

    1. Avatar for Jacopo Cappellato

      Hi Prince,

      I am not sure to understand your question, but you should be able to get the list out of the result of a service call in the following way (in this example the service bogusService returns a list with name myList):

      Hope it helps,


  3. Avatar for Jacopo Cappellato


    (Excuse my english, I’m a french student)

    I followed all the steps in this tutorial and all is OK except the PDF export. When I click on the PDF export button, I have an error :

    Unable to transform FO file: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

    Have you got an idea to solve this problem ?
    I tried to comment :
    type=”screenfop” content-type=”application/pdf”

    And when this was commented, I had this error :


    So I don’t understand what’s wrong with the PDF export.

    Thanks & regards,


    1. Avatar for Jacopo Cappellato

      Hi Teddy,

      your English is great.
      I am sorry to hear that the PDF export is not working, I tested the steps again and they work fine. Are you using the trunk version of OFBiz? Are you able to generate other PDF export from existing OFBiz screens?
      I would suggest you to send a message to the OFBiz user list if you are not able to solve your issue: in the user list it will be easier to communicate.

      Good luck for your studies and thank you for your feedback!


  4. Avatar for Jacopo Cappellato

    Hi Jacopo,
    I am able to create pdf.
    Can you tell me how to align labels(for payslip) and values in pdf page in ofbiz.
    expecting format is like this,

    label1 value1 label2 value2 label3 value3

    label4 value4 label5 value5 label6 value6




    1. Avatar for Jacopo Cappellato

      Hi Ullas,

      I apologize for the very late reply to your question.
      The PDF styling capabilities of the form widget are very simple and if you want more control on the layout of your document you can embed a fo.ftl template in your page and then use fo markup to style the page; you will find several examples of this in OFBiz, just search for files ending with fo.ftl.

      Kind regards,


Leave a Reply

Your email address will not be published. Required fields are marked *