You are on page 1of 24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN

GettingStarted Newsletters

Hi,Guest

LogOn

JoinUs

Store

SearchtheCommunity

Products

Services&Support

AboutSCN

Downloads

Industries

Training&Education

Partnership

DeveloperCenter

Activity

LinesofBusiness

UniversityAlliances

Events&Webinars

Innovation

Browse

Communications

Actions

SAPUI5DeveloperCenter

DisplaySmartform(PDF)inSAPUI5
PostedbyChandrashekharMahajaninSAPUI5DeveloperCenteronFeb3,201412:37:43PM
Share

15

Tweet

Like

UPDATE
PleaseseethelastsectionImprovedandRecommendedapproachtoDisplayPDF.

ThisapproachisbasedonSAPGWMediastreamingsolutionandisveryeasytoimplement.
Pleasechangeyoucoding/designaccordingly.

Introduction
ManytimesIsawquestionsonrequirementtodisplaysmartforminSAPUI5.
Belowarefewthreadsonsamerequirement,
Howtocallsmartfrominsapui5?
PrintFormsinSAPUI5
OpenPDFretrievedviaodataserviceinSAPUI5
AdobeformandSAPUI5

Showingpdfinsapui5usingastring.
HenceIthoughttowriteblogonthissubjectandputfocusonstepbystepproceduretodisplaysmartformin
SAPUI5.Iassumethatmanyofuswillbeinterestedtoknowhowtogetthesmartform(pdf)contenton
SAPUI5byexposingthebackenddataintheformofGateway(OData)service.
LetmeexplainallthesedetailsbytakingsimpleexampleofstandardsmartformSF_EXAMPLE_03(Smart
FormsTrainingExample3).OurobjectivewillbetodisplaytheoutputofsmartformSF_EXAMPLE_03in
SAPUI5applicationintheformofPDF.Wewillhavecustomernumberastheinputfieldandwillgettheflight
detailsinvoiceasanPDFoutput.WewilluseiframeascontainertodisplaythePDF.

Procedure

Veryfirst,wewilldevelopfunctionmoduleZ_TEST_PDF_DISPLAYwhichwilltakecustomernumberasinputandwill
exportURLpointingtoPDF.Youcangetthelogicoffunctionmoduleatsapui5
display_smartform_pdf/Z_TEST_PDF_DISPLAYatmasterCmIm/sapui5display_smartform_pdfGitHub

P.S.InsideFM,Iusedthelogicfromthread MimelogonotdisplayingtobuildtemporaryURLforPDF.

NowwewilldevelopGWservicewhichwillhelpustoexposethisdata.Let'screatesimpleGWserviceZTESTPDFas
displayedbelow.

Wewillhaveentityaspdfandentitysetaspdfset.generateruntimeartifactsandthengotogeneratedclass
ZCL_ZTESTPDF_DPC_EXT.NowRedefinemethodPDFSET_GET_ENTITYandputbelowcode.Youcanalsoget

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

1/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN

belowcodeatsapui5display_smartform_pdf/PDFSET_GET_ENTITYatmasterCmIm/sapui5display_smartform_pdf
GitHub
01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
11.
12.
13.
14.
15.

DATA:
lt_keysTYPE/iwbep/t_mgw_tech_pairs,
ls_keyTYPE/iwbep/s_mgw_tech_pair,
lv_customerTYPEs_customer,
lv_urlTYPEstring.
lt_keys=io_tech_request_context>get_keys().
READTABLElt_keysWITHKEYname='CUSTOMER'INTOls_key.
lv_customer=ls_keyvalue.
CALLFUNCTION'Z_TEST_PDF_DISPLAY'
EXPORTING
i_customer=lv_customer
IMPORTING
e_url=lv_url.
er_entitycustomer=lv_customer.
er_entityurl=lv_url.

NowregisteryourGWserviceandThat'sit!WearenowreadytotestourGWservice.Justquerywith
customernumberandyoushouldbeabletogettheoutputashighlightedbelow.

Atthispoint,wearedonewithbackendlogicandGWservicedevelopment.NowwewilldevelopSAPUI5
applicationwhichwillconsumethisservice.
CreateSAPUI5projectandputcodeinindex.html.(followMVCpatternasbestpractice!).Youwillgetsource
codeofindex.htmlatsapui5display_smartform_pdf/index.htmlatmasterCmIm/sapui5
display_smartform_pdfGitHub

EndResult
NowdeployyourapplicationtoSAPABAPserverandruntheapplication.provideanycustomernumber
(checkifdataisavailableintableSCUSTOM)andclickonDisplayPDFbutton.Youwillseebelowresulton
screen.Here,wearedisplayinginvoicedetailsofcustomernumber3intheformofsmartformpdf.

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

2/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN

ClosingRemarks
WiththesimpletechniqueofcreatingtemporaryURLforthePDFandthenexposingthatURLthroughGWservice,
wearebuildingSAPUI5applicationtoconsumeGWservice.Wearethensettingsrcpropertyofaniframewiththis
URLandsettingthiscontenttoHTMLUIelement.

Ihopewiththissimpleway,youcandisplayanybackendsmartforminSAPUI5application!
Iwillrequestyoutoputthecommentonthisblog.Pleasefeelfreetoputyourcomments/suggestionsandany
otherwaytodisplaysmartforminsapui5!

HappyLearningandCoding

ImprovedandRecommendedapproachtoDisplayPDF
[Addedon30thJune2014]
UsingODataMediaindicator,wecaneasilydownloadanyfilesinSAPGateway.Thisisverywellexplained
inthisblog HowToUploadandDownloadFilesUsingSAPNWGatewaySP06by JanThomas
Nygaard
Iwillusesimilarapproachforourcurrentfunctionalityandbelowarethestepsinvolvedintoit.Youneedto
marktheentitytypepdfasMediaenabledasdisplayedinbelowsnap.alsoNeedtotakepropertyMimeType
oftypestring.Thiswillbeusedtosetthemimetypeofthefiletobedownloaded.YoucanreferSupported
MIMETypesABAPWorkbenchToolsSAPLibraryformoreinformation.

