File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Create a Pdf file using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Create a Pdf file using Java" Watch "Create a Pdf file using Java" New topic

Create a Pdf file using Java

mahadevan raja
Ranch Hand

Joined: Apr 11, 2001
Posts: 96
hi all,
i had already posted a query regarding how to print the contents,but in vain no reply,
can anybody tell me is there any class so as to create a pdf file and methods used to write into the pdf file.
IOStreams,do create a pdf file,but me not able to open the pdf file.
I saw a PdfWriter class,but not in sun specifications
so anyone plz help me how to create and write to a pdf file.
thanx in advance.

SPECIALIST-WCSV5.1 Implementation.<br />SYSTEMS EXPERT-WAS4.0 Administration
Frank Daly
Ranch Hand

Joined: Mar 31, 2000
Posts: 141
The following article from javaworld might help you.
However you can also generate pdf files using xml, xsl:fo and cocoon which is a servlet available from apache.
Joe Gilvary
Ranch Hand

Joined: May 11, 2001
Posts: 152
Another related option is to use the FOP from
Apache. It is the same code that Cocoon uses
to generate PDF output. But if you do not need
all of the functionality of Cocoon, using just
FOP might be a solution.
There is a release candidate for FOP available
at the apache site,
for download. I have been using it for a project
that really does not require all of Cocoon.
senthil narayan

Joined: Jan 25, 2002
Posts: 13
Instead of using coocon to generate i think the foll is easy.
go to
Tool name is :itext.
It's easy to generate pdf using this tool.
Sergio Glez

Joined: Jan 09, 2002
Posts: 1
Hi! That class that you say (PdfWriter) is a part of a tool called StyleReport.
StyleReport is a reporter tool that can generate PDF, excel or HTML files.
It isn�t part of sun classes. You must by the StileReport in the next link:
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

Also there's gnujpdf (formerly retepPDF) on It mimics the Java printing subsystem. It does OK for lightweight printing requirements, though intense graphics may be beyond it.
BTW There's a pitfall in printing PDF's. If you don't set the Content-length header to the size of the generated PDF, some versions of Netscape won't be able to display it properly.
Unfortunately, since the size of a PDF isn't easy to determine in advance, this has forced me to write the PDF to a temporary file just to get its length, output the HTTP headers, then spool out the temp file to the HTTP output stream.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Create a Pdf file using Java
It's not a secret anymore!