Extjs pdf printing is the best solution

I am trying to print a pdf file using extjs and any help would be appreciated. My idea was to transfer the PDF file from the server as a stream, as advised by http://xmlgraphics.apache.org/fop/0.95/servlets.html#minimal-servlet . But the problem is that firtly I submit form data via ajax, save it to the database, create the PDF using FOP and ... I want to transfer the received PDF back to the client. My last idea is to save the PDF to a temp file on the server, return success: "true" for extjs, and then restore the temp file again using print iframe :) Are there any better solutions? or maybe someone has a working working code for this?

+3
source share
2 answers

Well, finally, I came to the following solution: firstly, we use the AJAX request to save the form details and create a PDF file on the server side.

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

How do we use iframes to download and open a file?

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

This approach allows us to check whether the response is saved for operability and display a useful dialog for the user if the save fails.

+2
source

I don't think this has anything to do with Ext JS. You need to either generate / save the PDF file, or return the URL to it, as you mentioned, or send the response directly to the browser using the "application / pdf" type of content, and the default browser behavior will work with it. Any approach is common to any frontend code.

, .NET. .

0

Source: https://habr.com/ru/post/1736403/


All Articles