Example usage for com.itextpdf.text.pdf PdfPTable PdfPTable

List of usage examples for com.itextpdf.text.pdf PdfPTable PdfPTable

Introduction

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

Prototype

public PdfPTable(final PdfPTable table) 

Source Link

Document

Constructs a copy of a PdfPTable.

Usage

From source file:com.etest.pdfgenerator.TQCoveragePDF.java

public TQCoveragePDF(int tqCoverageId) {
    this.tqCoverageId = tqCoverageId;

    Document document = null;//w ww  . j ava2 s. c om

    try {
        document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header1 = FontFactory.getFont("Times-Roman", 14, Font.BOLD);
        Font header2 = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);

        Image img = null;
        try {
            img = Image.getInstance("C:\\eTest-images\\SUCN_seal.png");
            img.scaleToFit(60, 60);
            img.setAbsolutePosition(100, 720);
        } catch (BadElementException | IOException ex) {
            Logger.getLogger(TQCoveragePDF.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.add(img);

        Paragraph title = new Paragraph();
        title.setAlignment(Element.ALIGN_CENTER);
        title.add(new Phrase("COLLEGE OF NURSING", header2));
        document.add(title);

        Paragraph school = new Paragraph();
        school.setAlignment(Element.ALIGN_CENTER);
        school.add(new Phrase("Siliman University", header2));
        document.add(school);

        Paragraph location = new Paragraph();
        location.setSpacingAfter(10f);
        location.setAlignment(Element.ALIGN_CENTER);
        location.add(new Phrase("Dumaguete City", header2));
        document.add(location);

        Paragraph examTitle = new Paragraph();
        examTitle.setSpacingAfter(20f);
        examTitle.setAlignment(Element.ALIGN_CENTER);
        examTitle
                .add(new Phrase(
                        cs.getCurriculumById(tq.getTQCoverageById(getTQCoverageId()).getCurriculumId())
                                .getSubject() + " " + tq.getTQCoverageById(getTQCoverageId()).getExamTitle(),
                        header2));
        document.add(examTitle);

        Paragraph instruction = new Paragraph();
        instruction.setSpacingAfter(5f);
        instruction.setAlignment(Element.ALIGN_LEFT);
        instruction.add(
                new Phrase("INSTRUCTIONS: Read the cases carefully. Choose the letter of the correct answer. "
                        + "Use an answer sheet and follow instruction for its use.", content));
        document.add(instruction);

        int itemNo = 1;
        Map<Integer, Map<Integer, Integer>> tqCoverage = tq.getTQCoverage(getTQCoverageId());
        for (Map.Entry<Integer, Map<Integer, Integer>> tqCases : tqCoverage.entrySet()) {
            Integer tqCaseId = tqCases.getKey();

            Label caseTopic = new Label();
            caseTopic.setValue(ccs.getCellCaseById(tqCaseId).getCaseTopic());
            caseTopic.setContentMode(ContentMode.HTML);
            document.add(new Paragraph(caseTopic.getValue().replaceAll("(?i)<p.*?>.*?</p>", ""), content));

            Map<Integer, Integer> value = tqCases.getValue();
            for (Map.Entry<Integer, Integer> itemIds : value.entrySet()) {
                Integer itemId = itemIds.getKey();
                Integer itemKeyId = itemIds.getValue();

                List<String> keyList = k.getAllItemKey(itemId);
                if (keyList.isEmpty()) {
                    ShowErrorNotification.error(
                            "No Item Key was found for STEM: \n" + cis.getCellItemById(itemId).getItem());
                    return;
                }

                Label stem = new Label();
                //                    stem.setValue(itemNo+". "+cis.getCellItemById(itemId).getItem().replace("{key}", keyList.get(0)));
                stem.setValue(itemNo + ". "
                        + cis.getCellItemById(itemId).getItem().replace("{key}", k.getItemKeyById(itemKeyId)));
                stem.setContentMode(ContentMode.HTML);
                document.add(new Paragraph(stem.getValue(), content));

                PdfPTable table = new PdfPTable(2);
                table.setWidthPercentage(100);
                table.setSpacingBefore(10f);
                table.setSpacingAfter(10f);

                //Set Column widths
                float[] columnWidths = { 1f, 1f };
                table.setWidths(columnWidths);

                PdfPCell cell1 = new PdfPCell(
                        new Paragraph("A) " + cis.getCellItemById(itemId).getOptionA(), content));
                //                cell1.setBorderColor(BaseColor.BLUE);
                cell1.setBorder(0);
                cell1.setPaddingLeft(10);
                cell1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

                PdfPCell cell2 = new PdfPCell(
                        new Paragraph("C) " + cis.getCellItemById(itemId).getOptionC(), content));
                //                cell2.setBorderColor(BaseColor.GREEN);
                cell2.setBorder(0);
                cell2.setPaddingLeft(10);
                cell2.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

                PdfPCell cell3 = new PdfPCell(
                        new Paragraph("B) " + cis.getCellItemById(itemId).getOptionB(), content));
                //                cell3.setBorderColor(BaseColor.RED);
                cell3.setBorder(0);
                cell3.setPaddingLeft(10);
                cell3.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);

                PdfPCell cell4 = new PdfPCell(
                        new Paragraph("D) " + cis.getCellItemById(itemId).getOptionD(), content));
                //                cell4.setBorderColor(BaseColor.RED);
                cell4.setBorder(0);
                cell4.setPaddingLeft(10);
                cell4.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);

                table.addCell(cell1);
                table.addCell(cell2);
                table.addCell(cell3);
                table.addCell(cell4);

                document.add(table);

                itemNo++;
            }
        }

        document.newPage();

        Paragraph ticketNo = new Paragraph();
        ticketNo.setSpacingAfter(30f);
        ticketNo.setAlignment(Element.ALIGN_LEFT);
        ticketNo.add(new Phrase("TQ Ticket #: " + tq.getTqCoverageTicketNo(getTQCoverageId()), content));
        document.add(ticketNo);

        document.add(new Paragraph("Answer Key: "));

        itemNo = 1;
        List<TQAnswerKey> answerKey = tq.getTQCoverageAnswerKey(getTQCoverageId());
        for (TQAnswerKey t : answerKey) {
            document.add(new Paragraph(
                    t.getItemNo() + ": " + cis.getOptionAnswer(t.getCellItemId()).get(t.getAnswer())));
        }

    } catch (DocumentException ex) {
        Logger.getLogger(TQCoveragePDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (document != null) {
            document.close();
        }
    }
}

