0

I am using ## Ofbiz XSL FO template for downloading PDF files ##. Currently the pdf file downloading with the same name always. I need to set the name of the PDF file. How can I set the filename dynamically? In some other questions I see that we have to set the response header "Content-Disposition", but not sure in ofbiz where to set this. Any answers or pointers will be helpful.

My controller.xml

    <view-map name="InvoicePDF" type="screenfop" 
   page="component://myapp/widget/OrderScreens.xml#InvoicePDF" content-type="application/pdf" encoding="none"/>

My OrderScreens.xml

          <!-- PDF Screens --> 
 <screen name="InvoicePDF">
    <section>

        <actions>
            <property-map resource="AppUiLabels" map-name="uiLabelMap" global="true"/>
            <service service-name="getInvoiceDetails" auto-field-map="true"/>
        </actions>
        <widgets>
            <platform-specific>
                <xsl-fo><html-template location="component://myapp/webapp/myapp/static/pdf/invoicePrint.fo.ftl"/></xsl-fo>
            </platform-specific>                
        </widgets>
        <fail-widgets>
            <label style="h3" text="${uiLabelMap.PrintPermission}"/>
        </fail-widgets>
    </section>
</screen>   
Mahesh K
  • 31
  • 5
  • OK, it's maybe not the answer you are looking for (so only a comment for now); but did you consider https://blogs.apache.org/ofbiz/entry/the-birt-flexible-reports-a - https://cwiki.apache.org/confluence/display/OFBIZ/Birt+Flexible+Reports ? – JacquesLeRoux Nov 30 '17 at 22:13
  • Thanks Jacques for the comment.. I had looked at the link.. interesting. I will explore it further.. However my immediate problem is to do this within the application using existing XSL-FO template. I experimented further and found a temporary solution for my problem. I added a groovy script action and where I sent the response header. – Mahesh K Dec 01 '17 at 19:26

1 Answers1

3

I tried one option and its working for me - I added a new groovy script in the actions tag as below:

        <script location="component://myapp/webapp/myapp/WEB-INF/actions/setContentDisposition.groovy"/>

setContentDisposition.groovy

import javax.servlet.*;
import javax.servlet.http.*;

filename = invoiceNumber +"_" + month + ".pdf";
response.setHeader( "Content-Disposition", "attachment;filename=" + filename );
Mahesh K
  • 31
  • 5