Results 1 to 2 of 2
  1. #1
    akbjavauser is offline Member
    Join Date
    Sep 2009
    Posts
    4
    Rep Power
    0

    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 Attached Files

  2. #2
    saketh is offline Member
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Default

    Hi,
    i had a problem in font setting.
    when i write the code example:
    Font font = new Font(Font.Courier, 10, Font.NORMAL);
    it showing error at "Font.Courier".
    plz tell me the solution.....
    Thank You.........

Similar Threads

  1. iText 2.0.4
    By levent in forum Java Software
    Replies: 2
    Last Post: 06-23-2010, 07:41 AM
  2. Reg : Create new Page in iText
    By Deepa in forum New To Java
    Replies: 0
    Last Post: 08-10-2009, 02:58 PM
  3. Replies: 0
    Last Post: 06-29-2009, 03:40 PM
  4. JAVA: String char removal with nested loop
    By igniteflow in forum New To Java
    Replies: 3
    Last Post: 11-28-2008, 03:09 AM
  5. iText 2.1.0
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 03-29-2008, 02:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •