Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

PDF created with iText can't be opened  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone, some help please
i wanted to create pdf with Itext , everything works well until i've made the runnable jar . Adobe reader shows that message : "Adobe Reader could not open xxx.pdf because it is either not a supported file type or because the file has been damaged. and the file generated 0 ko here is some of my code :




 
Saloon Keeper
Posts: 5475
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post compilable code so we can try ourselves. That includes the import statements and everything else in the class. Which iText version are you using?
 
abir hmida
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your answer
the code is very long that's why i just post some of it.
i use itext version 5.1.0
 
Tim Moores
Saloon Keeper
Posts: 5475
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you should create an SSCCE (<-- that's a link) for it. If we can't reproduce the issue, there's little chance of it being addressed.

Reducing the code to the bare minimum needed to reproduce the issue may even help you find the issue.
 
abir hmida
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i didn't understand how to send it
 
Tim Moores
Saloon Keeper
Posts: 5475
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just post it with CODE tags, like you did in the first post.
 
abir hmida
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Master Rancher
Posts: 4072
47
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's probably too much for anyone to step through and, as it isn't an SSCCE, i's not something we could attempt to debug.

There's database connections in there as well.

So, I suggest you stick debug statements in there to see what values you are getting through that method.
That might help you see what is being added to your document and whether or not it is being saved.

ETA:  Actually, thinking about it, I'd take out most of that code and add bits in slowly, seeing whether the document saves properly.
For starters, skip the database bits and just try and get some dummy paragraph saved.
 
Marshal
Posts: 24458
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If that code produces a PDF file with zero bytes, that must mean that the code which generates the PDF and writes it to the file is not executed. Or at least the "doc.close()" is not executed.

That strongly suggests to me that an exception has been thrown somewhere. You may think that printing the name of the exception to sysout would tell you that, but since the code you are running is Swing code, you don't get to see sysout.

I also notice that your code uses relative paths to access files. It is possible that when you run the executable jar file, your current working directory is not the same as it was in Netbeans. That will also be a problem.
 
abir hmida
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Paul Clapham
when i am on netbeans , every thing is going well , the pdf is created and i can print it.
but when i make the runnable jar the pdf is created but his size is 0ko and can't be opened
 
Tim Moores
Saloon Keeper
Posts: 5475
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried using absolute paths instead of relative paths, as Paul suggested?

Have you tried capturing any exceptions, maybe by showing them in a dialog? See http://www.java2s.com/Tutorial/Java/0240__Swing/CreateaMessageDialogBox.htm for an example.
 
Dave Tolls
Master Rancher
Posts: 4072
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you running the jar file?
If it's double clicking then try running it from the command line instead, that will show up the println call in that catch block.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!