0

i want to open a local PDF file in my sapui5 app, when i click a button.

Have anyone an idea, how could I solve this.

    onOpenDoku: function(oEvt) {
        //alert("Test für Dokumentenanzeige");
        var pdfViewer = new sap.m.PDFViewer();
        this.getView().addDependent(pdfViewer);

            //var oSample1Model =  new sap.ui.model.json.JSONModel({
                //Source: sap.ui.require.toUrl("file:///C:/Test/TestDatei.pdf")
                
            //});
            
            //this.byId('DOKU_BUTTON').setModel(oSample1Model);
            
            //var sSource = oEvt.getSource().getModel().getData().Source;

            var sSource ="file:///C:/Test/TestDatei.pdf";
            pdfViewer.setSource(sSource);
            pdfViewer.setTitle("My Custom Title");
            pdfViewer.open();
            //this.onShowDoku();
    },
Help
  • 31
  • 1
  • 5

1 Answers1

1

You cannot read local file on client side because of security reason. You can try adding link to file or iframe.

<a href="file:///C:/Test/TestDatei.pdf" target="_blank">PDF</a>

or

<iframe src="file:///C:/Test/TestDatei.pdf" width="200" height="200"></iframe>
mkysoft
  • 5,392
  • 1
  • 21
  • 30
  • thank you for your answer. my code works in internet explorer but in chrome not. – Help Oct 13 '20 at 07:39
  • I guess it is related with Chrome security rules. May be you can use iframe for IE and link for Chrome. More detail about Chrome security for local files in [this post](https://stackoverflow.com/questions/17950598/using-iframe-with-local-files-in-chrome). – mkysoft Oct 13 '20 at 08:39