NowweneedtoredefineDEFINEMethodofclassZCL_ZTESTPDF_MPC_EXTasbelow,
METHODdefine.

DATA:

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

3/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN
lo_entityTYPEREFTO/iwbep/if_mgw_odata_entity_typ,
lo_propertyTYPEREFTO/iwbep/if_mgw_odata_property.

super>define().

lo_entity=model>get_entity_type(iv_entity_name='pdf').

IFlo_entityISBOUND.
lo_property=lo_entity>get_property(iv_property_name='MimeType').
lo_property>set_as_content_type().
ENDIF.
ENDMETHOD.

GET_STREAMmethodofclassZCL_ZTESTPDF_DPC_EXTasbelow,
METHOD/iwbep/if_mgw_appl_srv_runtime~get_stream.

DATA:
lt_keysTYPE/iwbep/t_mgw_tech_pairs,
ls_keyTYPE/iwbep/s_mgw_tech_pair,
lv_customerTYPEs_customer,
lv_xstringTYPExstring,
ls_streamTYPEty_s_media_resource.

lt_keys=io_tech_request_context>get_keys().

READTABLElt_keysWITHKEYname='CUSTOMER'INTOls_key.

lv_customer=ls_keyvalue.

CALLFUNCTION'Z_TEST_PDF_DISPLAY'
EXPORTING
i_customer=lv_customer
IMPORTING
e_xstring=lv_xstring.

ls_streamvalue=lv_xstring.
ls_streammime_type='application/pdf'.

copy_data_to_ref(EXPORTINGis_data=ls_stream
CHANGINGcr_data=er_stream).

ENDMETHOD.

AsSAPGatewayperformschangingtheXSTRINGcontenttopropermediaformat,weneednottowriteextralogicof
generatingurletcasexplainedinFMlogicsapui5display_smartform_pdf/Z_TEST_PDF_DISPLAYatmaster
CmIm/sapui5display_smartform_pdfGitHub

Insteadofthat,wejustneedtoexporttheXSTRINGcontentfromFM.ImprovedversionofFMlogicisasbelow,
FUNCTIONz_test_pdf_display.
*"
*"*"LocalInterface:
*"IMPORTING
*"REFERENCE(I_CUSTOMER)TYPES_CUSTOMER
*"EXPORTING
*"REFERENCE(E_XSTRING)TYPEXSTRING
*"

*DataDeclaration
DATA:
lv_fm_nameTYPErs38l_fnam,
ls_output_optionsTYPEssfcompop,
lv_languageTYPEtdspras,
ls_control_parametersTYPEssfctrlop,
ls_output_dataTYPEssfcrescl,
lv_pdf_lenTYPEi,
lv_pdf_xstringTYPExstring,
lt_linesTYPETABLEOFtline,
lv_devtypeTYPErspoptype,
lv_app_typeTYPEstring,
lv_guidTYPEguid_32,
lo_cached_responseTYPEREFTOif_http_response,
ls_customerTYPEscustom,
lt_bookingsTYPEty_bookings,

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

4/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN
lt_connectionsTYPEty_connections,
lt_tstotfTYPEtsfotf.

*language
lv_language=sylangu.

TRANSLATElv_languageTOUPPERCASE.
ls_control_parameterslangu=lv_language.

*setcontrolparameterstogettheoutputtextformat(OTF)fromSmartForms
ls_control_parametersno_dialog='X'.
ls_control_parametersgetotf='X'.
ls_control_parameterspreview=space."Nopreview

*getdevicetypefromlanguage
CALLFUNCTION'SSF_GET_DEVICE_TYPE'
EXPORTING
i_language=lv_language
*i_application='SAPDEFAULT'
IMPORTING
e_devtype=lv_devtype
EXCEPTIONS
no_language=1
language_not_installed=2
no_devtype_found=3
system_error=4
OTHERS=5.

*setdevicetypeinoutputoptions
ls_output_optionstdprinter=lv_devtype.
*Setrelevantoutputoptions
ls_output_optionstdnewid='X'."Printparameters,
ls_output_optionstddelete=space."Printparameters

CALLFUNCTION'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname='SF_EXAMPLE_03'"Smartformname
IMPORTING
fm_name=lv_fm_name
EXCEPTIONS
no_form=1
no_function_module=2
OTHERS=3.

*DataretrievalandsupplyingittoSamrtformFM

SELECTSINGLE*FROMscustomINTOls_customerWHEREid=i_customer.
SELECT*FROMsbookINTOTABLElt_bookingsWHEREcustomid=i_customer.
SELECT*FROMspfliINTOTABLElt_connectionsUPTO10ROWS.

*CallSmartformgeneratedFM
CALLFUNCTIONlv_fm_name
EXPORTING
control_parameters=ls_control_parameters
output_options=ls_output_options
user_settings=space
customer=ls_customer
bookings=lt_bookings
connections=lt_connections
IMPORTING
job_output_info=ls_output_data
EXCEPTIONS
formatting_error=1
internal_error=2
send_error=3
user_canceled=4
OTHERS=5.

APPENDLINESOFls_output_dataotfdata[]TOlt_tstotf[].

*ConverttoOTF
CALLFUNCTION'CONVERT_OTF'
EXPORTING
format='PDF'
IMPORTING

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

