{oapdf_gg}
Office software is closely linked to the PDF,the PDF is also must have to control!      Set home Page  Add to Favorites  
You are here:Home > PDF info > PDF-related reference
PDF-related reference
From Java applications dynamically generate PDF documents
Finishing by: Date:2009-04-14 20:18:43 Popularity: Tags:


Sample application

What to do-it-yourself than to create a working example of a better demonstration of technology? Now, with the necessary tools (Eclipse IDE) and libraries (iText library), can begin to design and develop an example of the application.

Let us create a simple PDF document, which contains some basic elements, such as plain text, non-default font color of text, tables, lists, and other sections and subsections. The purpose of this application is familiar with the iText library allows you to use. There are a lot of PDF documents generated with the help of the class. Can not be introduced in all these categories. iText is the javadoc on how to use these kind of very good information. Let's start writing code.

The first step is to create a document. PDF document is the document all the elements of the container.

1. Instantiated document object

Document document = new Document (PageSize.A4, 50, 50, 50, 50);

The first parameter is the page size. Then the parameters are left, right, and under the margins. But there is no definition of the type of the document. It depends on the writer to create the type. For our example, select the com.lowagie.text.pdf.PdfWriter. Other writer for the HtmlWriter, RtfWriter, XmlWriter and so on. The name of their interpretation of their practical use.

List 2. PdfWriter object created

PdfWriter writer = PdfWriter.getInstance (document, \
new FileOutputStream ( "C: \ \ ITextTest.pdf "));< br/> document.open ();


The first parameter is a reference document object, the second parameter is the actual file name, in the name of the output path will be given. Next, open the document in order to write the content.

now will be the first page of the document to add some text. Through com.lowagie.text.Paragraph to add text. Can be used and the default text font, color, size, etc. The default settings to create a paragraph. Alternatively, you can set up your own fonts. Let us take a look at these two approaches.

List 3.
Object to create paragraphs

document.add (new Paragraph ( "First page of the document ."));< br/> document.add (new Paragraph ( "Some more text on the \
first page with different color and font type. ",
FontFactory.getFont (FontFactory.COURIER, 14, Font.BOLD, new Color (255, 150, 200 ))));
there isArticle InformationsComment Information
Category column

Site Help | Site Map | Feedback |
OAPDF.COM Copyright 2009 V1.1