maxx
maxx

Reputation: 575

Printing pdf from extjs - best solution

I'm trying to print PDF file using extjs and any help will be appreciated. My idea was to pass pdf file from server as stream as adviced on http://xmlgraphics.apache.org/fop/0.95/servlets.html#minimal-servlet. But problem that firtly I submit form data via ajax, save them to DB, create PDF using FOP and .... want to pass resulted PDF back to client. My last idea is to save PDF to temp file on server, return success:'true' to extjs and then retrieve temp file again using iframe for printing :) Are there any more correct solutions? or may be someone has ready working code for that stuff?

Upvotes: 3

Views: 11326

Answers (2)

maxx
maxx

Reputation: 575

Well, finally I came to the next solution: firstly we use AJAX request to save form details, and generate PDF on server side.

        success : function(form, action) {
            var result = Ext.decode(action.response.responseText)
            if (result.success) {
                this.openForPrint(result.tmpFileName);
            }
        },

Than we use iframe to download and open file

    openForPrint : function(fileSrc) {
        Ext.DomHelper.append(document.body, {
            tag : 'iframe',
            name : 'printIframe',
            src : this.getPrintPalletTagUrl()+'?userAction=actionPrint&tmpFileName='+fileSrc
        });
    }

Such approach lets us to check saving operation response and show meaningful dialog to user if saving fail.

Upvotes: 2

Brian Moeskau
Brian Moeskau

Reputation: 20429

I don't think this has anything to do with Ext JS. You either need to generate/store the PDF and return a URL to it as you mentioned, or you could send a response directly back to the browser with content-type "application/pdf" and the default browser behavior will handle it. Either approach is generic to any front end code.

I have done the second approach successfully, but in a .NET environment. The principles should be the same.

Upvotes: 0

Related Questions