5/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN
bin_filesize=lv_pdf_len
bin_file=lv_pdf_xstring"binaryfile
TABLES
otf=lt_tstotf
lines=lt_lines
EXCEPTIONS
err_max_linewidth=1
err_format=2
err_conv_not_possible=3
err_bad_otf=4
OTHERS=5.
IFsysubrc=0.
e_xstring=lv_pdf_xstring.
ENDIF.

ENDFUNCTION.

TodownloadthefileinGWClient,weneedtoexecutequeryas/sap/opu/odata/sap/ZTESTPDF_SRV/pdfset('5')/$value
andhenceaccordinglybelowarethechangesneedtobemadeinUI5application,

01. varoButton=newsap.ui.commons.Button({
02. id:'BCreate',
03. text:'DisplayPDF',
04. width:'10em',
05. press:function(){
06. varsRead="/pdfset(customer='"+oTF.getValue()+"')"+"/$value"
07.
08. oModel.read(sRead,null,null,true,function(oData,oResponse){
09. varpdfURL=oResponse.requestUri
10. html.setContent("<iframesrc="+pdfURL+"width='700'height='700'></iframe>")
11. oPanel.addContent(html)
12. oPanel.placeAt("content")
13.
14.
15. },function(){
16. alert("Readfailed")})
17.
18. }
19. })

That'sit.

Pleaseusethisapproachofmediastreamingsolution.Thisisbetterandeasytoimplement.

Categories:SAPUI5,OpenUI5
27520Views
Products:sap_netweaver_gatewayTopics:user_interface_technologyTags:innovation,user_interface,html5,pdf,odata,sapui5,
forms,smartforms,media,sapui5ui5html5javascript,openui5,print_forms,get_stream

AverageUserRating
(19ratings)

Share

15

Tweet

Like

72Comments
MikaelvonKetelhodtFeb3,20141:16PM

Greattutorial,hopefullyitwillassistpeoplewiththisveryquestioninthefuture

Thanksforsharing.

Kindregards
Miki

Like(2)

MartinCookFeb3,20141:41PM

Thanksforthisinformation,wecurrentlyusethesameapproachandIwillbelookingatmovingthisto
aCustomControloverthenextfewweeks,Iwriteablogaboutthisaswellandsharethecode.

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

6/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN

Martin
Like(2)

ChandrashekharMahajanFeb3,20141:48PM(inresponsetoMartinCook)

Sure!Thatwillgr8forallofus...waitingforyourblog
Like(0)

KrishnaKishorKammajeFeb3,20144:51PM

NiceoneChandra.ButIseeoneproblem.WheneverUI5applicationisinGatewayserverand
smartformpdfispointingtothebackendserver,thenwemighthavetomakeuseofreverseproxyto
overcomeSOP.MaybeabetteroptionistogetthepdfasanXSTRING.whatdoyousay?
Like(0)

ChandrashekharMahajanFeb4,20146:31AM(inresponsetoKrishnaKishorKammaje)

YesKrishna,therewillbeSOPissuesforthescenarioyoumentioned.Regardingxstring,I
canalsoexportxstringfrommyGWservicebutIdidnotfoundanysimplewaytoconvert
xstringtoPDFonclientsidei.eUI5application.maybeinthatcasewemayhavetouse
some3rdpartylibrariesetc.Pleaseletusknowincaseyouknowanybetterwaytoconvert
xstringtopdfonclientside.

Regards,
Chandra
Like(0)

JiriNeuzilMar3,201411:26AM(inresponsetoKrishnaKishorKammaje)

Hmm,whenSAPbackendcanconvertxstringtoPDF,whyyoucannotexecutesameFMon
Gatewayandprovidelinktogeneratedpdfongateway?
Like(0)

SyamBabuFeb25,20141:15PM

HiChandra,

GoodWork....IsitpossibletocallInteractiveformsthroughgateway?

Thanks,
Syam
Like(0)

ChandrashekharMahajanFeb26,20145:53AM(inresponsetoSyamBabu)

HiSyam,

inthisblog,IjustsharedprocesstodisplaysmartformPDFandIguesswiththesimilarway,
wecandisplayinteractiveformoutputbutnotsureiffurtherinteractionwiththeformwillbe
possibleinui5context.asofnowIdonothavemuchexperiencewithinteractiveformhence
cannotcommitmoreonit.

Regards,
Chandra
Like(1)

SyamBabuFeb26,20147:49AM(inresponsetoChandrashekharMahajan)

HiChandra,

Thanksforinfo..Haveyoufoundany3rdpartylibfilesforXSTRINGtoPDFon
clientsidei.eUI5.

Thanks,
Syam
Like(0)

ChandrashekharMahajanFeb26,201412:24PM(inresponsetoSyamBabu)

HiSyam,

AsofnowIdidnotfoundany3rdpartylibtoconvertXSTRINGtoPDFon
clientside.IwillsurelyupdatethisblogincaseIgetanygoodsolution.

Regards,
Chandra
Like(0)

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

7/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN
SyamBabuFeb26,20141:22PM(inresponsetoChandrashekhar
Mahajan)

HiChandra,

Thanks..
Like(0)

UdayKumarKanikeMar22,20144:25AM

Niceblog,veryhelpful.ThanksalotandpleasedoshareotherSAPUI5examples.

Thanks
Uday
Like(0)

akshathltApr22,201410:31AM

HiChandar,

Firstofalliwouldlikethankyouforyourwonderfulblog.

IhavecreatedinFM,ServiceinNWGWandUIScreenatSAPUI5withrespecttoyourblog.

Igotbelowresponseformyservice.

CONCATENATE'/sap/public''/'lv_guid'.''PDF'INTOe_url.

Functionmoduleisreturningurllike

URL=/sap/public/46C64CAC93CB1ED3B2BF04D15B23D801.PDF

Ihaveconsumedaboveserviceorurlinmyui5application.

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

8/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN

IgotbelowerrorwhilerunningUI5application.

