Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-08-2010, 04:35 AM
Member
 
Join Date: Sep 2009
Posts: 4
Rep Power: 0
akbjavauser is on a distinguished road
Default Itext with java : PDF nested table issues.. Please help
I have created PDF with nested tables,it has two two rows and second row has two cols.For some reason page is breaking intwo multiple pages with blank page. Below example is working..... please see the output.I am not understanding why first page is displaying as BLANK.


Please help me .. i could not able to attach pdf file.

I used : IText.2-1-7.jar


package com.ak.pdf;

import java.awt.Color;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;

import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

/**
* @author me
*
*/
public class TestPDF {


/**
*
*/
public void generatePDFTable(){

try {
OutputStream file = new FileOutputStream(new File("D:\\anil\\Test.pdf"));



Document document = new Document();

PdfWriter.getInstance(document, file);
document.open();

SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Font fonts = FontFactory.getFont(FontFactory.COURIER, 10,
Font.NORMAL);
Font boldFont = FontFactory.getFont(FontFactory.COURIER, 10,
Font.BOLD);

PdfPTable table = new PdfPTable(2);
table.setWidthPercentage(85f);


PdfPCell cell;

cell = new PdfPCell(new Paragraph("ABC Company MS"));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBorderColor(Color.GREEN);
cell.setColspan(2);

table.addCell(cell);

PdfPTable nestedTable = new PdfPTable(1);
PdfPTable nestedTable1 = new PdfPTable(1);


cell = new PdfPCell(new Paragraph("\nREB OFFER\n", boldFont));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
// cell.setBorder(0);
nestedTable.addCell(cell);
cell = new PdfPCell(new Paragraph("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
fonts));
cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIE D);
// cell.setBorder(0);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("Rebate Amount: $"
+ "bbbbbbbbbbbbbbbbbbb", fonts));
cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIE D);
// cell.setBorder(0);
// nestedTable.addCell(cell);
String dots = "....................";

cell = new PdfPCell(new Paragraph("\nREBATE FORM\n", boldFont));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
// cell.setBorder(0);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("\nName: " + dots, fonts));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// cell.setBorder(0);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("\nAddress:" + dots, fonts));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// cell.setBorder(0);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("\nCity: " + dots, fonts));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// cell.setBorder(0);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("\nState: " + dots, fonts));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// cell.setBorder(0);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("\nZip: " + dots, fonts));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// cell.setBorder(0);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("\nEmail: " + dots, fonts));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("\nStart Date: "
+ "01/02/2010", fonts));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// cell.setBorder(0);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("End Date: "
+ "01/02/2010", fonts));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// cell.setBorder(0);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("Postmark Date: "
+ "01/02/2010", fonts));
cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIE D);
// cell.setBorder(0);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("Received By Date: "
+ "01/02/2010", fonts));
cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIE D);
// cell.setBorder(0);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("\nRED REQUIREMENTS\n",
boldFont));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//cell.setBorder(0);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("ccccccccccccccccccccccccccccc" +
"ccccccccccccccccccccccccccccccccccccccccccccc c" +
"ccccccccccccccccccccccccccccccccccccccccccccccccc ccccc" +
"ccccccccccccccccccccccccccccccccccccccccccccccccc " +
"cccccccccccccccccccccccccccccccccccccdf" +
"gggggggggggggggggggggggggggggggjfdshfgggggggg " +
"ggggggggggggggggggggggggggggggggggggggg" +
"ggggggggggggggggggggggggggggggggggggggggggggggggg " +
"ggggggggggggggggggggggggggggggggggggggggggggggggg g" +
"ggggggggggggggggggggggggggggggggggggggggggggggggg gg" +
"ggggggggggggggggggggggggggggggggggggggggggggggggg gggggg" +
"ggggggggggggggggggggggggggggggggggggggggggggggggg ggggggg" +
"ggggggggggggggggggggggggggggggggggggggggggggggggg gggggggggg" +
"ggggggggggggggggggggggggggggggggggggggggggggggggg gggggggg" +
"ggggggggggggggggggggggggggggggggggggggggggggggggg ggggggggggg" +
"ggggggggggggggggggggggggggggggggggggjshfsdfkggdfg d" +
"gdfgdnfgkmdnfgndsfg" +
"dfgdfsgbjdgkldflgd" +
"gdfgbjdflkjffffffffffffffffffffff" +
"ggggggggggggggggggggggggg" +
"ggggggggggggggggggggggggggggggggggggggggggggggggg ggggggggggggg" +
"fffffffffffffffffffffffffffffffffffffffffffffffff fffffffffffffff" +
"fffffffffffffffffffffffffffffffffffffffffffffffff fffffff" +
"f_______________________________________________f ff" +
"_________________________________________________ _dsfsdfs" +
"fdfffffffffffffffffffffffffffffffffffffffffffffff fffffffffffff" +
"ffffffffffffffffffffffffffffffff fffffffffffffffffffffffffff" +
" fdgd" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"fffffffffffffffffffffffffffffffffffffffffffffffff fffffffffff" +
"fffffffffffffffffffffffffffffffffffffffffffffffff ffffffEND",
fonts));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//cell.setBorder(0);
//cell.setBackgroundColor(new Color(0xFF, 0x00, 0x00));
//nestedTable.getDefaultCell().setRowspan(1);

nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("\nCHECK REBATE STATUS:", fonts));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// cell.setBorder(0);
// nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("\nCHECK REBATE STATUS:"
+ "hdfhsfjsdffsfsdf" + "\n" + "efrewkfljsdlkfnsdf"
+ "\n" + "9013403019", fonts));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// cell.setBorder(0);
nestedTable.addCell(cell);

cell = new PdfPCell(new Paragraph("\nMail All Required Materials:"
+ "hhhhhhhhhhhh" + "\n"
+ "ggggggggggggggg" + "\n"
+ "vcvvvvvvvvvvvvvvvvv" + ","
+ "rrrrrrrrrrrrrrrrr" + " "
+ "mmmmmmmmmmmmmmmmmmmmmmm", fonts));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// cell.setBorder(0);

nestedTable.addCell(cell);

table.addCell(nestedTable);

cell = new PdfPCell(new Paragraph("REB RULES:", boldFont));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//cell.setBorder(0);
cell.setBorder(Rectangle.TOP);
nestedTable1.addCell(cell);
cell = new PdfPCell(new Paragraph("efjjdnffffffffffff" +
"fgdfgsfdg" +
"gdfgdfsgggggggggggggggggggggggg" +
"gdfgggggggggggggggggggggggggg" +
"fdgggggggggggggggggg" +
"fdgdfggggggggggggggggggggggggggggg" +
"ggggggggggggggggggggggggggggggg" +
"ggggggggggggggggggggggggggggg" +
"gggggggggggggggggggggggggggggggffffffffffffff ff" +
""
+ "\n\nRebate sponsored by " + "CARDONE"
+ "products", fonts));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorder(0);

nestedTable1.addCell(cell);

table.addCell(nestedTable1);



document.add(table);

System.out.println("Done");

document.close();
file.close();
}catch(Exception e){
e.printStackTrace();
}

}



/**
* @param args
*/
public static void main(String[] args) {
TestPDF obj = new TestPDF();

obj.generatePDFTable();

}

}
Attached Files:
File Type: pdf Test.pdf (2.7 KB, 0 views)
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
iText 2.0.4 levent Java Announcements 1 01-25-2010 12:22 PM
Reg : Create new Page in iText Deepa New To Java 0 08-10-2009 02:58 PM
How to merge two XFA formatted PDFs using iText and java ? dhanu8055 Advanced Java 0 06-29-2009 03:40 PM
JAVA: String char removal with nested loop igniteflow New To Java 3 11-28-2008 03:09 AM
iText 2.1.0 Java Tip Java Announcements 0 03-29-2008 02:05 PM


All times are GMT +2. The time now is 08:33 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org