If you post your code, and the exact error message you are getting, and someone will help point you in the right direction in terms of finding your error. (When posting your code, please be sure to place it in UBB [code] [/code] tags. It makes reading the code much easier. Take a look here to learn how to use UBB if you are not familiar.)
If you just want sample code to compare to, there is plenty of sample on the web. Start with the Sun Java Tutorial and www.javaalmanac.com. If those don't suit your needs, do a Google search and you'll find tons of examples.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com