Canyouhelponthis?Whereidonethemistake?

DoineedtopassPDFconvertedstringtoUI5asodata?

Thanksinadvance.
Akshath
Like(0)

ChandrashekharMahajanApr22,201410:57AM(inresponsetoakshathlt)

ThiserrorrelatedtoCORS.Insteadofrunningitonlocalhost,youcandeployitonABAPAS
andthenrunonit.elseyouneedtosetupproxyasmentionedinblog Howtocreate
SAPUI5applicationconsumingGatewayservicewiththehelpofSAPNWGatewayPlugin
forEclipse

Regards,
Chandra
Like(0)

RoshanJalgaonkarJul10,201410:23AM

HelloChandrashekharMahajan,

Ihadtriedtheabovecode,anditsworkingperfectlyfineondesktop,butwhenIamusingthesame
codeonmobiledevice(androidTablet).Itjustdisplaysblankpage.
Helpisappreciated

ThanksandRegards
RoshanJalgaonkar
Like(0)

ChandrashekharMahajanJul10,201410:45AM(inresponsetoRoshanJalgaonkar)

Hi,

Haveyoutrieditwithget_streamapproachwhichImentionedinthisblog?

Regards,
Chandra
Like(0)

RoshanJalgaonkarJul10,201411:14AM(inresponsetoChandrashekharMahajan)

Hi,

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

9/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN
Ihaveusedfollowingcodetodisplaypdfinsapui5application

vardocURL=undefined
vardocType=undefined
vartemp
varhtml=newsap.ui.core.HTML()
oModel.read(readUrl,undefined,undefined,false,function(oData,oResponse){

docURL=oResponse.requestUri
temp=oResponse.headers
docType=temp["ContentType"]
},function(oError){
errorHandling(oError)
})

if(docType=="application/pdf"||docType=="image/jpeg"){
html.setContent("<iframesrc='"+docURL+"'type='"+docType+"'width='600'
height='700'></iframe>")

}else{
html.setContent("<embedsrc='"+docURL+"'title='attachment'"+
"width='1000px'height='1000px'></embed>")
}

Helpisappreciated

ThanksandRegards
RoshanJalgaonkar
Like(1)

JefersonAmendJul23,20144:34AM(inresponsetoRoshanJalgaonkar)

I'mcurrentlyfacingthesameissue,inDesktopitworksperfectly,butin
thetablet(iPad)itsimplydoesn'twork,itshowsonlythepdfwithout
scrollingbar.ThisseemstobeacommonissuewithiPad(Safari)andI've
alreadytriedsomanydifferentapproachestoreplacetheIFRAME,
withoutsuccess.
Like(0)

HseyinErbekJan27,20163:50PM(inresponsetoJefersonAmend)

HiJefersondidyousolvetheissue?Iamfacingthesame
issuetoo.
Like(0)

MichaelApplebyJan27,20164:13PM(inresponseto
HseyinErbek)

PleasecreateanewDiscussionmarkedasa
Question.TheCommentssectionofaBlog(or
Document)isnottherightvehicleforaskingquestions
astheresultsarenoteasilysearchable.Onceyour
issueissolved,aDiscussionwiththesolution(and
markedwithCorrectAnswer)makestheresultsvisible
toothersexperiencingasimilarproblem.Ifablogor
documentisrelated,putinalink.ReadtheGetting
Starteddocuments(linkatthetopright)includingthe
RulesofEngagement.

NOTE:Gettingthelinkiseasyenoughforboththe
authorandBlog.SimplyMouseOvertheitem,Right
Click,andselectCopyShortcut.Pasteitintoyour
Discussion.Youcanalsoclickontheurlafterpasting.
ClickontheAtoexpandtheoptionsandselectT(on
theright)toAutoTitletheurl.

Thanks,Mike(Moderator)
SAPTechnologyRIG
Like(0)

JefersonAmendJan27,20164:17PM(inresponseto
HseyinErbek)

Hi,I'vecreatedaniframewithintheviewandmanually
resizeit,itwastheonlywaytofixtheissue.Belowthe
codesnippetofonlythepartthatmattersforyou.

functionresize_pdf(){
varheight=window.innerHeight//Firefox
varheaderHeight=51
if(document.body.clientHeight){
height=document.body.clientHeight//IE

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

10/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN
}
//resizetheiframeaccordingtothesizeofthe
//window(alltheseshouldbeonthesameline)
document.getElementById("pdfId").style.height=
parseInt(height
document.getElementById("pdfId").offsetTop
headerHeight)+"px"
}

sap.ui.core.mvc.Controller.extend("PDF.view.Attachment",
{

onInit:function(){

varhtmlId=this.byId("htmlId")

htmlId.setContent("<iframeid=\"pdfId\"src=\"\"
frameborder=\"0\"width=\"100%\"/>")

sap.ui.core.UIComponent.getRouterFor(this).attachRoutePatternMatched(this.handleRoutePatternMatched,
this)
},

handleRoutePatternMatched:function(oEvent){
if(oEvent.getParameter("name")==="Attachment"){
//Everytimeuserresizesthebrowserwindow,adjust
Attachmentsize
window.onresize=resize_pdf
}
},

onAfterRendering:function(){
//FirsttimeloadingAttachmentview(iframewouldn't
bevisiblefromRouteMatchedyet)
$("#pdfId").attr("src",this._sServiceUrl)
resize_pdf()
}

})
Like(0)

PradypParakalaJul10,201411:43AM

Hi

Thanksforsharingsuchausefuldocument,keeppostingmoresuchdocs..

Cheers
Pradyp
Like(0)

MohitSachdevaJul14,20144:48PM

HelloChandrashekhar,

Iamgettingastatuscode500"internalservererror".ThemessagethatIamgettingis
"Method'PDFSET_GET_ENTITY'notimplementedindataproviderclass."

