cancel
Showing results for 
Search instead for 
Did you mean: 

Opening a PDF File from WebDynpro

MVar
Explorer
0 Kudos

Hello Everyone,

I have a Webdynpro project and need to create a link on one of the views to display a .PDF document.

1. Where should I store the PDF document within the webdynpro project?

2. How do I open the PDF file?

I've created a link with action on the view and just need to know how to open it.

Thanks in advance for your help.

Mike

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Mike,

if your PDF is part of your component (i.e. it should be deployed along with the component) placing the file manually on the server is not very convenient - you may put the file in mimes folder of the WDpro Component.

Check details here:

Then all you need to do:

IWDWebResource resource = WDWebResource.getWebResource( wdComponentAPI.getDeployableObjectPart(), WDWebResourceType.PDF, "Test.pdf");

String externalURL = resource.getAbsoluteURL();

You may associate reference to this externalURL to the LinkToURL element.

The information about parsing "component-local" xml could be applied together with RK's advice to create downloadable PDF indirectly.

Best regards,

Nick

MVar
Explorer
0 Kudos

Nick,

Your solution solved my problem!

Thank you very much for your help!

Best regards,

Mike

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Mike,

You can try one of the following methods:

Method 1:

-


1. Create a context attribute (say pdfsource) of type binary.

2. Create a file download control

3. Attach this attribute to the data property of file download control.

4. In the init method of the view or in some other method store the content of the pdf in the context attribute. And do the following code

IWDAttributeInfo attInfo = wdContext.currentContextElement().node().getNodeInfo().getAttribute("pdfSource");

ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) type;

binaryType.setFileName("Test.pdf");

binaryType.setMimeType(WDWebResourceType.PDF);

5. Now on click of File Download link, it will ask for "Open", "Save", or "Cancel" dialog box. You can choose open to open as a pdf document.

-


Method 2:

-


1. Write an action on click of the button or so.

2. In that action get the contents and store it in an byte array and open the pdf file directly as follows.

byte[] PDFbytes = <source string>.getBytes();

if(PDFbytes!= null) { IWDCachedWebResource pdffile= WDWebResource.getPublicCachedWebResource( PDFbytes , WDWebResourceType.PDF, WDScopeType.CLIENTSESSION_SCOPE, wdThis.wdGetAPI().getComponent().getDeployableObjectPart(),

"Some Title"); wdComponentAPI.getWindowManager().createNonModalExternalWindow(pdffile.getURL(), "Some PDF").open();

-


Thanks and regards

RK

Former Member
0 Kudos

Hi,

You have to put it in the server .If you have the document in test folder in c drive

then go to

\usr\sap\<instance name>\JC<instance number>\j2ee\admin\go.bat

open visual admin

go to services->http provider

select the tab alias

give a name say testword and define the path as c:/test/<name of the document>.doc

save properties

write the code below in the action associated with the link

IWDWindow newwindow = wdComponentAPI.getWindowManager().createExternalWindow("http://cgnlpt041:50000/testword","<title of window>",false);

newwindow.open();

deploy the project

it will open in a new window

Regards

Rohit

Hope this helps you

MVar
Explorer
0 Kudos

Hello Rohit,

Where on the server do I put the file? Can I include the file in the directory structure of the webdynpro project and get it from there?

thanks,

Mike

Former Member
0 Kudos

Hi,

You just have to put the pdf in a physical location in server and specify the path in defining alias

Regards

Rohit