From source file:com.etest.pdfgenerator.TQCriticalIndexValuesReportPDF.java

public TQCriticalIndexValuesReportPDF(int tqCoverageId) {
    this.tqCoverageId = tqCoverageId;

    Document document = null;/*from  www .j a va2s.  c o  m*/

    try {
        document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);

        Paragraph reportTitle = new Paragraph();
        reportTitle.setSpacingAfter(10f);
        reportTitle.setAlignment(Element.ALIGN_CENTER);
        reportTitle.add(new Phrase("Interactive Querying", header));
        document.add(reportTitle);

        Paragraph title2 = new Paragraph();
        title2.setSpacingAfter(10f);
        title2.setAlignment(Element.ALIGN_CENTER);
        title2.add(new Phrase("View Item Analysis Critical Values of a Test", content));
        document.add(title2);

        Paragraph subject = new Paragraph();
        subject.setAlignment(Element.ALIGN_LEFT);
        subject.add(new Phrase("Subject: "
                + cs.getCurriculumById(tq.getTQCoverageById(getTqCoverageId()).getCurriculumId()).getSubject()
                        .toUpperCase()
                + "(" + cs.getCurriculumById(tq.getTQCoverageById(getTqCoverageId()).getCurriculumId())
                        .getDescriptiveTitle()
                + ")", content));
        document.add(subject);

        Paragraph term = new Paragraph();
        term.setAlignment(Element.ALIGN_LEFT);
        term.add(new Phrase("SY and Semester Administered: 2015-16 2nd Semester", content));
        document.add(term);

        Paragraph descriptiveTitle = new Paragraph();
        descriptiveTitle.setSpacingAfter(10f);
        descriptiveTitle.setAlignment(Element.ALIGN_LEFT);
        descriptiveTitle.add(
                new Phrase("Type of Test: " + tq.getTQCoverageById(getTqCoverageId()).getExamTitle(), content));
        document.add(descriptiveTitle);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(75);

        PdfPCell cellOne = new PdfPCell(new Phrase("Difficulty"));
        cellOne.setBorder(0);
        cellOne.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellOne.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellTwo = new PdfPCell(new Phrase("Discrimination"));
        cellTwo.setBorder(0);
        cellTwo.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTwo.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellThree = new PdfPCell(new Phrase(
                String.valueOf(rs.getTQCriticalIndexValue(getTqCoverageId(), "DifficultIndex", 0.00, 0.19))
                        + " Very difficult item(s)",
                content));
        cellThree.setBorder(0);
        cellThree.setPaddingLeft(50);
        cellThree.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellThree.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFour = new PdfPCell(new Phrase(
                String.valueOf(rs.getTQCriticalIndexValue(getTqCoverageId(), "DiscriminationIndex", 0.00, 0.19))
                        + " Poor items(s)",
                content));
        cellFour.setBorder(0);
        cellFour.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellFour.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFive = new PdfPCell(new Phrase(
                String.valueOf(rs.getTQCriticalIndexValue(getTqCoverageId(), "DifficultIndex", 0.81, 1))
                        + " Very easy item(s)",
                content));
        cellFive.setBorder(0);
        cellFive.setPaddingLeft(50);
        cellFive.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellFive.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellSix = new PdfPCell(new Phrase(""));
        cellSix.setBorder(0);
        cellSix.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellSix.setVerticalAlignment(Element.ALIGN_MIDDLE);

        table.addCell(cellOne);
        table.addCell(cellTwo);
        table.addCell(cellThree);
        table.addCell(cellFour);
        table.addCell(cellFive);
        table.addCell(cellSix);

        table.getDefaultCell().setBorderWidth(0f);
        document.add(table);

    } catch (DocumentException ex) {
        Logger.getLogger(TQCriticalIndexValuesReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (document != null) {
            document.close();
        }
    }

}

