Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

pdf tables

                         

In this program we are going to tell you how we can make a table in a pdf file irrespective of the fact whether it exists or not. If it exists then its fine, otherwise a pdf file will be created. 

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 tablePDF. 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 object of PdfPTable class. It will create a table with 2 rows and 2 columns as we have passed 2 inside the constructor of a PdfPTable. After that add the content to the table. Now add the table to the Document object. 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.*;
public class tablePDF{
    public static void main(String arg[])throws Exception{
       Document document=new Document();
       PdfWriter.getInstance(document,new FileOutputStream("tablePDF.pdf"));
       document.open();
       PdfPTable table=new PdfPTable(2);
       table.addCell("Name");
       table.addCell("Place");
       table.addCell("RoseIndia");
       table.addCell("Delhi");
       document.add(table);
       document.close()
   }
}

The output of the program is given below:

Download this example.

                         

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 
Latest Searches:
Scrum
insert data to text fi
standard deviation arr
connect to sql databas
insert content to text
calender class
swap arrays in java
Photoshop Text Effects
java excel
decimal to unicode
string Compareing
how to get system scre
java write file line b
Area and circumference
\n java
jboss connection pool
how to print arraylist
Display name of system
struts.jar download
login code example in
velocity rules engine
netbeans jsp
ensureCapacity of vect
tattoo efectes
compression of a file
rmi
standered jstl jar to
count the number of di
create xls using POI
Java Count words,reve
java.sql.Date
Quartz Tutorial
Date in JSP
Java show Vowels in th
code for Write a small
struts language swit
tibco
tabindex
setvisible tab
Socket tcp
Display name of system
what are the syntax in
Sentence case
set cell value JTable
jQuery To Hide the Div
conversion of decimal
seam tutorial
codebar
Retrieving Data From d
disable Jframe
apache derby embedded
richfaces a4j taglibr
constructor
selectOneRadio
java string
à¹?à¸?à¸?à¹???à¹?à¸?à¸
loading combo values f
bidirectional
space char
new language insert an
sql timestamp examples
/n java
download icefaces appl
checkbox button enable
calculate mode in Java
<logic:iterate>
extract title from htm
passing value from ser
A�������
Struts Dispatch Action
increase size of strut
qMgr.accessQueue(
tree and treenode (Aja
Tutorial:FlashBasicPas
AOP Example Spring
how to check the char
disabale Jframe
Photoshop Basics Add F
What are the defined J
convert date to number
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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 | 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.