Canyoupleasehelpmewiththesame.IamnewtoABAPsoyourhelpwouldbeappreciated.
Like(0)

SyamBabuJul14,20144:54PM(inresponsetoMohitSachdeva)

HiMohit,

youhaveredefinethePDFSET_GET_ENTITYandimplementthecodesameinthismethod.

Thanks,
Syam
Like(1)

MohitSachdevaJul14,20148:12PM(inresponsetoSyamBabu)

HiSyam,

ThankYouforyourreply.ButIamstillgettinganerror.Iwasactivatingitandit
saysthe"ZCL_YTESTPDF_DPC_EXT,methodPDFSET_GET_ENTITY"has
syntaxerrorsandtheerrorisatline22whichis
"er_entityurl=lv_url.".Ihaveusedthesamecode,butIdon'tknowwhythis
happening.
Like(0)

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

11/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN

SyamBabuJul14,20148:21PM(inresponsetoMohitSachdeva)

HiMohit,

Whatistheerrorgetting?

Thanks,
Syam
Like(1)

MohitSachdevaJul14,20148:45PM(inresponsetoSyamBabu)

HiSyam,

Itjustsayssyntaxerroranditpointsmerow22whichis"
er_entityurl=lv_url."

AlsothereisanothererrorwhichsaysThedataobject
"ER_ENtity"doesnothaveacomponentcalledURL.
Like(0)

SyamBabuJul15,20149:25AM(inresponsetoMohit
Sachdeva)

HelloMohit,

InyourentitytypehavetheURLproperty?..ifitnot
haveyouhavetocreateonepropertywithnameURL.

Thanks,
Syam
Like(0)

MohitSachdevaJul15,20143:52PM(inresponse
toSyamBabu)

HiSyam,

Thanksforyourreply.Ididcreatetheproperty
withnameURL,butitstillgivesmethesame
error.Belowarethescreenshotsofthesame.

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

12/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN

Like(0)

ChandrashekharMahajanJul15,2014
4:09PM(inresponsetoMohitSachdeva)

HiMohit,

Kindlycreatediscussionthreadfor
yourissue.

Regards,
Chandra
Like(0)

VinceTebanoAug1,20143:47PM

WhenIgoeditMETHOD/iwbep/if_mgw_appl_srv_runtime~get_stream.IgettheerrorSystem
settingdoesnotallowchangestobemadetotheobjectCLAS/IWBEP/CL_MGW_ABS_DATA.IfI
can/IWBEPtobemodifiablethesystemthenasksmeadeveloperskeytomodifystandardSAP
code.

Thisdoesnotseemright?Isthereastepmissing?
Like(0)

ChandrashekharMahajanAug4,20149:44AM(inresponsetoVinceTebano)

Hi,

youneedtoredefinethemethodinyourZ*_DPC_EXTclass.

Regards,
Chandra
Like(0)

VinceTebanoAug4,20144:41PM(inresponsetoChandrashekharMahajan)

Thanks,IgottheredefinesinandwastestingthereadbutnowIamgetting:
Method'PDFSET_GET_ENTITY'notimplementedindataproviderclass.Forthe
streamapproachIdidn'tthinkwehadtomodifythis.Doyouknowwhyitisnot
gettinggenerated?
Like(0)

MohitSachdevaAug4,20145:01PM(inresponsetoVinceTebano)

HiVince,

Iwasgettingthesameerrorbefore.

Justmakesureoftwothingthatyouhaveredefinedthemethod
PDFSET_GET_ENTITYcorrectlyandaftermakingchangesyouare
generatingtheruntimeobjects.
Like(0)

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

13/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN
VinceTebanoAug4,20145:22PM(inresponsetoMohitSachdeva)

ThetwothingsthatIsawthatweretoberedefinedwere:
ZCL_ZTESTPDF_MPC_EXT>DEFINE
ZCL_ZTESTPDF_DPC_EXT>GET_STREAM

ThePDFSET_GET_ENTITYwasdescribedasonlytobe
usedintheURLversionofthecode.Ifyouredefinethe
get_entitycodewhatgoesintherebecauseitdoesnot
showanychangestoit.Ifyouleaveitasisandremove
theURLparametertoaddtheMimeTypeyouwillgetan
errorstatingtheURLparameterisnotthere.Also,Inthat
get_entityIwouldnotthinkyouwouldwanttocalltheFM
z_test_pdf_displayagainsinceitgettingcalledinthe
get_stream.
Like(0)

ChandrashekharMahajanAug5,20147:34AM(inresponse
toVinceTebano)

Hello VinceTebanoand MohitSachdeva

forthe2ndapproach,youneednottoredefine
PDFSET_GET_ENTITY.Asmentioned,youjustneed
toredefinemethodDEFINEandGET_STREAM.Also
pleasenotethatFMz_test_pdf_displayis
exportingonlyE_XSTRINGaswedonotrequireURL
parametertobeexported.

andtotestthefunctionality,youneedtoexecuteURI
asbelow,
/sap/opu/odata/sap/ZTESTPDF_SRV/pdfset('5')/$value

$valuewilltriggerGET_ENTITYmethod.

Ihopethisclearsallthedoubts

Regards,
Chandra
Like(0)

VinceTebanoAug5,20143:47PM(inresponseto
ChandrashekharMahajan)

Yesitdoes.
Iwastestingthelink:

/sap/opu/odata/sap/ZTESTPDF_SRV/pdfset('5')
WhichwascallingtheRead
PDFSET_GET_ENTITY(whichwasnot
defined).
Afterchangingthelinkto:

/sap/opu/odata/sap/ZTESTPDF_SRV/pdfset('5')
ItishittingtheGET_STREAMthatwas
redefined.

Makesperfectsensenow.

Thanksforhelp,
Vinnie
Like(0)

