File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes Adobe Acrobat gives error to open programmatically generated pdf attachment. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Adobe Acrobat gives error to open programmatically generated pdf attachment." Watch "Adobe Acrobat gives error to open programmatically generated pdf attachment." New topic
Author

Adobe Acrobat gives error to open programmatically generated pdf attachment.

sanskriti agarwal
Greenhorn

Joined: Dec 31, 2007
Posts: 13
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!!


SANSKRITI AGARWAL
[SCJP 1.5 -88%] Software Developer, Global Groupware Software Solutions Ltd., India
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41839
    
  63
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.


Ping & DNS - my free Android networking tools app
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

You might want to show us the remainder of your code.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
sanskriti agarwal
Greenhorn

Joined: Dec 31, 2007
Posts: 13
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
Marshal

Joined: Mar 22, 2005
Posts: 41839
    
  63
You might want to show us the remainder of your code.
sanskriti agarwal
Greenhorn

Joined: Dec 31, 2007
Posts: 13
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());
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adobe Acrobat gives error to open programmatically generated pdf attachment.