Skip to Content
author's profile photo Former Member
Former Member

Strange problem of Pdf downloading with Web Dynpro

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!

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 01, 2005 at 06:41 AM

    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);

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 01, 2005 at 07:13 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 01, 2005 at 07:06 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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);

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.