1

I am using Spring + ExtJS and need to 'export to' functionality on UI screen. I am making an Ajax call and sending the data in JSON format to controller. In controller I am doing all stuff to generate the PDF using iText and it does generate the document.

Now I am not seeing the generated PDF to downlaod/view in browser. If I do it without Ajax call, it works. Not sure whats making the difference.

I read few related articles around this which suggested to use below :

Content-type: application/pdf
Content-Disposition: attachment; filename="FileName.pdf"

But no luck with this. Please advice on this/let me know if going wrong.

Snehal Masne
  • 3,403
  • 3
  • 31
  • 51

1 Answers1

1

As mentioned here and here, you can use an hidden iframe to do this. Personnally I prefer the hidden form posting solution, here is an example :

var formEl = Ext.DomHelper.append(document.body, {
            tag: 'form',
            css : 'display:none;',
            id: 'downloadForm'
        }, true);
var form = new Ext.form.BasicForm(formEl, {
            url : [your spring controller url],
            method : 'POST',
            fileUpload: true,
            baseParams: [your JSON parameters]|| {}
        });
form.doAction(new Ext.form.action.StandardSubmit({
            form: form,
            clientValidation: false
        }));

I hope this helps.

Community
  • 1
  • 1
budgw
  • 710
  • 1
  • 5
  • 13
  • Using iFrame is not supposed to be done in my project, more over, it doesnt work when tried. :( – Snehal Masne Aug 21 '14 at 13:58
  • Did you try storing the PDF first locally on server and then sending that location info in ajax reponse and then fetching the file later the ajax request ? – TechLover Aug 22 '14 at 13:08