0

I have a SAPUI js controller that will call a servlet to display a pdf file. However, the url call returns a response which I believe is a pdf xstring format. Basically if i open the url directly it will just display the pdf, but since i am calling the servlet, there is no window opened.

Following is my call.

            $.ajax({
                url : 'http://localhost/pentaho',
                type: 'GET',
                crossDomain: true,
                success : function(data) {

                },
                error : function(data){
                    console.log("Error");
                }
            }); 

I am using GET as i would need to pass some parameters to the servlet but I just require the pdf to be displayed. The ajax call is successfull with the variable (data) filled with which I believe the xstring binary pdf.

Question : 1. Can i call the servlet url and let the pdf open in another window without a response ? 2. How do i format the response string to display as pdf in sapui5 if above is not possible.

The data stream looks like this.

%PDF-1.6 %âãÏÓ 21422 0 obj <>stream hÞœ›Q,Çq¥ÿÊ

Hope you can help shed some light into the matter.

Thanks. Anand

  • You can follow the guide https://sapui5.hana.ondemand.com/#/api/sap.m.PDFViewer%23controlProperties Also for embedded from data variable you can use "data:application/pdf," + encodeURI(pdfString) Refer this https://stackoverflow.com/questions/2805330/opening-pdf-string-in-new-window-with-javascript – Ashish Jun 09 '20 at 17:56
  • 1
    You say that if you open the URL directly it will just display the pdf. Then why don't you just open the URL in a new tab via JavaScript? `window.open("http://localhost/pentaho")` – Marc Jun 10 '20 at 06:22

1 Answers1

0

Both suggestion works and gave me some hints to progress. Finally went with the following.

Set the source with the URL options as parameters

                       var source = "/pentaho?P_WERKS="+oClient;
                        var _pdfurl = source;
                            this.oPDFViewer = new sap.m.PDFViewer();
                            this.oPDFViewer.setSource(_pdfurl);
                            this.oPDFViewer.open();

Thanks. Anand