on 2023 Jul 26 10:09 AM
Hello all,
I want to display to local PDF files in my sap ui5 application but it is not showing the files.
I tried the following but it does not work.
I cannot make the path work properly
I have the files on my src folder inside the APP.
View code followed by controller code:
<PDFViewer class="sapUiSmallMarginEnd" source="webapp/src/dummy.pdf" title="{/Title1}" height="{/Height}" width="auto">
<layoutData>
<FlexItemData growFactor="1"/>
</layoutData>
</PDFViewer>
<PDFViewer class="sapUiSmallMarginBegin" source="{/Source}" title="{/Title2}" height="{/Height}" width="auto">
<layoutData>
<FlexItemData growFactor="1"/>
</layoutData>
</PDFViewer>
-------------------------------------------------------
function(jQuery, Controller, JSONModel) {
"use strict";
var PageController = Controller.extend("PdfViewTest.controller.App", {
onInit : function () {
this._sValidPath = sap.ui.require.toUrl("sap/m/sample/PdfViewTest") + "/sample.pdf"; // sap.ui.core.URI("webapp/src/dummy.pdf")
this._sInvalidPath = sap.ui.require.toUrl("sap/m/sample/PdfViewTest") + "/sample_nonexisting.pdf";
this._oModel = new JSONModel({
Source: this._sValidPath,
Title1: "My Title 1",
Title2: "My Title 2",
Height: "600px"
});
this.getView().setModel(this._oModel);
},
onCorrectPathClick: function() {
this._oModel.setProperty("/Source", this._sValidPath);
},
onIncorrectPathClick: function() {
this._oModel.setProperty("/Source", this._sInvalidPath);
}
});
return PageController;
Request clarification before answering.
You use "sap.ui.require.toUrl" like this:
First you add the namespace of your app like "PdfViewTest" or "sap/m/sample".
Then you add the path to your PDF inside the webapp folder.
So for you, it should look like :
sap.ui.require.toUrl("PdfViewTest/sample.pdf")
when your "sample.pdf" is your webapp folder.
If it is in a subfolder of webapp likes "files" it would be:
sap.ui.require.toUrl("PdfViewTest/files/sample.pdf")
https://sapui5.hana.ondemand.com/sdk/#/api/sap.ui%23methods/sap.ui.require.toUrl
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 18 | |
| 7 | |
| 6 | |
| 6 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.