on 05-19-2011 12:44 PM
Hi,
I am trying to download pdf from a LinkToaction UI element.
I recieve %pdf" error when trying to download using below code. from backend perspective ABAPer said they are able to download PDF from ABAP program. Lokks like I am doing some mistake somewhere in below code.
From the backend, pdf is coming in a table in the form of SOLI-Text Line (TLine - SO_TEXT255)
In webdynpro I am tried to take each line from that table and attched to a IWDResource as below.
Please correct me if anything wrong here to get out of %pdf" error.
IModel_Pdf_FileNode Model = wdContext.nodeModel_Pdf_File();
IPDFElement pdf = wdContext.nodePDF().currentPDFElement();
if (Model != null && Model.size() > 0)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
try {
for (int i = 0; i < Model.size(); i++){
IModel_Pdf_FileElement Element =
Model.getModel_Pdf_FileElementAt(i);
baos.write(Element.getLine().getBytes());
}
IWDResource resource =WDResourceFactory.createCachedResource(
baos.toByteArray(),
"Test",
WDWebResourceType.PDF);
pdf.setBinaryResource(resource);
Thanks
Praveen
Hi Praveen,
Can you try this code sample...to get the Byte Array o/p
IContent content = resource.getContent();
InputStream in = content.getInputStream();
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();
My application is working fine with this.
Hope it helps,
Sattam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the sample. I use version NWDS7.0 and I don't find IContent type in my NWDS after re-organizing import statements.
currently I use below code to get the PDF on click of LinkToaction UI element (After I set the pdf from backend above part of the code).
{code
IWDResource pdfResource = wdContext.nodePDF().currentPDFElement().getBinaryResource();
String pdfURL = pdfResource.getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal());
IWDWindow window =
wdComponentAPI.getWindowManager()
.createNonModalExternalWindow(pdfURL , "Test");
window.show();
{code}
Currently above code giving %pdf" error when clicking LTU UI elemnt.
Please suggest How I need to adjust your sample in my case.
Thanks
Praveen
Hi Praveen,
Sorry for late reply.
Actually it was my fault.... you need to add a few jars, i forgot to mention them in my previous posts. Following is the list
-webdynpro_services.jar
bc.rf.framework_api.jar
bc.sf.framework_api.jar
bc.util.public_api.jar
com.sap.security..api.ep5.jar
com.sap.security..api.jar
prtapi.jar
ps- actually my application involved uploading and downloading from km. So i am not sure which ones are really needed, I gave you all.
Even if this does not work try adding the referance PORTAL:sap.com/com.sap.km.application under Sharing references under web dynpro references.
Pls let me kno in case u face any issues.
Regards,
Sattam
Hi Praveen,
In my application the file is being downloaded from a KM folder, not a FM.
I just provided the part of code where i obtained the output byte array from the resource.
I already knew the path to the resource in KM folder hirearchy.
Regards,
Sattam
Edited by: Sattam Kumar Datta on May 20, 2011 8:17 AM
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.