Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adobe Acrobat gives error to open programmatically generated pdf attachment.

 
sanskriti agarwal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using iText1.3.jar and writing following code in my servlet . It opens a download dialog box and later in Adobe Acrobat when i try to open this file it gives error that - file is an attachment and corrupt and cant be open.


response.setHeader("Content-Disposition","attachment;filename=c:\\Report.pdf;");
response.setHeader("Content-Type","application/pdf");
Document doc = new Document();
PdfWriter docWriter = PdfWriter.getInstance(doc, response.getOutputStream());
doc.open();
doc.add(new Paragraph("Report 1"));

What is being left to let open this file in Adobe Acrobat ? Please Help!!
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's probably not the problem, but leave out the "c:\\" from the filename; you can't specify a directory anyway.

You could also try a current version of iText; 1.3 has been obsolete for years.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11914
207
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to show us the remainder of your code.
 
sanskriti agarwal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its again generating same error

"Adobe could not open 'Report.pdf' because either it is not a supported file type or because the file has been damaged (for example it was sent as an email attachment and wasnt correctly decoded)"

I also use 'inline' in place of 'attachment' but same the file is creating but could not be opened.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to show us the remainder of your code.
 
sanskriti agarwal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The whole code is as follows (in Servlet) :-

try
{
response.setHeader("Content-Disposition","attachment;filename=c:\\Report.pdf;");
response.setHeader("Content-Type","application/pdf");
Document doc = new Document();
PdfWriter docWriter = PdfWriter.getInstance(doc, response.getOutputStream());
doc.open();
doc.add(new Paragraph("Report 1"));
document.close();
}
catch (Exception e2)
{
System.out.println(e2.getMessage());
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic