Example usage for com.lowagie.text.pdf PdfWriter setPageEvent

List of usage examples for com.lowagie.text.pdf PdfWriter setPageEvent

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfWriter setPageEvent.

Prototype


public void setPageEvent(PdfPageEvent event) 

Source Link

Document

Sets the PdfPageEvent for this document.

Usage

From source file:questions.stamppages.BookmarksToTOC2.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {// ww w  .ja v  a 2  s. co  m
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        writer.setPageEvent(new ParagraphBookmarkEvents(true));
        document.open();
        BufferedReader reader = new BufferedReader(new FileReader(RESOURCE));
        String line;
        Paragraph p;
        while ((line = reader.readLine()) != null) {
            p = new Paragraph(line);
            p.setAlignment(Element.ALIGN_JUSTIFIED);
            document.add(p);
            document.add(Chunk.NEWLINE);
        }
        reader.close();
        document.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    try {
        PdfReader reader = new PdfReader(baos.toByteArray());
        Rectangle rect = reader.getPageSizeWithRotation(1);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        stamper.insertPage(1, rect);
        ColumnText column = new ColumnText(stamper.getOverContent(1));
        column.setSimpleColumn(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36));
        column.addElement(new Paragraph("TABLE OF CONTENTS"));
        List<Map> list = SimpleBookmark.getBookmark(reader);
        Chunk link;
        String dest;
        for (Map<String, String> bookmark : list) {
            link = new Chunk(bookmark.get("Title"));
            dest = bookmark.get("Named");
            link.setAction(PdfAction.gotoLocalPage(dest, false));
            column.addElement(new Paragraph(link));
        }
        column.go();
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:questions.tables.AddTableAsHeaderFooter.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 100);
    try {// w  w w.  ja v  a 2 s .co m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        writer.setPageEvent(new AddTableAsHeaderFooter());
        document.open();
        String text = "Lots of text. ";
        for (int i = 0; i < 5; i++)
            text += text;
        for (int i = 0; i < 20; i++)
            document.add(new Paragraph(text));
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:storemanagment.Printing.java

public final void TransactionGiven(String transactionReceiptNo, String officer, ArrayList<CartPojo> items) {
    Calendar c = Calendar.getInstance();
    Date today = c.getTime();//from   w  w  w.  j  av a  2 s.  com

    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("");

            RecieptTilte.addCell("Transaction Receipt");

            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(((CartPojo) items.get(a)).getItem_name(), a));
                RecieptitemsTitles
                        .addCell(createTextCellcolor(((CartPojo) items.get(a)).getTransaction_quantity(), a));
                RecieptitemsTitles.addCell(
                        createTextCellcolor(((CartPojo) items.get(a)).getTransaction_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(), transactionReceiptNo + "" + DATE + ".pdf");
                Desktop.getDesktop().open(file);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

}

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 av  a 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(), 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();/*ww w .  j  av  a2  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")));
            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();//ww w. jav a  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(), 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();//  w  w w .ja  v  a2  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 + "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  ww  .j  a  v  a 2s.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 + "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();
            }
        }
    }

}