cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Display two PDF Files in SAP UI5 PDFViewer

g_bessa
Explorer
0 Kudos
804

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;


Accepted Solutions (0)

Answers (1)

Answers (1)

Marian_Zeis
Active Contributor

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