on 07-05-2008 5:14 AM
Hello All,
I created a webdynpro application that opens a pdf document using the code described in the following link.
I am getting the following error:
"There was an error opening this document. The file is damaged and could not be repaired"
But I am able to open the same file using another ASP application.
Am I missing anything?
Thanks in advance.
Nikhil,
I tried increasing the byte size but I am still getting the same error.
May be the code where I am reading the bytes from blob :
Blob pdfBlob = resultSet.getBlob(COLUMNNAME)
byte[] pdf = new byte[pdfBlob.length];
pdf = pdfBlob.getBytes(1,(int)pdfblob.length());
is not working. Should I read the bytes on by one using a while loop? If so how? (I am reading this from the database)
Naga - Thanks for the response. I am reading this pdf data from a database ( stored as a blob).
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nikhil,
I tried and I am getting the following error while opening the PDF document:
"The file is damaged and could not be repaired"
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
did you try what i suggested? I think in dynpro whole binary is not cached.
Please try changing the byte[] size to blob size and reply me what error you are getting.
nikhil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nikhil and Vinod,
Thanks for your help. There is nothing wrong with the PDF, I can open the same file using an ASP application without any problems. The only difference I observed between the ASP application and the webdynpro application is that, in the ASP application, the pdf file is opening directly in the browser while in the webdynpro application it is opening in Adobe. Would this make any difference?
Thanks again for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nikhil and Vinod,
Thanks for your response. I used this code but it is not working. I am still getting the same error.
In my application, I am not reading the pdf from a file. Instead, it is stored in the database as a blob. I am reading the data using the following code:
Blob pdfBlob = resultSet.getBlob(COLUMNNAME)
byte[] pdf = new byte[1024]
pdf = pdfBlob.getBytes(1,(int)blob.length());
I am storing this value in a context and then displaying it as a pdf. I am using the following code to get bytes
byte[] pdfBytes = wdContext.currentElement().getBLOB(); (BLOB - name of the context attribute where bytes are stored)
and using the following code to open the pdf document (as suggested)
IWDResource pdfResource = WDResourceFactory.createResource(pdfBytes,"test.pdf",WDWebResourceType.PDF);
* *
* wdComponentAPI.getWindowManager().createNonModalExternalWindow(pdfResource.getUrl(0),"test.pdf").show();*
Am I missing anything here?
How can I force the pdf document to open in a browser window instead of Adobe?
Thanks in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try this code
Blob pdfBlob = resultSet.getBlob(COLUMNNAME)
byte[] pdf = new byte[pdfBlob.length];
pdf = pdfBlob.getBytes(1,(int)blob.length());
once you get byte[] you can pretty well go for constructing a cached web resource from it thus opening in browser.
refer the code below
resource = WDResourceFactory.createCachedResource(pdf,"Name",WDWebResourceType.PDF);
IWDWindow window = wdComponentAPI.getWindowManager().createNonModalExternalWindow(resource.getUrl(0),
"Name");
window.show();
nikhil
Shilaja,
This will open the PDF file in server in to your browser application.
Specify the location of the file in Path.
try{
InputStream stream = new FileInputStream(Path);
IWDResource resource = resource = WDResourceFactory.createResource( stream, "test.pdf", WDWebResourceType.pdf, true);
stream.close();
wdComponentAPI.getWindowManager().createNonModalExternalWindow( resource.getUrl( 0), "test.pdf").show();
}catch( Exception e){ e.printStackTrace();}
Modify the code as follows to read file
FileInputStream in = new FileInputStream(new File(resourcePath));
ByteArrayOutputStream out = new ByteArrayOutputStream();
int len;
byte[] bytes = new byte[1024];
while ((len = in.read( bytes)) != -1)
{
out.write(bytes, 0, len);
}
in.close();
regards
Vinod
Edited by: Vinod V on Jul 5, 2008 10:50 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try giving more length to byte array like
byte[] part = new byte[30 * 1024];
nikhil
Edited by: Nikhil ßos on Jul 5, 2008 11:09 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
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.