PDF CREATION IN JAVA
USING ITEXT JAR:
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class Pdfcreation
{
public static void
main(String[] args) throws FileNotFoundException
{
Document
document = new Document();
try
{
PdfWriter
writer = PdfWriter.getInstance(document, new
FileOutputStream("D:\\HelloWorld.pdf"));
document.open();
document.add(new Paragraph("OM GANAPATHAYAE NAMAHA..."));
document.add(new Paragraph("OM GANAPATHAYAE NAMAHA..."));
document.close();
writer.close();
}
catch
(DocumentException e)
{
e.printStackTrace();
}
}
}
SIMPLE PDF BILL GENERATION IN JAVA:-
public void calc() throws IOException,
ClassNotFoundException, SQLException, DocumentException
{
Date d=new Date();
String
line="***************************************************";
DateFormat
dateFormat = new SimpleDateFormat("HH-mm-ss");
filename=dateFormat.format(d);
Document
document = new Document();
PdfWriter
writer = PdfWriter.getInstance(document, new
FileOutputStream(filename+".pdf"));
document.open();
document.add(new Paragraph("BILL TIME:- "+d.toString()));
document.add(new Paragraph("BILL NO:- "+max));
document.add(new Paragraph(line));
document.add(new Paragraph("HOTEL MANAGEMENT SYSTEM"));
document.add(new Paragraph("**your food destination**"));
document.add(new Paragraph(line));
document.add(new Paragraph("FOOD
QTY RATE TOTAL-AMT"));
document.add(new Paragraph(line));
for (String
l11 : l1)
{
Statement
stm=new DataBase_Connection().ConnectionGet().createStatement();
ResultSet
rs = stm.executeQuery("select * from fooditems where fid='" + l11 +
"'");
while(rs.next())
{
document.open();
fcost=rs.getString("cost");
fname=rs.getString("fname");
String
qty=m1.get(l11);
String
tota=tot.get(l11);
String
cont=fname+"___"+qty+"___"+tota+"___"+fcost;
document.add(new Paragraph(cont));
//str.add(cont);
}
}
document.add(new Paragraph(line));
document.add(new Paragraph("GRAND TOTAL:.."+grand));
document.add(new Paragraph(line));
document.add(new Paragraph("THANK YOU!
VISIT AGAIN.."));
document.close();
writer.close();
String
gran=Double.toString(grand);
dout.writeUTF(gran);
}
----------------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment