Neha Gujarathi

Greenhorn
+ Follow
since Jul 23, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Neha Gujarathi

hey... I did close the FileOutputStream... It did not help...
And the pdf getting generated on the server is valid..
14 years ago
JSP
Hey..Thanks for the reply... Its JSP...

And about the data in the file...Sorry forgot to add post code

here is the whole code

Document pdfDocument = new Document();
File file=new File("neha.pdf");
FileOutputStream fos = new FileOutputStream( file );
PdfWriter writer = null;
writer = PdfWriter.getInstance(pdfDocument, fos);
writer.open();
pdfDocument.open();
pdfDocument.addTitle("A sample PDF Title");
pdfDocument.addAuthor("Neha");
pdfDocument.add(new Paragraph("This is a sample PDF document "));
pdfDocument.add(new Paragraph("This is second Paragraph"));
writer.flush();
pdfDocument.close();
writer.close();

response.reset();
response.setHeader("Expires", "0");
response.setHeader("Cache-Control","cache");
response.setHeader("Pragma", "cache");
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment;filename=neha.pdf");

ServletOutputStream so = response.getOutputStream();

ByteArrayOutputStream output = new ByteArrayOutputStream();
InputStream in = new BufferedInputStream(new FileInputStream("neha.pdf"));
byte bytebuff[] = new byte[500];

for(int lengthread = 0; (lengthread = in.read(bytebuff)) != -1;){
output.write(bytebuff, 0, lengthread);
}

byte data[] = output.toByteArray();
response.setContentLength(data.length);
so.write(data);
in.close();
so.close();

Thanks a ton
14 years ago
JSP
Hi,

I am trying to open a pdf file in IE. But the problem is that it opens up a blank pdf page... When I download the pdf, its size is not 0 and it does contain the pdf author name,and title but its empty..

The code snippet

response.reset();
response.setHeader("Expires", "0");
response.setHeader("Cache-Control","cache");
response.setHeader("Pragma", "cache");
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment;filename=neha.pdf");

ServletOutputStream so = response.getOutputStream();

ByteArrayOutputStream output = new ByteArrayOutputStream();
InputStream in = new BufferedInputStream(new FileInputStream("neha.pdf"));
byte bytebuff[] = new byte[500];

for(int lengthread = 0; (lengthread = in.read(bytebuff)) != -1;){
output.write(bytebuff, 0, lengthread);
}

byte data[] = output.toByteArray();
response.setContentLength(data.length);
so.write(data);
in.close();
so.close();

Thanks a lot,

Neha
14 years ago
JSP