PawanKalyanJun7,20164:42AM(inresponsetoChandrashekharMahajan)

HiChandrashekhar,

Documentisverygood..ButiamabletoseemyPDF.

IamnotgettinganyerrorbutiamnotabletoseePDFContent,Iamseeingonly
IFRAME.

ForIframeSRC,ihaveusedXSTRINGanduploadeditinservercachejustlike
youmentionedintheabovetutorial.

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

14/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN

WhymyPDFContentisnotgettingDisplayed.Pleasetellme..Iaminserious
needofsomeassistance.
Like(0)

AbhishekGoelAug25,20142:31PM

HiChandrashekhar,

Thisisaveryinformativeblog,thankyouverymuchforsharingthis.

ThoughIamworkingonaverydifferentrequirementwhereIamgeneratingSalarySlipsof
employeesanddisplayingtheminPDFformatinaUI5application.IamfetchingdetailsofSalaryfor
theemployeeusingastandardRFContheSAPend.ThisRFCreturnstherequireddatainXString
format.

NowmyrequirementistoconvertthisXStringintoPDFformat.Ihavetwoalternativewithme:

1.IpassthisXStringasisthroughtheODataserviceandhandleitinmyUI5applicationand
convertthisintoaPDFformatanddisplaythesame.TheissueisthatIhavenotbeenableto
figureoutasolutiononhowtohandleXStringintheUI5appandconvertitintoPDFformat.
2.TheotheroptionisthatIconvertthisintoPDFformatwithinmywrapperRFContheSAPend
andstorethisPDFintocachememory,thengenerateaURLforthisfile,passittotheUI5
applicationandcallthisURLfromtheapptodisplaythePDFinaniFrame.HereIamfacing
seriousissueswiththeconversionofXStringintoPDFformatandthegeneratedPDFisina
verydistortedformat,hencenotacceptable.

RequestyoutopleasehelpmewithyourinputsonthiscriticalissuesoIcanfindafeasiblesolution
onthesame.Pleaseletmeknowincasethereisanyfurtherinformationyouwouldrequirefromme
tohelpyouunderstandmyissuebetter.

Thanks,
AbhishekGoel.
Like(0)

ChandrashekharMahajanAug25,20143:00PM(inresponsetoAbhishekGoel)

HiAbhishek,

for2ndoption,UseGET_STREAMmethodapproachasexplainedintheblog.Checkwith
thatandletmeknowifyoustillfaceanyissue.

Regards,
Chandra
Like(0)

AbhishekGoelAug25,20143:06PM(inresponsetoChandrashekharMahajan)

Ireallyappreciateyourpromptresponse.

Ihavetriedfollowingasyourbloghasdirected,butIthinktheGET_STREAM
methodonlydiscussesconversionofaSmartFormintoPDFandsendingthatPDF
throughgatewaytotheUI5application.Please,kindlycorrectmeifIamwrongin
myunderstanding.

ButinmyscenarioIdonothaveanySmartFormatallandjustgettingasingle
XStringasoutputfromthatRFC.SoIamnotsurehowtoconvertthatXStringinto
PDFandsenditthroughtheservice.

Thanks,
Abhishek.
Like(0)

ArshadAnsaryOct4,20146:26PM

HiChandrasekhar,

Excellentblogandnicewaytoreturnbackthedatainxstringmannerviaget_streammethod.

Howcanweusethesame$valuelinkinURLforGET_ENTITYSETcase..

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

15/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN

InthebelowURL,itisnotcallingtheGET_STREAMmethod

/sap/opu/odata/sap/ZGW_ARS_EMP_SRV/EmployeeSet?$filtereqEmployeeIDeq'000004'/$value

IfthisissupportedthentheURLcanhavefilter,sorted,$selectvaluesalso..

OnemoredoubtiswhatrelevancedoesthebelowhaveinMPC

IFlo_entityISBOUND.
lo_property=lo_entity>get_property(iv_property_name='MimeType').
lo_property>set_as_content_type().
ENDIF.
Youarenowhereusingthispropertyforstreamvalueassignment

Regards
Arshad
Like(0)

DhananjayChoubeyNov6,20148:44AM

HiChandrashekhar,

It'sanicedocumentandithelpedmealot.Ijustfollowedyourstepsandeverythingwasworkingwell.
Iamdoingitinlocalhost.
Igotthiserror.

Ihavealsoopenedasdndiscussion.
Simpleexampleforgatewayandodatacommunication

Thanksinadvance
Dhananjay
Like(0)

StefanFedeacNov18,20144:20PM

HelloChandrashekhar,
Thankyouforthishelpfuldocument.
Ifollowedthestepsyoudescribedintheimprovedandrecommendedapproachandeverythingwas
workingjustfineuntilthelaststepwhenIcouldnotseethepdfdocument.
Itdisplaysonlytheframe,butnocontent.
ItestedtheserviceusingtheRESTClientandIgetthepdf,soIdon'tthinkthattheserviceisthe
problem.
ImustmentionthatIcreatedanAndroidapplication,soIwaswonderingifthereareanymodifications
thatmustbeperformedonthesourcecodeoftheSAPUI5applicationinordertoseethePDFon
Android.
Also,IwanttomentionthatIamusingtheservicethroughGatewayandnotlocally.

Thanksinadvance,
Stefan

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

16/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN

Like(0)

DhananjayChoubeyNov20,20146:57AM(inresponsetoStefanFedeac)

oncecheckbyincreasingyourcachetime.
****SettheCacheTimeout60
secondsweonlyneedthisinthe
cache
****longenoughtobuildthepage
lo_cached_response
>server_cache_expire_rel(
expires_rel=60).
Like(0)

KarthikAJan23,20158:50AM(inresponsetoStefanFedeac)

HiStefan,

