Click here to Skip to main content
16,017,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I created the PDF file using the jasper report(ireport tool).I want to display the pdf file content in the jsp page itself.For this i searched in the google and i found that use response.setcontent(application/pdf).If i use this then i am getting the dialog prompt to open or save the file and if i open then it is displaying in the firefox browser.I dont want to open the file in the browser i want to display it in the jsp page itself.I am not getting any idea for this.Its very urgnt for me.I am searching for this from three days.If anyone have any idea can you please give the solution.

Tanks In Advance.


Edit: Additional information form OP-Comment below
Hi i am using the below code to display the pdf file in jsp.But with this it is displaing only the data in the continuous lines.But my pdf file contains images also.I want it to display as it is like when i am displaying using adobe reader.Anything more is required to do this.If any idea can you please tell me....

Java
try
{
   Document document = new Document();
   document.open();
   PdfReader reader = new PdfReader("FilePath");
   PdfDictionary dictionary = reader.getPageN(1);
   PRIndirectReference reference = (PRIndirectReference) dictionary.get(PdfName.CONTENTS);
   PRStream stream = (PRStream) PdfReader.getPdfObject(reference);
   byte[] bytes = PdfReader.getStreamBytes(stream);
   PRTokeniser tokenizer = new PRTokeniser(bytes);
   StringBuffer buffer = new StringBuffer();
   while (tokenizer.nextToken()) {
      if (tokenizer.getTokenType() == PRTokeniser.TK_STRING) {
         buffer.append(tokenizer.getStringValue()+" ");
      }
   }
   String test = buffer.toString();
   out.println(test);
}
catch (Exception e) {
        }
Posted
Updated 13-Apr-12 0:40am
v2
Comments
saru 2 13-Apr-12 3:10am    
Hi i am using the below code to display the pdf file in jsp.But with this it is displaing only the data in the continuous lines.But my pdf file contains images also.I want it to display as it is like when i am displaying using adobe reader.Anything more is required to do this.If any idea can you please tell me....



try {

Document document = new Document();
document.open();
PdfReader reader = new PdfReader("FilePath");
PdfDictionary dictionary = reader.getPageN(1);
PRIndirectReference reference = (PRIndirectReference) dictionary.get(PdfName.CONTENTS);
PRStream stream = (PRStream) PdfReader.getPdfObject(reference);
byte[] bytes = PdfReader.getStreamBytes(stream);
PRTokeniser tokenizer = new PRTokeniser(bytes);
StringBuffer buffer = new StringBuffer();
while (tokenizer.nextToken()) {
if (tokenizer.getTokenType() == PRTokeniser.TK_STRING) {
buffer.append(tokenizer.getStringValue()+" ");
}
}
String test = buffer.toString();
out.println(test);
} catch (Exception e) {
}
Nelek 13-Apr-12 6:41am    
Please, next time you want to add information use the "improve question".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900