From source file:com.example.admin.avoidq.billGenerated.java

private void generatePDF(final String personName) {
    new Thread(new Runnable() {
        public void run() {
            // a potentially  time consuming task

            //create a new document
            Document document = new Document();

            try {

                PdfWriter docWriter = PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
                document.open();/*w  w  w .j  av a2  s .  co m*/

                PdfContentByte cb = docWriter.getDirectContent();
                //initialize fonts for text printing
                initializeFonts();

                //the company logo is stored in the assets which is read only
                //get the logo and print on the document
                /*
                try {
                        
                bitmap11 = encodeAsBitmap(barcode_data, BarcodeFormat.CODE_128, 600, 300);
                iv.setImageBitmap(bitmap11);
                        
                } catch (WriterException e) {
                e.printStackTrace();
                }
                * */
                InputStream inputStream = getAssets().open("sale.png");

                Bitmap bmp = null;//BitmapFactory.decodeStream(inputStream);
                bmp = bitmap11;
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);

                Image companyLogo = Image.getInstance(stream.toByteArray());
                companyLogo.setAbsolutePosition(25, 700);
                companyLogo.scalePercent(65);
                document.add(companyLogo);
                Calendar calendar = Calendar.getInstance();
                SimpleDateFormat df1 = new SimpleDateFormat("dd-MM-yyyy");
                String formattedDate = df1.format(calendar.getTime());

                //creating a sample invoice with some customer data
                createHeadings(cb, 400, 780, "Date :");
                createHeadings(cb, 430, 780, formattedDate);

                String fname = customer.getName();
                String lname = customer.getSurname();
                createHeadings(cb, 400, 765, "Customer :");
                createHeadings(cb, 445, 765, fname + " " + lname);

                String mob = customer.getMobile_no();
                createHeadings(cb, 400, 750, "Mobile No :");
                createHeadings(cb, 445, 750, mob);

                createHeadings(cb, 400, 735, "Shop :");
                createHeadings(cb, 430, 735, "Empress Mall");

                createHeadings(cb, 400, 720, "City :");
                createHeadings(cb, 430, 720, "Nagpur");
                // createHeadings(cb,400,720,"Country");

                //list all the products sold to the customer
                float[] columnWidths = { 1.5f, 3f, 2.5f, 2.5f, 2f, 2f };
                //create PDF table with the given widths
                PdfPTable table = new PdfPTable(columnWidths);
                // set table width a percentage of the page width
                table.setTotalWidth(500f);

                PdfPCell cell = new PdfPCell(new Phrase("S.NO"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase("Item Name"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase("Price"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase("Quantity"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase("Discount"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase("Amount"));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
                table.setHeaderRows(1);

                /*DecimalFormat df = new DecimalFormat("0.000");
                for(int i=0; i < 10; i++ ){
                    double price = Double.valueOf(df.format(Math.random() * 10));
                    double extPrice = price * (i+1) ;
                    table.addCell(String.valueOf(i+1));
                    table.addCell("ITEM" + String.valueOf(i+1));
                    table.addCell(String.valueOf(5*i));
                    table.addCell(String.valueOf(1));
                    table.addCell(String.valueOf(i)+ " %");
                    table.addCell(df.format(extPrice));
                }*/
                int sr = 0;
                DecimalFormat df = new DecimalFormat("0.0");
                double total_price = 0;
                //Log.i("c0","c0 = "+carts[0].getItemname()+" "+String.valueOf(carts[0].getPrice()));
                // Log.i("c1","c1 = "+carts[1].getItemname()+" "+String.valueOf(carts[1].getPrice()));
                for (Cart cd : carts) {
                    Log.i("cartscheck", "carts check = " + cd.getBarcode() + " " + cd.getItemname() + " "
                            + String.valueOf(cd.getPrice()));
                }
                for (Cart c : carts) {
                    double price = c.getPrice();
                    int quantity = c.getQuantity();
                    price = (price / quantity);
                    double discont = c.getDiscount();
                    sr++;
                    table.addCell(String.valueOf(sr));
                    table.addCell(c.getItemname());
                    table.addCell(df.format(price));
                    table.addCell(String.valueOf(quantity));
                    table.addCell(df.format(discont) + " %");

                    double total = (price * quantity);
                    total_price = total_price + total;
                    Log.i("total", "total in for loop = " + String.valueOf(total));
                    table.addCell(df.format(total));

                }
                float headerHeight = table.getHeaderHeight();
                Log.i("headerHeight", String.valueOf(headerHeight));
                //absolute location to print the PDF table from
                table.writeSelectedRows(0, -1, document.leftMargin(), 650, docWriter.getDirectContent());
                float total_height = table.getTotalHeight();
                Log.i("total_height", String.valueOf(total_height));
                createHeadings(cb, 420, 750f - 125f - total_height, "Total Price = ");
                createHeadings(cb, 475, 750f - 125f - total_height, String.valueOf(total_price));

                //print the signature image along with the persons name
                inputStream = getAssets().open("user.png");
                bmp = BitmapFactory.decodeStream(inputStream);
                stream = new ByteArrayOutputStream();
                bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
                Image signature = Image.getInstance(stream.toByteArray());
                signature.setAbsolutePosition(400f, 750f - 125f - total_height - 60f);
                signature.scalePercent(35f);
                document.add(signature);

                createHeadings(cb, 450, 750f - 125f - total_height - 80f, fname + " " + lname);

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

            //PDF file is now ready to be sent to the bluetooth printer using PrintShare
            Intent i = new Intent(Intent.ACTION_VIEW);
            //   i.setPackage("com.dynamixsoftware.printershare");
            i.setDataAndType(Uri.fromFile(pdfFile), "application/pdf");
            startActivity(i);

        }
    }).start();

}

From source file:com.example.drivequickstart.PDFActivity.java

private void createTable(Section subCatPart) throws BadElementException {
    PdfPTable table = new PdfPTable(3);

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    PdfPCell c1 = new PdfPCell(new Phrase("Job Name:"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);/*w w  w  .j a  va 2  s . c om*/

    c1 = new PdfPCell(new Phrase("Test 001"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(""));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    table.addCell("Date:");
    table.addCell("1.1");
    table.addCell("");
    table.addCell("Labor Rate:");
    table.addCell("2.2");
    table.addCell("");
    table.addCell("Labor Cost:");
    table.addCell("3.2");
    table.addCell("3.3");

    subCatPart.add(table);

}

From source file:com.example.pdfcreate.MainActivity.java

private static void createTable(Section subCatPart) throws BadElementException {
    PdfPTable table = new PdfPTable(3);

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    PdfPCell c1 = new PdfPCell(new Phrase("Job Name:"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);//from w  ww  . jav  a 2s. c om

    c1 = new PdfPCell(new Phrase("Test 001"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(""));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    table.addCell("Date:");
    table.addCell("1.1");
    table.addCell("");
    table.addCell("Labor Rate:");
    table.addCell("2.2");
    table.addCell("");
    table.addCell("Labor Cost:");
    table.addCell("3.2");
    table.addCell("3.3");

    //subCatPart.add(table);

}

From source file:com.farouk.projectapp.ManagerGUI.java

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
    String pdfName = JOptionPane.showInputDialog(rootPane, "Enter Title", "Please enter a title", WIDTH);
    if (pdfName.isEmpty()) {
        pdfName = "Global Report";
    }/*  w  w w  .ja v  a 2  s  . c om*/
    Document document = new Document();
    int numEMployees = 1;

    try {
        PdfWriter.getInstance(document, new FileOutputStream(pdfName + ".pdf"));

        document.open();
        document.addAuthor("TeamPirates");
        document.addTitle("Global Report");

        Font font1 = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD);
        Font font2 = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.UNDERLINE);

        for (User u : SQLConnectMana.getEmployeesFromDb()) {
            JTable jTableTran = new JTable();
            JTable jTableReport = new JTable();

            Chapter chapter = new Chapter(
                    new Paragraph(new Phrase("Employee : " + u.getLogin() + "\n\n", font1)), numEMployees);

            Section section1 = chapter.addSection(new Paragraph(new Phrase("Recent Transactions :\n", font2)),
                    9);

            Section section2 = chapter.addSection(new Paragraph(new Phrase("Reported Companies :\n", font2)),
                    9);

            // Transactions :
            DefaultTableModel modelPDFtrans = new DefaultTableModel();
            modelPDFtrans.setColumnIdentifiers(
                    new String[] { "Name", "Operation", "Quantity", "Price Paid", "Date" });
            for (Transaction t : SQLConnectMana.getTransactions(u.getId())) {
                modelPDFtrans.addRow(new String[] { t.getSymbol(), t.getOperation(),
                        Integer.toString(t.getQuantity()), Double.toString(t.getPricePaid()), t.getDate() });
            }
            jTableTran.setModel(modelPDFtrans);

            PdfPTable pdfTableTrans = new PdfPTable(jTableTran.getColumnCount());

            for (int i = 0; i < jTableTran.getColumnCount(); i++) {
                pdfTableTrans.addCell(jTableTran.getColumnName(i));
            }
            //extracting data from the JTable and inserting it to PdfPTable
            for (int rows = 0; rows < jTableTran.getRowCount(); rows++) {
                for (int cols = 0; cols < jTableTran.getColumnCount(); cols++) {
                    pdfTableTrans.addCell(jTableTran.getModel().getValueAt(rows, cols).toString());

                }
            }
            Paragraph blank = new Paragraph("\n\n");
            section1.add(blank);
            section1.add(pdfTableTrans);

            section1.add(blank);
            //Reported Companies :
            DefaultTableModel modelPDFReported = new DefaultTableModel();
            modelPDFReported.setColumnIdentifiers(
                    new String[] { "Name", "Symbol", "Stock Price ()", "Quantity Bought" });
            for (Company c : SQLConnectMana.getNameOfReported(u.getId())) {
                modelPDFReported.addRow(new String[] { c.getName(), c.getSymbol(),
                        String.valueOf(c.getStockPrice().doubleValue()),
                        Integer.toString(c.getNumberOwned()) });
            }
            jTableReport.setModel(modelPDFReported);
            PdfPTable pdfTableReport = new PdfPTable(jTableReport.getColumnCount());

            for (int i = 0; i < jTableReport.getColumnCount(); i++) {
                pdfTableReport.addCell(jTableReport.getColumnName(i));
            }
            //extracting data from the JTable and inserting it to PdfPTable
            for (int rows = 0; rows < jTableReport.getRowCount(); rows++) {
                for (int cols = 0; cols < jTableReport.getColumnCount(); cols++) {
                    pdfTableReport.addCell(jTableReport.getModel().getValueAt(rows, cols).toString());
                }
            }
            section2.add(blank);
            section2.add(pdfTableReport);
            section2.add(blank);
            //End of doc for a single employee
            document.add(chapter);

            numEMployees++;

        }
        Chapter ban = new Chapter(new Paragraph(new Phrase("Prohibited Companies :\n\n", font1)),
                ++numEMployees);

        com.itextpdf.text.List bannedCompanies = new List(List.ORDERED);
        for (String lii : SQLConnectMana.getBannedCompForAll()) {
            bannedCompanies.add(new com.itextpdf.text.ListItem(lii));
        }
        ban.add(bannedCompanies);
        document.add(ban);
        document.close();
    } catch (DocumentException | FileNotFoundException e) {
        System.err.println("Sorry Problem in pdf.\n" + e);
    }

}

From source file:com.ftt.gui.FrameFormation.java

private void pdf1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pdf1ActionPerformed

    if (nomf.getText() == null || descriptionf.getText() == null || "".equals(lieux.getText())
            || dateclot.getDate() == null || dateov.getDate() == null) {
        JOptionPane.showMessageDialog(this, "Vrifier les champs !");
    } else {//w w w.  j a  v a2s . c  o m
        SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy");
        String val1 = lieux.getText();
        String val2 = formateur.format(dateov.getDate());
        String val3 = formateur.format(dateclot.getDate());
        String val4 = combocible.getSelectedItem().toString();
        String val5 = nomf.getText();
        String val6 = descriptionf.getText();
        Document document = new Document();

        try {
            PdfWriter.getInstance(document, new FileOutputStream("rapport.pdf"));

            document.open();

            com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png");
            document.add(image);
            document.add(new Paragraph("Liste des formations",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD)));
            document.add(new Paragraph(formateur.format(new Date())));
            String val322 = formateur.format(new Date());
            document.add(new Paragraph("                    "));

            PdfPTable table = new PdfPTable(2);
            PdfPCell cell = new PdfPCell(new Paragraph("formations"));
            cell.setColspan(4);
            cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
            cell.setBackgroundColor(BaseColor.BLUE);
            table.addCell(cell);
            table.addCell("Nom formation");
            table.addCell(val5);
            table.addCell(cell);
            table.addCell("Description");
            table.addCell(val6);
            table.addCell(cell);
            table.addCell("Lieux");
            table.addCell(val1);
            table.addCell("Date d'ouverture");
            table.addCell(val2);
            table.addCell("Date de cloture");
            table.addCell(val3);
            table.addCell("Cible");
            table.addCell(val4);
            document.add(table);
            document.add(new Paragraph("    "));
            document.add(new Paragraph("    "));
            document.add(new Paragraph("Responsable des formations"));
            document.add(new Paragraph("Federation Tunisenne de Tennis"));
            document.close();
            JOptionPane.showMessageDialog(null, "Rapport Enregistrer");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
    }
}

From source file:com.ftt.gui.FrameFormation.java

private void pdf2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pdf2ActionPerformed

    FormationDAO fd = new FormationDAO();
    ArrayList<Formation> formations = (ArrayList<Formation>) fd.select();
    SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy");

    Document document = new Document();

    try {/*www.j ava  2s  .  c om*/
        PdfWriter.getInstance(document, new FileOutputStream("rapport_formations.pdf"));

        document.open();

        com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png");
        document.add(image);
        document.add(new Paragraph("Liste des formations",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD)));
        document.add(new Paragraph("   "));
        document.add(new Paragraph("    "));
        for (int i = 0; i < formations.size(); i++) {
            document.add(new Paragraph("    "));
            int val = formations.get(i).getId();
            String val1 = formations.get(i).getLieux();
            String val2 = formations.get(i).getDateOuverture();
            String val3 = formations.get(i).getDateCloture();
            String val4 = formations.get(i).getCible();
            String val5 = formations.get(i).getNom();
            String val6 = formations.get(i).getDescription();

            PdfPTable table = new PdfPTable(2);
            PdfPCell cell = new PdfPCell(new Paragraph("formation " + val));
            cell.setColspan(4);
            cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
            cell.setBackgroundColor(BaseColor.GRAY);
            table.addCell(cell);
            table.addCell("Nom formation");
            table.addCell(val5);
            table.addCell("Description");
            table.addCell(val6);
            table.addCell("Lieux");
            table.addCell(val1);
            table.addCell("Date d'ouverture");
            table.addCell(val2);
            table.addCell("Date de cloture");
            table.addCell(val3);
            table.addCell("Cible");
            table.addCell(val4);
            document.add(table);
        }

        document.add(new Paragraph("    "));
        document.add(new Paragraph("    "));
        document.add(new Paragraph("Responsable des formations"));
        document.add(new Paragraph("Federation Tunisenne de Tennis"));
        document.close();
        JOptionPane.showMessageDialog(null, "Rapport Enregistrer");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }
}

From source file:com.ftt.gui.FrameJoueur.java

private void pdf2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pdf2ActionPerformed

    JoueurDAO fd = new JoueurDAO();
    ArrayList<Joueur> joueurs = (ArrayList<Joueur>) fd.select_trie_par_club();
    SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy");

    Document document = new Document();

    try {/*from w ww  .  j  ava  2  s .co  m*/
        PdfWriter.getInstance(document, new FileOutputStream("rapport_joueurs.pdf"));

        document.open();

        com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png");
        document.add(image);
        document.add(new Paragraph("Liste des joueurs",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD)));
        document.add(new Paragraph("   "));

        for (int i = 0; i < joueurs.size(); i++) {
            document.add(new Paragraph("    "));
            document.add(new Paragraph(joueurs.get(i).getNom_club()));
            document.add(new Paragraph("   "));
            Integer val = joueurs.get(i).getId();
            String val1 = joueurs.get(i).getNomJoueur();
            String val2 = joueurs.get(i).getPrenomJoueur();
            String val3 = joueurs.get(i).getDateNaissance();
            String val4 = joueurs.get(i).getCarriere();
            String val5 = joueurs.get(i).getSexe();
            Integer val6 = joueurs.get(i).getPoints();
            PdfPTable table = new PdfPTable(2);
            PdfPCell cell = new PdfPCell(new Paragraph("Joueur id: " + val));
            cell.setColspan(4);
            cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_LEFT);
            cell.setBackgroundColor(BaseColor.GRAY);
            table.addCell(cell);
            table.addCell("Nom");
            table.addCell(val1);
            table.addCell("Prenom");
            table.addCell(val2);
            table.addCell("Date de naissance");
            table.addCell(val3);
            table.addCell("Carriere");
            table.addCell(val4);
            table.addCell("sexe");
            table.addCell(val5);
            table.addCell("points");
            table.addCell(val6.toString());
            document.add(table);
        }

        document.add(new Paragraph("    "));
        document.add(new Paragraph("    "));

        document.add(new Paragraph("Federation Tunisenne de Tennis"));
        document.close();
        JOptionPane.showMessageDialog(null, "Rapport Enregistrer");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }
}

