cancel
Showing results for 
Search instead for 
Did you mean: 

Strange problem of Pdf downloading with Web Dynpro

Former Member
0 Kudos

Hi, experts, I have to setup a project to realize pdf downloading with web dynpro. But unluckily, I have tried all the methods in this froum ,there's really strange problem .Because when I click the link of Download UI link, there's no reaction at all, I really don't know why.Below is the codes I used , can anyone help me ? thank you very much!

public void wdDoInit()

{

//@@begin wdDoInit()

IWDAttributeInfo attInfo =

wdContext

.currentContextElement()

.node()

.getNodeInfo()

.getAttribute(

"Pdfsource");

ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) type;

binaryType.setFileName("test.pdf");

binaryType.setMimeType(WDWebResourceType.PDF);

try {

int length =

(int) wdContext.currentPdfdownloadElement().getBin_Filesize();

byte b[] = new byte[length];

b = wdContext.currentPdfdownloadElement().getBin_File();

wdContext.currentContextElement().setPdfsource(b);

} catch (Exception ex) {

}

"Pdfsource" is the context value attribute of type binary.And Bin_File is the xstring type parameter from my RFC contains pdf content.

I used two views and one customer-controller . I put some value in the first view to set search condition.and the second then appears and have the download UI element. Are there any additional codes I should use? pls help!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Hao,

Try this out

Suppose the file name is test.doc in c drive in server

create a context attribute filedata of binary type

bind it to data property

write the following code

try

{

File input = new File("C:
test.doc");

int length =(int)input.length();

//Create a byte array b to hold the file

byte b[] = new byte[length];

FileInputStream in = new FileInputStream(input);

//Reading the file to a byte array b

in.read(b);

in.close();

//Setting the data from the byte array to the context element.

wdContext.currentContextElement().setfiledata(b);

}

catch(Exception ex)

{

wdComponentAPI.getMessageManager().reportSuccess("Error in File

IO"+ex.toString());

}

// Structure information of the context attribute

IWDAttributeInfo attinfo = wdContext.getNodeInfo().getAttribute("filedata");

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attinfo.getModifiableSimpleType();

// Default File name which appears when opened on client machine

binaryType.setFileName("testing.doc");

//Explicitly setting the file type

binaryType.setMimeType(WDWebResourceType.DOC);

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Hao,

try this piece of code.......

//@@begin wdDoInit()

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

ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) type;

binaryType.setFileName("yourfile.pdf");

binaryType.setMimeType(WDWebResourceType.PDF);

String fileName = "temp
webdynpro
web
local
.......";(file-path)

try

{

File file = new File(fileName);

FileInputStream in = new FileInputStream(file);

ByteArrayOutputStream out = new ByteArrayOutputStream();

int length;

byte[] part = new byte [10 * 1024];

while ((length = in.read(part)) != -1)

{

out.write(part, 0, length);

}

in.close();

wdContext.currentContextElement().setPdfSource_download(out.toByteArray());

}

catch(Exception e)

{

throw new WDRuntimeException(e);

}

//@@end

Former Member
0 Kudos

Hi, Deep,

I'm really sorry your answer did't resolve my problem . I had said that I know this, but it does't help, I even use ByteArrayInputStream to reget my Bin_File, but useless. anyway, thank for your help.

Can anyone who had made simliar job help me ?

Former Member
0 Kudos

Can anyone help me? Really urgent. I was doing this project after reading other experts' post that I should make a xstring type pdfcontent return from RFC then I can download. I implemented exactly and I can see in R/3, but why I can't make it in web??

Former Member
0 Kudos

waiting online

Former Member
0 Kudos

Hi,Rohit

Thank you for your answer. But my problem is not that, I know how to download, But because now I want to download the Bin_File (xstring type) returned by a RFC,I have tested in R/3, it returns binary as Bin_File, but somehow I can't download by web dynpro, I think maybe it's dynamic download that generate this problem ,But I have tried all the methods in the froum , neither helps. I really got headache with this for 3 days:(

Can anyone check my code ? thanks in advance

Former Member
0 Kudos

By the way, Pdfdownload is my download view's module node, and can I use my code below to get the xstring pdfcontent and set it to the datasource of Download UI?

try {

// int length =

// (int) wdContext.currentPdfdownloadElement().getBin_Filesize();

// byte b[] = new byte[length];

// b = wdContext.currentPdfdownloadElement().getBin_File();

//

// wdContext.currentContextElement().setPdfsource(b);