RefThis: http://scn.sap.com/community/developercenter/front
end/blog/2015/01/23/disablehttpssecuritycertificateinmobiletabletandroidandios

1.DownloadPDFfromServicetoLocalFilebyusingwindow.preferenceconcepts
2.thenusefileopenerplugintoopendownloadedfilefromyourlocaldevice

Hopethiswillwork.

Thanks,
KarthikA
Like(0)

KarthikAJan6,201512:55PM

Hi,

IamfacingsomeproblemtodisplaypdfinAndroidapplication.
Hereweusediframe,objecttags.Butnouse

Cananyonepleasegiveyourideatoviewpdfinandroidapplication.

Note:Samecode(iframetag)workingfineindesktop.butinmobile/tabletitisnotworking.

(IamusingSAPGatewayservice)

Thanks,
KarthikA
Like(0)

karthikjalapallyJul20,201511:09AM(inresponsetoKarthikA)

HiKarthik,

DidyouabletosolvetheproblemKindlyHelpme.

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

17/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN
Like(0)

KarthikAJul20,201511:33AM(inresponsetokarthikjalapally)

Hikarthik,

Isolvedthisissue...

RefThis: http://scn.sap.com/community/developercenter/front
end/blog/2015/01/23/disablehttpssecuritycertificateinmobiletabletandroid
andios

1.DownloadPDFfromServicetoLocalFilebyusingwindow.preferenceconcepts
2.thenusefileopenerplugintoopendownloadedfilefromyourlocaldevice

Followthislink...

Itisworking...

Thanks,
KarthikA
Like(0)

RavikiranRJan21,20156:22AM

HiThankyoufortheexcellentandveryusefularticle

Canweusethisforexcelfiledownloadalso

Inthefunctionmoduleificonverttheexceltoxstring
andinthegatewayifichangethels_streammime_type='application/pdf'toapplication/msexcel

Willthiswork?

Thanksalot
Like(0)

ChandrashekharMahajanJan21,201512:23PM(inresponsetoRavikiranR)

yesyoucandownloadexcelfileaswell.checkthisblog Displayingbackenddataboth
asSAPUI5TableandanExcelFilebutsticktoimprovedapproachofusingmediasteaming.

Regards,
Chandra
Like(0)

RavikiranRJan22,20156:35AM(inresponsetoChandrashekharMahajan)

ThankyouMahajan,wewillbetryingittoday.

Regards,
Ravikiran
Like(0)

TFdoFeb3,20157:37PM

ThankyouverymuchChandrashekhar..VeryNiceandInformative...
Like(0)

JatenSangalFeb17,20159:42AM

HiChandrashekhar,

IhavereferredyourblogasIamalsohavingsamekindofrequirement,butfacinganissue.Could
youpleasecheckthebelowpostedthreadandgiveyourvaluableinputonthat.
openthesmartformasaPDFinUI5

Regards,
JatenSangal
Like(0)

VishnuPankajakshanApr9,20154:05PM

HiChandra,

Inmylandscapeitscentralhubdeployment...sohowwillthecachedurlwillbeuseful.

formetheerroris:

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

18/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN

Regards,
Vishnu
Like(0)

VishnuPankajakshanApr10,20159:10AM(inresponsetoVishnuPankajakshan)

IinternallychangedthehostnameofGWwithERP.Nowitsworking...

Regards,
Vishnu
Like(0)

ChandrashekharMahajanApr10,201510:02AM(inresponsetoVishnuPankajakshan)

yesyoufiguredouttheissuecorrectlyasthetemp.urlisgettinggeneratedinthe
backendsystemandhencethatwillnotworkonGWserver.othersolutioncould
betoexportxstringfromthebackendfromyourFMfore.g.FM
z_test_pdf_display
andthenusethelogicofgeneratingthetemp.urlonGWhubsystemsothatitwill
usehostnameofHubsystem.

Butinsteadofdoingallthis,pleaseusetheimprovedapproachofusingmedia
stream(get_stream)methodtodisplayPDF.

Regards,
Chandra
Like(1)

karthikjalapallyJul20,201511:07AM

HiChandrashekharMahajan,

Thanksforyourblog.Itworkedprettywell.I'mabletoviewthePDFiniOSbutnotinandroid.

andtheurl

http:<server>:<domain>/sap/....../Employee('xyz')/$value
isdownloadingthepdfautomaticallybutnotembeddinginsidetheiframeasyousuggested.

Kindlyhelp

KarthikJ
Like(0)

DeepakSharmaAug19,20158:21PM

HiKarhik,

Haveyoufoundsolutionforembeddinginsteadofdownloadingpdf.Inourcasepdfwasopeningas
embeddedtillweupgradedUI5&Gateway.AfterupgradetoGatewaySP11andUI51.28,pdfis
downloadinginsteadofopeningasembedded.

Thanks
Deepak
Like(0)

JefersonAmendAug19,20158:49PM(inresponsetoDeepakSharma)

IhadthatissueafterupgradingGWaswell,andthesolutionforthisisthatGWis
settingtheHTTPheaderdifferently,soifyoudon'tsetityourselfitwilldownload

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

19/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN
insteadofdisplayit.
InyourGET_STREAMmethod:
DATA:ls_headerTYPEihttpnvp.
ls_headername='ContentDisposition'.
ls_headervalue=|inlinefilename="{lv_filename}"|.
set_header(is_header=ls_header).
Hopeithelps
Like(1)

DeepakSharmaAug19,20158:59PM(inresponsetoJefersonAmend)

ThanksJeferson.

Solvedbysettingheaderassuggested.
Like(0)

DhananjayChoubeyOct21,20158:21AM(inresponsetoJefersonAmend)

Canyoupleasetellmewhatislv_filenameherefromthecode?Thanks.
Like(0)

