Professional Documents
Culture Documents
In this tutorial, we will see the pdf generation using java programming and also how the
content which is available on website can be exported to pdf file.
According to Wikipedia, PDF is a file format used to represent documents in a manner
independent of application software, hardware, and operating systems. Each PDF file
encapsulates a complete description of a fixed-layout flat document, including the text,
fonts, graphics, and other information needed to display it. You can see more in this link
PDF is the heart of every reporting technique that is being followed by every website or big
organizations. The important part is to know how to create PDF files in java and how the
content which is available on online version of the website can be exported to pdf file. Let
us first learn how to create the pdf at the time when the database is triggered. This is being
done making use of java programming.
There are lots of open source library that lets you play with the pdf files in java. We can use
the same for java. Compile the same that can be implemented from the command line. Let
us see below the example where we had used java to generate a portrait which is then
being saved as a pdf.
We will now create a simple pdf document. The document comprises of the elements such
as plain text, coloured ones that lists table, list, lesson etc. lots of classes are present that
holds the potential to do lot amount of work as far as pdf generation is concerned.
Initiation of the document object is shown below
Let us learn and understand the meaning of the above line where in the first function
defines the size of the page followed by margins of the left, right, top and bottom. There is
a need to define the type of this document which basically is dependent on the sort of
writer that needs to be created. Here in we will be making use of the pdfwriter object.
Listing 3: Using pdfwriter object
Pdf writer = PdfWriter.getInstance(file, new FileOutput("C:\\Test.pdf"));
document.open();
Now here we have first function as the document object reference. The second one is the
file name where in we will write the output. The final step will be to make sure that the
document is open for the purpose of writing.
Let us now add some content on the documents first page and then the default paragraph
can be created. This can be done with the help of settings of font, color, size etc. All these
attributes are set by default though we can also set and choose the same of our own.
The below listing describes about the scaleAbsolute where in then the image object is being
incorporated to the section.
Now we have no more elements that need to be added to lesson1. We will now go ahead
and add lesson 1 to our main document and then will close the same when we will be
through with our demo application.
Read more:
http://mrbool.com/how-to-create-and-export-pdf-files-in-java/27343#ixzz3bLT9coo2