PDF Generation in Java
4 posters
Page 1 of 1
PDF Generation in Java
PDF version of this tutorial is available HERE
Do you want to print something as a pdf in your java application? if, this text is for you. Its prety simple.
First you need download a jar. download it from here.
its 4.09MB in size.
now you need to configure it in your eclipse IDE. I use eclise. so no idea about others how to
configure. I hope you the other IDE users, know the best.
follow the steps-
1. Create a new java project in Eclipse named "Pdf Converter"
2. Right click on the Pdf Converter project in the package explorer view and select build path then
select Add libraries. there will pop up a box name add libraries. Select User library, press on the button at right top
side named "user library"
3. Click on New. Give a name of iText library and then Click ok.
4. now click on Add Jars button and browse the iText.jar in the directory.
5. Click OK.
Now you can use the classes of iText. The com.lowagie.text.Document is the main class for PDF document generation. First we need to instantiate it. Then we will write on it using the com.lowagie.text.pdf.PdfWriter class.
now lets see a example that print hello world as a pdf.
Do you want to print something as a pdf in your java application? if, this text is for you. Its prety simple.
First you need download a jar. download it from here.
its 4.09MB in size.
now you need to configure it in your eclipse IDE. I use eclise. so no idea about others how to
configure. I hope you the other IDE users, know the best.
follow the steps-
1. Create a new java project in Eclipse named "Pdf Converter"
2. Right click on the Pdf Converter project in the package explorer view and select build path then
select Add libraries. there will pop up a box name add libraries. Select User library, press on the button at right top
side named "user library"
3. Click on New. Give a name of iText library and then Click ok.
4. now click on Add Jars button and browse the iText.jar in the directory.
5. Click OK.
Now you can use the classes of iText. The com.lowagie.text.Document is the main class for PDF document generation. First we need to instantiate it. Then we will write on it using the com.lowagie.text.pdf.PdfWriter class.
now lets see a example that print hello world as a pdf.
- Code:
package iTextImpl;
import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class HelloWorld {
private static String text = "This is a simple tutorial on how to print your text"
+ "as a pdf.\n To print as pdf format you need to configure iText library.\n"
+ "This is a open source library.\n\n\n\n\n";
public static void main(String[] args) {
// document object created that describe the document attributes
// like page size, margin etc
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try {
// PdfWriter.getInstance() creates a PDF document writer that writes
// PDF syntax to concerned file by a FileOutputStream.
PdfWriter.getInstance(document, new FileOutputStream("hello.pdf"));
document.open();
document.addTitle("simple test pdf");
document.add(new Paragraph(text, FontFactory.getFont(
FontFactory.HELVETICA_OBLIQUE, 14, Font.NORMAL, new Color(
0, 150, 200))));
// create a chunk object using chunk class of itext library.
Chunk chunk = new Chunk("This is a simple pdf file created by: ");
// set the distance between text and line.
chunk.setTextRise(10.0f);
chunk.setUnderline(new Color(10, 160, 10), 0, (float) 0.2, 3, 0,
PdfContentByte.LINE_CAP_PROJECTING_SQUARE);
document.add(chunk);
document.add(new Paragraph("Bazlur Rahman", FontFactory.getFont(
FontFactory.COURIER, 16, Font.BOLD,
new Color(100, 150, 100))));
document.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}
}
Last edited by bit0112-rokon on Wed Aug 04, 2010 6:19 pm; edited 1 time in total
Re: PDF Generation in Java
I was in need of this...
tui ei post ta na dile toke call kortam eita janar jonno. call korte hoilo na..
BIT0107-Toma- Programmer
- Course(s) :
- BIT
Blood Group : B+
Posts : 280
Points : 453
Re: PDF Generation in Java
Hey I've written an api with this itext. All about this will be available here
Re: PDF Generation in Java
Well from what I've found out, if you are looking for a document generation system on Java, take a look at this Java document generation site. It has basic info on all the vendors. It makes for a great starting point.
andrewb- Pre-Alpha Release
- Posts : 1
Points : 1
Similar topics
» Java Tutorial: Using Two Java Reference Keywords, this and super
» Java EE vs .Net???
» Java 7
» About Java 3D
» Array in Java
» Java EE vs .Net???
» Java 7
» About Java 3D
» Array in Java
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Sep 29, 2015 2:45 pm by Sophiawood
» Cisco EHWIC SFP/GE WAN Card
Mon Sep 07, 2015 11:08 am by Sophiawood
» Huawei S1700-28GFR-4P-AC Price
Thu Jun 25, 2015 2:31 pm by Sophiawood
» teach yourself C++ / Herbert Schildt Solutions
Wed Jun 03, 2015 1:52 pm by Abdullah Al Noman
» teach yourself c by herbert schildt pdf
Wed May 13, 2015 11:01 pm by Raquib Ridwan
» ASA 5506X With Firepower ASA5506-K9
Fri Apr 10, 2015 4:31 pm by Sophiawood
» New Trends in Deal Business
Tue Feb 03, 2015 9:38 pm by nersoa
» PoE Power Allocation for WS-C2960S-24PS-L
Wed Nov 05, 2014 11:12 am by Sophiawood
» How to cure back pain
Fri Oct 31, 2014 7:15 pm by Bergen Guildford