billyshenSep25,20155:11AM

HiChandrashekhar,
ifollowedtheImprovedandRecommendedapproachtodisplaypaf,itokwith
Firefoxandgatewayclient,butnotokonChrome,Safiri.onChromethepdfdidn'tgenerateinthe
Z_TEST_PDF_DISPLAY,whenitCALLFUNCTIONlv_fm_name,thels_output_dataisempty.On
Firefoxithasdata.notsurewhy.doyouhaveanyideas?whatshoulddowithhttpheaderorcache
response,itriedlotsofcodes,stillnotworking.

thanks,
Billy

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

20/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN

Like(0)

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

21/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN
SudheerSomisettyOct10,20152:16PM

HiChandrasekhar,
Excellentblogandwelldocumented.WefollowedsameapproachtodisplaythePDFin
UI5usingSmartForm.Wearegetting404errorwhenweuseyourfirstapproach(generatingURLin
ECC)insteadStreamone.Firsttimeitis404errorandifIrefreshafter8secondslaterweareableto
seethepdf.IfIrefreshitisnotdiplayingandgetting404.Theissueisintermittent.Couldyou
pleasehelptoresolvetheissue.Thankyou.

WithRegards
Sudheer.
Like(0)

MichaelApplebyOct12,20152:44PM(inresponsetoSudheerSomisetty)

PleasecreateanewDiscussionmarkedasaQuestion.Commentstoablogisnottheright
vehicleforaskingquestionsastheresultsarenoteasilysearchable.Onceyourissueis
solved,aDiscussionwithmaketheresultsmuchmorevisibletoothersexperiencinga
similarproblem.

Thanks,Mike(Moderator)
SAPTechnologyRIG
Like(0)

CHIRAGMAKWANAOct18,20152:51PM

GreatTutorial, ChandrashekharMahajansir
completelyfollowyourblogand,achievedsuccessoverthat.
IhaveissueonnamingconventionwhiledownloadingPDFthroughbrowser,

EverytimeIclickthelinkinbrowser,itsgenerate'Entity.pdf',
howcanispecifyuniquenametothatgeneratingPDFwithusingODataServices.
>>/sap/opu/odata/sap/ZTESTPDF_SRV/pdfset('501')/$value
workingwell,but
thislinkshowmeentity.pdfasadownloadedfile.
howcanweconvertnameentity.pdfto501.pdfwithODataservices
pleasehelpmeonthis..

Thanks,ChiragMakwana.
Like(0)

ChandrashekharMahajanOct30,20158:55AM

HiSatyaki,

PleasecreateanewDiscussionmarkedasaQuestion.Commentstoablogisnottherightvehicle
foraskingquestionsastheresultsarenoteasilysearchable.Onceyourissueissolved,aDiscussion
withmaketheresultsmuchmorevisibletoothersexperiencingasimilarproblem.

Thanks,
Chandra(Moderator)
Like(0)

DeepakSharmaDec1,20157:10PM

UsingiFramesrc="pdflocation"isactuallymakingmultiplecallstoSAPgateway.Iguessonecallis
bymodel.readandanotherifbyiFrametoactuallydisplaythepdfcontent.

YoucanplacesessiondebuggerinDPCclass&youcanseethatitishit2times.

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

22/24

7/2/2016

DisplaySmartform(PDF)inSAPUI5|SCN

Isthereawaytoavoidmaking2calls?

Screenshotfrombrowsermakingmultiplecallsisattached.

Thanks
Deepak
Like(0)

ArunShanmugampillaiFeb4,20163:18PM

HiChandrasekhar,
Iamtryingtousethesmartforminmyappandiamusingthereadfunctionjustlikeyousuggested,
butforsomereasonigeta"NoHandlerfordata"error.Ialsomadeapostwhereyoucanseeallthe
thingsthatItried.Thespecifieditemwasnotfound.

MaybeyoucantellmewhatIdidwrong.Ihopeyoucanhelpme,

Kindregards,

Arun
Like(0)

ElieHMar21,20164:38PM(inresponsetoArunShanmugampillai)

HiArum,

Ifaceonthesameissue.

Didyousolveit?

Bestregards,

Elie
Like(0)

Amber.Feb12,20169:56PM

HiChandreshekar,
VeryInformativeblogbutIhaveasmallquestion.Evenifwedon'tdeclareMIMEtypeaspropertyin
theentity"pdf"andaccordinglycommentthelineforsettingitascontenttype,itwillstillwork,right??
Sincetheget_streammethodwillreturnMIMEobject,whatistheneedtohavemimeproperty
definedinourentityPDFaswearenotusingpdf_get_entityatall

JusthadtheabovequestioninmindsinceItriedremovingtheabovepartasImentionedanditstill
works(alsosamethingwithMIMEimages)
Like(0)

SiddharthShahApr13,20163:53PM

Hi Chandrashekhar,

ThanksforexplainingandsharingcodetodisplaysmartformusingODataandconsumeitinSAPUI5.
IamabletoconsumesmartforminmySAPUI5application.

WhenIexecutedtheSAPUI5application,IobservedthatODataserviceisbeingcalledthreetimes.I
guessonewhen"oModel.Read"isbeingcalled,secondwheniframeisbeingloadedandthirdtime
maybewhencontentisbeingloaded.

Isthereanywaytorestricttheservicecalltosinglecall?

Onceagain,thankyousomuchforthisblog

Regards,
Sid
Like(0)

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

23/24

7/2/2016
SiteIndex
Privacy

DisplaySmartform(PDF)inSAPUI5|SCN
ContactUs
TermsofUse

SAPHelpPortal
LegalDisclosure

Copyright

http://scn.sap.com/community/developercenter/frontend/blog/2014/02/03/displaysmartformpdfinsapui5

FollowSCN

24/24

You might also like