5

My goal is either to detect the presence of PDF object (or) validate the PDF/stream if the PDF is displayed/failed to load.

Tried different solutions available/suggested but nothing worked. Would highly appreciate for any suggestions to achieve any of these(detect the presence of PDF object (or) validate the PDF/stream if the PDF is displayed/failed to load.)

Here is the sample code i'm using to display the PDF on my page.

In displaying JSP:

<Object id= "main_content" type="application/pdf" frameborder= "0" scrolling="auto" marginheight= "1" align="top" height = "197px" WIDTH="100%" data="sample.jsp"  standby="Loading document...">Oops, you have no pdf viewer enabled.</Object>

In processing JSP:

String pdfData ="some data in base64 encoded stream"
byte[] byteArr = pdfData.getBytes(); 
byteArr = Base64.decodeBase64(byteArr);
response.reset();
response.setContentType("application/pdf"); 
response.setHeader("Content-disposition", "inline; filename=\"sample.pdf\""); 
OutputStream output = response.getOutputStream();
output.write(byteArr);
output.close();

1 Answers1

0

This isn't the sort of thing you can tell from jsp itself, as jsp is only there to get data from one place to another, you'd need something clientside to have the client tell you if it worked or not, if something like this does exist, it's probably javascript.

A quick google showed me this which looks promising, i would give that a shot.

Community
  • 1
  • 1
Zachary Craig
  • 2,192
  • 4
  • 23
  • 34