From source file:com.gadroves.gsisinve.controller.FacturarController.java

private void createItemsTable(Document doc, TbFacturaVenta facturaVenta) throws DocumentException {
    PdfPTable table = new PdfPTable(4);

    PdfPCell c1 = new PdfPCell(new Phrase("Descripcion"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);//w  w w  .j a v  a  2 s.  c om

    c1 = new PdfPCell(new Phrase("Cantidad"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Precio Unitario"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Valor"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    //table.setHeaderRows(1);
    PdfPCell desc;
    PdfPCell cant;
    PdfPCell pu;
    PdfPCell val;
    for (TbLineaFac lineaFac : facturaVenta.getTbLineaFacsById()) {
        desc = new PdfPCell(new Phrase(lineaFac.getDescripcion()));
        cant = new PdfPCell(new Phrase(String.valueOf(lineaFac.getQuant())));
        pu = new PdfPCell(new Phrase(String.valueOf(lineaFac.getP_unitario())));
        val = new PdfPCell(new Phrase(String.valueOf(lineaFac.getTotal())));
        table.addCell(desc);
        table.addCell(cant);
        table.addCell(pu);
        table.addCell(val);
    }
    float[] columnWidths = new float[] { 40f, 10f, 10f, 10f };
    table.setWidths(columnWidths);
    doc.add(table);

}