Example usage for com.lowagie.text.pdf PdfPTable setLockedWidth

List of usage examples for com.lowagie.text.pdf PdfPTable setLockedWidth

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable setLockedWidth.

Prototype

public void setLockedWidth(boolean lockedWidth) 

Source Link

Document

Uses the value in setTotalWidth() in Document.add().

Usage

From source file:storemanagment.Printing.java

public final void TransactionReceived(String transactionReceiptNo, String officer,
        ArrayList<ReceivedCart> items, String total_cash, String[] otherDetails) {
    Calendar c = Calendar.getInstance();
    Date today = c.getTime();/*  w  w w.  j ava  2  s  .co m*/

    java.util.Date d = (today);

    java.sql.Date DATE = new java.sql.Date(d.getTime());

    // String OrgDetails=res[1]+"\n"+DATE.toString();
    String orgDetails[] = getRes();
    String orgImg = orgDetails[0];
    String orgAbout = orgDetails[1];

    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File(","));
    chooser.setDialogTitle("Save at");
    chooser.setApproveButtonText("save");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        try {

            Document pdfp = new Document();
            PdfWriter writer = PdfWriter.getInstance(pdfp, new FileOutputStream(
                    new File(chooser.getSelectedFile(), transactionReceiptNo + "" + DATE + ".pdf")));

            // PdfWriter writer = PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),"Group "+jComboBoxGroup.getSelectedItem().toString()+".pdf")));
            HeaderFooterPageEvent event = new HeaderFooterPageEvent(officer, transactionReceiptNo, DATE);
            writer.setPageEvent(event);
            pdfp.open();

            //        Document pdfp=new Document();
            //            PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),transactionReceiptNo+""+DATE+".pdf")));
            //                pdfp.open();
            PdfPTable header1 = new PdfPTable(1);

            //                //  tbl.setWidthPercentage(100);
            //                
            header1.setTotalWidth(575);
            header1.setLockedWidth(true);
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            PdfPTable header = new PdfPTable(3);

            //                //  tbl.setWidthPercentage(100);
            //                
            header.setTotalWidth(575);
            header.setLockedWidth(true);

            header.setWidths(new int[] { 1, 4, 1 });

            //THE FIRST ROW
            //first column ///Logo
            if (orgImg.equals("image")) {
                header.addCell("no image ");

            } else {
                header.addCell(createImageCell(orgImg));

            }
            //second column ///description
            header.addCell(createTextCell(orgAbout));

            header.addCell(createTextCell(""));

            PdfPTable RecieptTilte = new PdfPTable(3);

            //                //  tbl.setWidthPercentage(100);
            //                
            RecieptTilte.setTotalWidth(575);
            RecieptTilte.setLockedWidth(true);
            // RecieptTilte.setHorizontalAlignment(Align.CENTER);
            RecieptTilte.setWidths(new int[] { 1, 1, 1 });
            RecieptTilte.setSpacingBefore(8);
            RecieptTilte.setSpacingAfter(6);
            //       RecieptTilte.getDefaultCell().setBorderWidthBottom(2);
            RecieptTilte.getDefaultCell().setBorderWidthLeft(0);
            RecieptTilte.getDefaultCell().setBorderWidthRight(0);
            RecieptTilte.addCell(createTextCellNb(""));

            RecieptTilte.addCell("GOODS RECEIVED NOTE");

            RecieptTilte.setSpacingAfter(8);
            RecieptTilte.addCell(createTextCellNb(""));

            PdfPTable RecieptFrom = new PdfPTable(3);

            //                //  tbl.setWidthPercentage(100);
            //                
            RecieptFrom.setTotalWidth(575);
            RecieptFrom.setLockedWidth(true);
            // RecieptTilte.setHorizontalAlignment(Align.CENTER);
            RecieptFrom.setWidths(new int[] { 1, 1, 1 });
            // RecieptFrom.setSpacingBefore(8);
            // RecieptFrom.setSpacingAfter(6);
            //       RecieptTilte.getDefaultCell().setBorderWidthBottom(2);
            RecieptFrom.getDefaultCell().setBorderWidthLeft(0);
            RecieptFrom.getDefaultCell().setBorderWidthRight(0);

            RecieptFrom.addCell(createTextCellNb(""));
            RecieptFrom.addCell(createTextCellNb(""));
            RecieptFrom.addCell(createTextCellNb(""));

            RecieptFrom.addCell(createTextCellNb("Received From : "));
            RecieptFrom.addCell(createTextCellNb(otherDetails[0]));
            RecieptFrom.addCell(createTextCellNb(""));
            RecieptFrom.addCell(createTextCellNb("Address       :"));
            RecieptFrom.addCell(createTextCellNb(otherDetails[1]));
            RecieptFrom.addCell(createTextCellNb(""));

            RecieptFrom.addCell(createTextCellNb(""));
            RecieptFrom.addCell(createTextCellNb(""));
            RecieptFrom.addCell(createTextCellNb(""));
            //                                    otherDetails[0]=from;
            //                    otherDetails[1]=fromAddress;
            //                    otherDetails[2]=receivedBy;
            //                    otherDetails[3]=designation;
            //                    otherDetails[4]=department;
            //                    otherDetails[5]=deliveredBy;
            //                    otherDetails[6]=reciept_in;

            PdfPTable RecieptitemsTitles = new PdfPTable(5);

            RecieptitemsTitles.setTotalWidth(575);
            RecieptitemsTitles.setWidths(new int[] { 2, 1, 1, 1, 1 });

            RecieptitemsTitles.setLockedWidth(true);

            RecieptitemsTitles.addCell(creatTextCellTitles("Description"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Quantiy"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Purchase Order No"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Rate(Kshs)"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Value(Kshs)"));
            //    RecieptitemsTitles.addCell(creatTextCellTitles("Id"));

            //  PdfPTable Recieptitems=new PdfPTable(4);
            for (int a = 0; a < items.size(); a++) {
                RecieptitemsTitles
                        .addCell(createTextCellcolor(((ReceivedCart) items.get(a)).getItem_name(), a));
                RecieptitemsTitles.addCell(
                        createTextCellcolor(((ReceivedCart) items.get(a)).getTransaction_quantity(), a));
                RecieptitemsTitles.addCell(createTextCellcolor(
                        ((ReceivedCart) items.get(a)).getTransaction_purchase_order_no(), a));
                RecieptitemsTitles.addCell(
                        createTextCellcolor(((ReceivedCart) items.get(a)).getTransaction_item_cash(), a));
                RecieptitemsTitles
                        .addCell(createTextCellcolor(((ReceivedCart) items.get(a)).getTransaction_cash(), a));
                //  RecieptitemsTitles.addCell(createTextCellcolor(String.valueOf(((CartPojo)items.get(a)).getItem_id()),a));

            }

            PdfPTable RecieptTotals = new PdfPTable(4);

            //                //  tbl.setWidthPercentage(100);
            //                
            RecieptTotals.setTotalWidth(575);
            RecieptTotals.setLockedWidth(true);
            // RecieptTilte.setHorizontalAlignment(Align.CENTER);
            RecieptTotals.setWidths(new int[] { 1, 1, 1, 1 });
            RecieptTotals.setSpacingBefore(8);
            RecieptTotals.setSpacingAfter(6);
            //       RecieptTilte.getDefaultCell().setBorderWidthBottom(2);
            RecieptTotals.getDefaultCell().setBorderWidthLeft(0);
            RecieptTotals.getDefaultCell().setBorderWidthRight(0);
            //                    otherDetails[2]=receivedBy;
            //                    otherDetails[3]=designation;
            //                    otherDetails[4]=department;
            //                    otherDetails[5]=deliveredBy;
            //                    otherDetails[6]=reciept_in;

            RecieptTotals.addCell(createTextCellNb(""));
            RecieptTotals.addCell(createTextCellNb(""));
            RecieptTotals.addCell(createTextCellNb(""));
            RecieptTotals.addCell(createTextCellNb(""));

            RecieptTotals.addCell(createTextCellNb("Received By  : "));
            RecieptTotals.addCell(createTextCellNb(otherDetails[2]));
            RecieptTotals.addCell(createTextCellNb("Delivered By :"));
            RecieptTotals.addCell(createTextCellNb(otherDetails[5]));
            RecieptTotals.addCell(createTextCellNb("Designation  : "));
            RecieptTotals.addCell(createTextCellNb(otherDetails[3]));
            RecieptTotals.addCell(createTextCellNb("Total        :"));
            RecieptTotals.addCell(createTextCellNb(total_cash));
            RecieptTotals.addCell(createTextCellNb("Department   :"));
            RecieptTotals.addCell(createTextCellNb(otherDetails[4]));

            RecieptTotals.addCell(createTextCellNb(""));
            RecieptTotals.addCell(createTextCellNb(""));
            RecieptTotals.addCell(createTextCellNb(""));
            RecieptTotals.addCell(createTextCellNb(""));

            PdfPTable RecieptEnds = new PdfPTable(3);
            RecieptEnds.setTotalWidth(575);
            RecieptEnds.setLockedWidth(true);
            // RecieptTilte.setHorizontalAlignment(Align.CENTER);
            RecieptEnds.setWidths(new int[] { 1, 1, 1 });
            RecieptEnds.setSpacingBefore(8);
            RecieptEnds.setSpacingAfter(6);
            //       RecieptTilte.getDefaultCell().setBorderWidthBottom(2);
            RecieptEnds.getDefaultCell().setBorderWidthLeft(0);
            RecieptEnds.getDefaultCell().setBorderWidthRight(0);
            //                    otherDetails[2]=receivedBy;
            //                    otherDetails[3]=designation;
            //                    otherDetails[4]=department;
            //                    otherDetails[5]=deliveredBy;
            //                    otherDetails[6]=reciept_in;

            RecieptEnds.addCell(createTextCellNb(""));
            RecieptEnds.addCell(createTextCellNb(""));
            RecieptEnds.addCell(createTextCellNb(""));

            RecieptEnds.addCell(createTextCellNb("Store  Ledger No  : "));
            RecieptEnds.addCell(createTextCellNb("Invoice No        : "));
            RecieptEnds.addCell(createTextCellNb("Suppliers Delivery No :"));

            RecieptEnds.addCell(createTextCellNb(""));
            RecieptEnds.addCell(createTextCellNb(""));
            RecieptEnds.addCell(createTextCellNb(""));

            RecieptEnds.addCell(createTextCellNb(transactionReceiptNo));
            RecieptEnds.addCell(createTextCellNb(otherDetails[6]));
            RecieptEnds.addCell(createTextCellNb("-----------------"));

            RecieptEnds.addCell(createTextCellNb(""));
            RecieptEnds.addCell(createTextCellNb(""));
            RecieptEnds.addCell(createTextCellNb(""));

            pdfp.add(header1);
            pdfp.add(header);
            pdfp.add(RecieptTilte);
            pdfp.add(RecieptFrom);
            pdfp.add(RecieptitemsTitles);

            pdfp.add(RecieptTotals);

            pdfp.add(RecieptEnds);

            pdfp.close();

        } catch (DocumentException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        }
        // jComboBoxGroup
        if (Desktop.isDesktopSupported()) {
            try {
                File file = new File(chooser.getSelectedFile(), transactionReceiptNo + "" + DATE + ".pdf");
                Desktop.getDesktop().open(file);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

}

From source file:storemanagment.Printing.java

public final void Inventory(String store, String officer, ArrayList<ItemsPojo> items, String trNo) {
    Calendar c = Calendar.getInstance();
    Date today = c.getTime();//  w  w  w  .  j a v  a2s.co m

    java.util.Date d = (today);

    java.sql.Date DATE = new java.sql.Date(d.getTime());

    // String OrgDetails=res[1]+"\n"+DATE.toString();
    String orgDetails[] = getRes();
    String orgImg = orgDetails[0];
    String orgAbout = orgDetails[1];

    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File(","));
    chooser.setDialogTitle("Save at");
    chooser.setApproveButtonText("save");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        try {

            Document pdfp = new Document();
            PdfWriter writer = PdfWriter.getInstance(pdfp,
                    new FileOutputStream(new File(chooser.getSelectedFile(), store + "" + DATE + ".pdf")));

            // PdfWriter writer = PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),"Group "+jComboBoxGroup.getSelectedItem().toString()+".pdf")));
            HeaderFooterPageEvent event = new HeaderFooterPageEvent(officer, trNo, DATE);
            writer.setPageEvent(event);
            pdfp.open();

            //        Document pdfp=new Document();
            //            PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),transactionReceiptNo+""+DATE+".pdf")));
            //                pdfp.open();
            PdfPTable header1 = new PdfPTable(1);

            //                //  tbl.setWidthPercentage(100);
            //                
            header1.setTotalWidth(575);
            header1.setLockedWidth(true);
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            PdfPTable header = new PdfPTable(3);

            //                //  tbl.setWidthPercentage(100);
            //                
            header.setTotalWidth(575);
            header.setLockedWidth(true);

            header.setWidths(new int[] { 1, 4, 1 });

            //THE FIRST ROW
            //first column ///Logo
            if (orgImg.equals("image")) {
                header.addCell("no image ");

            } else {
                header.addCell(createImageCell(orgImg));

            }
            //second column ///description
            header.addCell(createTextCell(orgAbout));

            header.addCell(createTextCell(""));

            PdfPTable RecieptTilte = new PdfPTable(3);

            //                //  tbl.setWidthPercentage(100);
            //                
            RecieptTilte.setTotalWidth(575);
            RecieptTilte.setLockedWidth(true);
            // RecieptTilte.setHorizontalAlignment(Align.CENTER);
            RecieptTilte.setWidths(new int[] { 1, 1, 1 });
            RecieptTilte.setSpacingBefore(8);
            RecieptTilte.setSpacingAfter(6);
            //       RecieptTilte.getDefaultCell().setBorderWidthBottom(2);
            RecieptTilte.getDefaultCell().setBorderWidthLeft(0);
            RecieptTilte.getDefaultCell().setBorderWidthRight(0);
            RecieptTilte.addCell("");

            RecieptTilte.addCell(store + " INVENTORY");

            RecieptTilte.setSpacingAfter(8);
            RecieptTilte.addCell("");

            PdfPTable RecieptitemsTitles = new PdfPTable(3);

            RecieptitemsTitles.setTotalWidth(575);
            RecieptitemsTitles.setWidths(new int[] { 2, 1, 1 });

            RecieptitemsTitles.setLockedWidth(true);

            RecieptitemsTitles.addCell(creatTextCellTitles("Item-Name"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Quantiy"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Unit"));
            //    RecieptitemsTitles.addCell(creatTextCellTitles("Id"));

            //  PdfPTable Recieptitems=new PdfPTable(4);
            for (int a = 0; a < items.size(); a++) {
                RecieptitemsTitles.addCell(createTextCellcolor(((ItemsPojo) items.get(a)).getItem_name(), a));
                RecieptitemsTitles
                        .addCell(createTextCellcolor(((ItemsPojo) items.get(a)).getItem_quantity(), a));
                RecieptitemsTitles
                        .addCell(createTextCellcolor(((ItemsPojo) items.get(a)).getItem_quantity_in(), a));
                //  RecieptitemsTitles.addCell(createTextCellcolor(String.valueOf(((CartPojo)items.get(a)).getItem_id()),a));

            }

            pdfp.add(header1);
            pdfp.add(header);
            pdfp.add(RecieptTilte);
            pdfp.add(RecieptitemsTitles);

            pdfp.close();

        } catch (DocumentException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        }
        // jComboBoxGroup
        if (Desktop.isDesktopSupported()) {
            try {
                File file = new File(chooser.getSelectedFile(), store + "" + DATE + ".pdf");
                Desktop.getDesktop().open(file);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

}

From source file:storemanagment.Printing.java

public final void StoreTaking(String store, String officer, ArrayList<ItemsPojo> items) {
    Calendar c = Calendar.getInstance();
    Date today = c.getTime();/*from   w  w w.  j  ava 2 s .c  o  m*/

    java.util.Date d = (today);

    java.sql.Date DATE = new java.sql.Date(d.getTime());

    // String OrgDetails=res[1]+"\n"+DATE.toString();
    String orgDetails[] = getRes();
    String orgImg = orgDetails[0];
    String orgAbout = orgDetails[1];

    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File(","));
    chooser.setDialogTitle("Save at");
    chooser.setApproveButtonText("save");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        try {

            Document pdfp = new Document();
            PdfWriter writer = PdfWriter.getInstance(pdfp,
                    new FileOutputStream(new File(chooser.getSelectedFile(), store + "" + DATE + ".pdf")));

            // PdfWriter writer = PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),"Group "+jComboBoxGroup.getSelectedItem().toString()+".pdf")));
            FooterOnly event = new FooterOnly(officer, "", DATE);
            writer.setPageEvent(event);
            pdfp.open();

            //        Document pdfp=new Document();
            //            PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),transactionReceiptNo+""+DATE+".pdf")));
            //                pdfp.open();
            PdfPTable header1 = new PdfPTable(1);

            //                //  tbl.setWidthPercentage(100);
            //                
            header1.setTotalWidth(575);
            header1.setLockedWidth(true);
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            PdfPTable header = new PdfPTable(3);

            //                //  tbl.setWidthPercentage(100);
            //                
            header.setTotalWidth(575);
            header.setLockedWidth(true);

            header.setWidths(new int[] { 1, 4, 1 });

            //THE FIRST ROW
            //first column ///Logo
            if (orgImg.equals("image")) {
                header.addCell("no image ");

            } else {
                header.addCell(createImageCell(orgImg));

            }
            //second column ///description
            header.addCell(createTextCell(orgAbout));

            header.addCell(createTextCell(""));

            PdfPTable RecieptTilte = new PdfPTable(3);

            //                //  tbl.setWidthPercentage(100);
            //                
            RecieptTilte.setTotalWidth(575);
            RecieptTilte.setLockedWidth(true);
            // RecieptTilte.setHorizontalAlignment(Align.CENTER);
            RecieptTilte.setWidths(new int[] { 1, 1, 1 });
            RecieptTilte.setSpacingBefore(8);
            RecieptTilte.setSpacingAfter(6);
            //       RecieptTilte.getDefaultCell().setBorderWidthBottom(2);
            RecieptTilte.getDefaultCell().setBorderWidthLeft(0);
            RecieptTilte.getDefaultCell().setBorderWidthRight(0);
            RecieptTilte.addCell("");

            RecieptTilte.addCell(store + " Stock Taking Guide");

            RecieptTilte.setSpacingAfter(8);
            RecieptTilte.addCell("");

            PdfPTable RecieptitemsTitles = new PdfPTable(5);

            RecieptitemsTitles.setTotalWidth(575);
            RecieptitemsTitles.setWidths(new int[] { 2, 1, 1, 1, 1 });

            RecieptitemsTitles.setLockedWidth(true);

            RecieptitemsTitles.addCell(creatTextCellTitles("Item-Name"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Quantiy"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Unit"));

            RecieptitemsTitles.addCell(creatTextCellTitles("Ph"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Var"));
            //    RecieptitemsTitles.addCell(creatTextCellTitles("Id"));

            //  PdfPTable Recieptitems=new PdfPTable(4);
            for (int a = 0; a < items.size(); a++) {
                RecieptitemsTitles.addCell(createTextCellcolor(((ItemsPojo) items.get(a)).getItem_name(), a));
                RecieptitemsTitles
                        .addCell(createTextCellcolor(((ItemsPojo) items.get(a)).getItem_quantity(), a));
                RecieptitemsTitles
                        .addCell(createTextCellcolor(((ItemsPojo) items.get(a)).getItem_quantity_in(), a));

                RecieptitemsTitles.addCell(createTextCellcolor("", 1));
                RecieptitemsTitles.addCell(createTextCellcolor("", 1));
                //  RecieptitemsTitles.addCell(createTextCellcolor(String.valueOf(((CartPojo)items.get(a)).getItem_id()),a));

            }

            pdfp.add(header1);
            pdfp.add(header);
            pdfp.add(RecieptTilte);
            pdfp.add(RecieptitemsTitles);

            pdfp.close();

        } catch (DocumentException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        }
        // jComboBoxGroup
        if (Desktop.isDesktopSupported()) {
            try {
                File file = new File(chooser.getSelectedFile(), store + "" + DATE + ".pdf");
                Desktop.getDesktop().open(file);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

}

From source file:storemanagment.Printing.java

public final void Transactions(String store, String officer, ArrayList<TransactionsPojo> items, String trNo) {
    Calendar c = Calendar.getInstance();
    Date today = c.getTime();/* www .ja  va 2s.  c o  m*/

    java.util.Date d = (today);

    java.sql.Date DATE = new java.sql.Date(d.getTime());

    // String OrgDetails=res[1]+"\n"+DATE.toString();
    String orgDetails[] = getRes();
    String orgImg = orgDetails[0];
    String orgAbout = orgDetails[1];

    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File(","));
    chooser.setDialogTitle("Save at");
    chooser.setApproveButtonText("save");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        try {

            Document pdfp = new Document();
            PdfWriter writer = PdfWriter.getInstance(pdfp,
                    new FileOutputStream(new File(chooser.getSelectedFile(), store + "tr" + DATE + ".pdf")));

            // PdfWriter writer = PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),"Group "+jComboBoxGroup.getSelectedItem().toString()+".pdf")));
            HeaderFooterPageEvent event = new HeaderFooterPageEvent(officer, trNo, DATE);
            writer.setPageEvent(event);
            pdfp.open();

            //        Document pdfp=new Document();
            //            PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),transactionReceiptNo+""+DATE+".pdf")));
            //                pdfp.open();
            PdfPTable header1 = new PdfPTable(1);

            //                //  tbl.setWidthPercentage(100);
            //                
            header1.setTotalWidth(575);
            header1.setLockedWidth(true);
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            PdfPTable header = new PdfPTable(3);

            //                //  tbl.setWidthPercentage(100);
            //                
            header.setTotalWidth(575);
            header.setLockedWidth(true);

            header.setWidths(new int[] { 1, 4, 1 });

            //THE FIRST ROW
            //first column ///Logo
            if (orgImg.equals("image")) {
                header.addCell("no image ");

            } else {
                header.addCell(createImageCell(orgImg));

            }
            //second column ///description
            header.addCell(createTextCell(orgAbout));

            header.addCell(createTextCell(""));

            PdfPTable RecieptTilte = new PdfPTable(3);

            //                //  tbl.setWidthPercentage(100);
            //                
            RecieptTilte.setTotalWidth(575);
            RecieptTilte.setLockedWidth(true);
            // RecieptTilte.setHorizontalAlignment(Align.CENTER);
            RecieptTilte.setWidths(new int[] { 1, 1, 1 });
            RecieptTilte.setSpacingBefore(8);
            RecieptTilte.setSpacingAfter(6);
            //       RecieptTilte.getDefaultCell().setBorderWidthBottom(2);
            RecieptTilte.getDefaultCell().setBorderWidthLeft(0);
            RecieptTilte.getDefaultCell().setBorderWidthRight(0);
            RecieptTilte.addCell("");

            RecieptTilte.addCell(store + " Transactions");

            RecieptTilte.setSpacingAfter(8);
            RecieptTilte.addCell("");

            PdfPTable RecieptitemsTitles = new PdfPTable(9);

            RecieptitemsTitles.setTotalWidth(575);
            RecieptitemsTitles.setWidths(new int[] { 1, 1, 2, 1, 1, 1, 1, 1, 2 });

            RecieptitemsTitles.setLockedWidth(true);

            RecieptitemsTitles.addCell(creatTextCellTitles("Item-Name"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Quantiy"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Type"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Unit Rate"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Total Cash"));
            RecieptitemsTitles.addCell(creatTextCellTitles("From"));
            RecieptitemsTitles.addCell(creatTextCellTitles("To"));
            RecieptitemsTitles.addCell(creatTextCellTitles("R.No"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Date"));
            //    RecieptitemsTitles.addCell(creatTextCellTitles("Id"));

            //  PdfPTable Recieptitems=new PdfPTable(4);
            for (int a = 0; a < items.size(); a++) {
                RecieptitemsTitles
                        .addCell(createTextCellcolor(((TransactionsPojo) items.get(a)).getItem_name(), a));
                RecieptitemsTitles
                        .addCell(createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_quantity()
                                + " " + ((TransactionsPojo) items.get(a)).getTransaction_quantity_in(), a));
                RecieptitemsTitles.addCell(
                        createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_type(), a));

                RecieptitemsTitles.addCell(
                        createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_item_cash(), a));
                RecieptitemsTitles.addCell(
                        createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_cash(), a));
                RecieptitemsTitles.addCell(
                        createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_from(), a));
                RecieptitemsTitles
                        .addCell(createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_to(), a));
                RecieptitemsTitles.addCell(createTextCellcolor(
                        ((TransactionsPojo) items.get(a)).getTransaction_receipt_no_out(), a));
                RecieptitemsTitles.addCell(
                        createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_time_string(), a));
                //  RecieptitemsTitles.addCell(createTextCellcolor(String.valueOf(((CartPojo)items.get(a)).getItem_id()),a));

            }

            pdfp.add(header1);
            pdfp.add(header);
            pdfp.add(RecieptTilte);
            pdfp.add(RecieptitemsTitles);

            pdfp.close();

        } catch (DocumentException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        }
        // jComboBoxGroup
        if (Desktop.isDesktopSupported()) {
            try {
                File file = new File(chooser.getSelectedFile(), store + "tr" + DATE + ".pdf");
                Desktop.getDesktop().open(file);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

}

From source file:storemanagment.Printing.java

public final void StockTake(String store, String officer, ArrayList<TransactionsPojo> items, String trNo) {
    Calendar c = Calendar.getInstance();
    Date today = c.getTime();//  w w w  .  ja  v  a 2s. c  o m

    java.util.Date d = (today);

    java.sql.Date DATE = new java.sql.Date(d.getTime());

    // String OrgDetails=res[1]+"\n"+DATE.toString();
    String orgDetails[] = getRes();
    String orgImg = orgDetails[0];
    String orgAbout = orgDetails[1];

    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File(","));
    chooser.setDialogTitle("Save at");
    chooser.setApproveButtonText("save");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        try {

            Document pdfp = new Document();
            PdfWriter writer = PdfWriter.getInstance(pdfp,
                    new FileOutputStream(new File(chooser.getSelectedFile(), store + "st" + DATE + ".pdf")));

            // PdfWriter writer = PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),"Group "+jComboBoxGroup.getSelectedItem().toString()+".pdf")));
            HeaderFooterPageEvent event = new HeaderFooterPageEvent(officer, trNo, DATE);
            writer.setPageEvent(event);
            pdfp.open();

            //        Document pdfp=new Document();
            //            PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),transactionReceiptNo+""+DATE+".pdf")));
            //                pdfp.open();
            PdfPTable header1 = new PdfPTable(1);

            //                //  tbl.setWidthPercentage(100);
            //                
            header1.setTotalWidth(575);
            header1.setLockedWidth(true);
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            header1.addCell(createTextCell(""));
            PdfPTable header = new PdfPTable(3);

            //                //  tbl.setWidthPercentage(100);
            //                
            header.setTotalWidth(575);
            header.setLockedWidth(true);

            header.setWidths(new int[] { 1, 4, 1 });

            //THE FIRST ROW
            //first column ///Logo
            if (orgImg.equals("image")) {
                header.addCell("no image ");

            } else {
                header.addCell(createImageCell(orgImg));

            }
            //second column ///description
            header.addCell(createTextCell(orgAbout));

            header.addCell(createTextCell(""));

            PdfPTable RecieptTilte = new PdfPTable(3);

            //                //  tbl.setWidthPercentage(100);
            //                
            RecieptTilte.setTotalWidth(575);
            RecieptTilte.setLockedWidth(true);
            // RecieptTilte.setHorizontalAlignment(Align.CENTER);
            RecieptTilte.setWidths(new int[] { 1, 1, 1 });
            RecieptTilte.setSpacingBefore(8);
            RecieptTilte.setSpacingAfter(6);
            //       RecieptTilte.getDefaultCell().setBorderWidthBottom(2);
            RecieptTilte.getDefaultCell().setBorderWidthLeft(0);
            RecieptTilte.getDefaultCell().setBorderWidthRight(0);
            RecieptTilte.addCell("");

            RecieptTilte.addCell(store + " Transactions");

            RecieptTilte.setSpacingAfter(8);
            RecieptTilte.addCell("");

            PdfPTable RecieptitemsTitles = new PdfPTable(8);

            RecieptitemsTitles.setTotalWidth(575);
            RecieptitemsTitles.setWidths(new int[] { 1, 1, 2, 1, 1, 1, 1, 2 });

            RecieptitemsTitles.setLockedWidth(true);

            RecieptitemsTitles.addCell(creatTextCellTitles("Item-Name"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Quantiy"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Type"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Cash"));
            RecieptitemsTitles.addCell(creatTextCellTitles("From"));
            RecieptitemsTitles.addCell(creatTextCellTitles("To"));
            RecieptitemsTitles.addCell(creatTextCellTitles("R.No"));
            RecieptitemsTitles.addCell(creatTextCellTitles("Date"));
            //    RecieptitemsTitles.addCell(creatTextCellTitles("Id"));

            //  PdfPTable Recieptitems=new PdfPTable(4);
            for (int a = 0; a < items.size(); a++) {
                RecieptitemsTitles
                        .addCell(createTextCellcolor(((TransactionsPojo) items.get(a)).getItem_name(), a));
                RecieptitemsTitles.addCell(
                        createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_quantity(), a));
                RecieptitemsTitles.addCell(
                        createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_type(), a));

                RecieptitemsTitles.addCell(
                        createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_cash(), a));
                RecieptitemsTitles.addCell(
                        createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_from(), a));
                RecieptitemsTitles
                        .addCell(createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_to(), a));
                RecieptitemsTitles.addCell(createTextCellcolor(
                        ((TransactionsPojo) items.get(a)).getTransaction_receipt_no_out(), a));
                RecieptitemsTitles.addCell(
                        createTextCellcolor(((TransactionsPojo) items.get(a)).getTransaction_time_string(), a));
                //  RecieptitemsTitles.addCell(createTextCellcolor(String.valueOf(((CartPojo)items.get(a)).getItem_id()),a));

            }

            pdfp.add(header1);
            pdfp.add(header);
            pdfp.add(RecieptTilte);
            pdfp.add(RecieptitemsTitles);

            pdfp.close();

        } catch (DocumentException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        }
        // jComboBoxGroup
        if (Desktop.isDesktopSupported()) {
            try {
                File file = new File(chooser.getSelectedFile(), store + "tr" + DATE + ".pdf");
                Desktop.getDesktop().open(file);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

}