cancel
Showing results for 
Search instead for 
Did you mean: 

How can I open a PDF File and integrate it on my view?

Former Member
0 Kudos

Hi everybody,

I try to solve the problem like this:

- Creating a context attribute "pdf" type byte

- Creating a view UI Element "MyPdf" type interactive form binding on the context attribute "pdf"

- Inserting the following code in the wddoinit:

IPrivateView.IcontextElement contextEle = wdContext.currentContextElement();

byte bytes = contextEle.getPdf();

try

{

File file = new File("C:/text.pdf");

FileOutputStrem os = new FileOutputStream(file);

os.write(bytes);

os.close();

contextEle.setPdf(bytes);

}

catch (IOException e)

{

e.printStackTrace();

}

I'm running it on a local machine with Netweaver 7.1 and get the following error message:

java.lang.ClassCastException: class java.lang.Byte:null incompatible with interface com.sap.......

If I delete the view UI Element there is no error message. What am I doing wrong???

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I think you have to bind the "dataSource" (and if needed the "pdfSource") properties to context attributes of dictionary type "binary" which corresponds to byte[] in the code.

Armin

Former Member
0 Kudos

Thx Armin for your Reply. This didn't solved the complete problem, but the half so I gave you the full point.

The other reason was that I haven't selected the "usePdf" mode in the properties of the interactive form. Tidy stupid, I know 😄

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi friend,

check with following code i think your file path is not proper that why its not able to create or read file and giving null and null can't b cast in to byte array. and the "\" is a special character (escape sequence ) so it need to be. "//"


File file1=new File(".\\CAF_DOCs\\"
+ wdContext.currentContextElement().getResource().getResourceName());

try and let us know if issue persist further. Hope it will help.

Regards

Jeetendra

Former Member
0 Kudos

Hi,

I'm sorry but it doesn't solve the problem. The error message is the same and it only appears if I have included the interactive form in the view.

If I delete the interactive form, there is no error and it seems that the coding in the wddoinit() Method works.

I've found a simple tutorial that describes my intention. But it works on webDynpro for Abap and uses Function Modules.

http://wiki.sdn.sap.com/wiki/display/WDABAP/ASimpleWebDynproApplicationtodisplayapdffileinthebrowser+window

Anybody know a similar tutorial but for WebDynpro for Java?