Tutorial :Printing pdf from extjs - best solution



Question:

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?


Solution:1

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.


Solution:2

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »