Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

pdf file

  Asked By: Harley    Date: Oct 14    Category: Java    Views: 881

i want to create one pdf file and write something to it by servlet. i write this code:

DataOutputStream dos = new DataOutputStream(new FileOutputStream("c:\\file.pdf"));
dos.write("This is a test of the FileWriter class.\n");

and i also exam this code:
FileWriter fw = new FileWriter("c:\\test.pdf");
fw.write("This is a test of the FileWriter class.\n");
and also printwriter and printstream. file properly create but when i want to open file i encounter with one error that say this file is cottupt and ....



6 Answers Found

Answer #1    Answered By: Rochelle Elliott     Answered On: Oct 14

There are many libraries to manipulate pdf  using java, just google "java pdf libraries" or queries like this to see a plenty of them.

Answer #2    Answered By: Silvia Chapman     Answered On: Oct 14

you must use some tools like "itext" for generating PDF files.

Answer #3    Answered By: Ty Thompson     Answered On: Oct 14

with this code  you can create file  with pdf  extension but you dont follow of PDF structure.you must use pdf libraries for read and write  PDF files. you can find some libraries in following links:

Answer #4    Answered By: Grady Stewart     Answered On: Oct 14

I think you should use a free java-pdf library like (iText) to create pdf  files.

Answer #5    Answered By: Brendan Smith     Answered On: Oct 14

You can't write  into a pdf  directly!!! you have to use an API in order to create  a pdf file
use iText to create pdf files

Answer #6    Answered By: Faiza Mian     Answered On: Oct 14

does anybody know what pdf  library can read pdf file  completely(in java)?

Didn't find what you were looking for? Find more on pdf file Or get search suggestion and latest updates.