Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
pdf chapter 
 

In this section, you will read about pdf chapter as well as its example.

 

pdf chapter

                         

As we all have seen a pdf file, in the pdf file there are too many chapter. Do you want to make them by your own. In this program we are going to tell you how you can make different chapters in pdf file irrespective of the fact whether it exists or not.

To make a program over this, firstly we need to import some packages. Remember to make this program the first and foremost thing to remember is to place the iText.jar in WEB-INF/lib of your web application. The packages we were talking about are java.io.* for input output, com.lowagie.text.pdf.*, and com.lowagie.text.*. These two package will help us to make and use pdf file in our program.

Now create a file named chapterPDF. Remember the name of the file should be such that the reader can understand what the program is going to perform. Inside the class declare a main method inside which we are going to write the logic of our program.

Firstly make a object of class Document. The Document describes a document's page size, margins, and other important attributes. It works as a container for a document's chapters, sections, images, paragraphs, and other content. 

Now create a document writer that writes the equivalent syntax for a document's content to a specific OutputStream. PdfWriter.getInstance() creates a PDF document writer that writes PDF syntax to concerned file by a FileOutputStream. If the pdf file doesn't exist then it will create a pdf file by that name.

Now open the document by document.open(). Make a Paragraph object and inside the constructor of the Paragraph pass a String. Now make a Chapter and inside the constructor of Chapter pass a paragraph object that houses a paragraph of text, tells the PDF document writer to ensure that the Paragraph's text is justified on both sides. Add the Chapter object to the previously created Document. At last closes the document by using the document.close(). The closing of the document is important because it flushes and closes the OutputStream instance. 

 

The code of the program is given below:

import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.awt.*;
public class chapterPDF{
public static void main(String arg[])throws Exception{
Document document=new Document();
PdfWriter.getInstance(document,new FileOutputStream("chapterPDF.pdf"));
document.open();
Paragraph paragraph=new Paragraph("Rose-Java");
Paragraph paragraph1=new Paragraph("Rose-Java1");
Paragraph paragraph2=new Paragraph("Rose-Java2");
Paragraph paragraph3=new Paragraph("Rose-Java3");
Paragraph paragraph4=new Paragraph("Rose-Java4");
Paragraph paragraph5=new Paragraph("Rose-Java5");
Chapter chapter=new Chapter(paragraph,0);
Chapter chapter1=new Chapter(paragraph1,1);
Chapter chapter2=new Chapter(paragraph2,2);
Chapter chapter3=new Chapter(paragraph3,3);
Chapter chapter4=new Chapter(paragraph4,4);
Chapter chapter5=new Chapter(paragraph5,5);
document.add(chapter);
document.add(chapter1);
document.add(chapter2);
document.add(chapter3);
document.add(chapter4);             
document.add(chapter5);
document.close();
}
}

The output of the program is given below:

Download this program.

                         

» View all related tutorials
Related Tags: c web pdf file stl text application import jar diff io make packages port this package itext app if tex

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

some examples about java in chapter file input out put stream

Posted by alaa on Sunday, 04.8.07 @ 14:16pm | #13582

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.