Example usage for com.itextpdf.text.pdf PdfPCell setColspan

List of usage examples for com.itextpdf.text.pdf PdfPCell setColspan

Introduction

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

Prototype

public void setColspan(int colspan) 

Source Link

Document

Setter for property colspan.

Usage

From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java

License:Open Source License

private void setTableCaptionStyle(BaseColor summaryBackgroundColor, PdfPCell cell) {
    cell.setBorderWidth(0.0f);/*  w w w  . j a  v  a 2 s  . co  m*/
    cell.setBackgroundColor(summaryBackgroundColor);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setPaddingTop(5.0f);
    cell.setPaddingRight(10.0f);
    cell.setPaddingBottom(5.0f);
    cell.setPaddingLeft(10.0f);
    cell.setColspan(2);
}

From source file:edu.ksu.cs.a4vm.bse.reporter.Reporter.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {

    JFileChooser chooser = new JFileChooser();
    int option = chooser.showSaveDialog(null);
    if (option == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile() != null) {
            File3 = chooser.getSelectedFile().getAbsolutePath();
        }/* w w  w .  j  a v  a2  s .c o  m*/

        try {
            br1 = new BufferedReader(new FileReader(f));
            BufferedReader b1 = new BufferedReader(new FileReader(f));
        } catch (FileNotFoundException ex) {

        }

        String line = "";

        bull1 = new String[number_of_rows - 1][];
        int k = 0;
        BufferedReader br3 = null;
        try {
            br3 = new BufferedReader(new FileReader(f));
        } catch (FileNotFoundException ex) {
        }
        try {
            while ((line = br3.readLine()) != null) {

                // use comma as separator
                String Bull[] = line.split(",");
                if (k != 0) {
                    System.out.println(Bull.length);
                    bull1[k - 1] = new String[Bull.length];
                    for (int j = 0; j < Bull.length; j++) {

                        bull1[k - 1][j] = Bull[j];

                    }
                }
                k++;
            }
        } catch (IOException ex) {
        }
        Document doc = new Document();
        PdfWriter docWriter = null;

        DecimalFormat df = new DecimalFormat("0.00");

        try {

            //special font sizes
            Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0));
            Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 6);
            Font bfBold20 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
            Font bfBold25 = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.BOLD);
            //file path

            docWriter = PdfWriter.getInstance(doc, new FileOutputStream(File3));

            //document header attributes
            doc.addAuthor("Shubh Chopra");
            doc.addCreationDate();
            doc.addProducer();
            doc.addCreator("Shubh Chopra");
            doc.addTitle("BES");
            doc.setPageSize(PageSize.LETTER.rotate());

            //open document
            doc.open();
            //create a paragraph
            Paragraph paragraph = new Paragraph("BULL EVALUATION\n\n");
            paragraph.setFont(bfBold25);
            paragraph.setAlignment(Element.ALIGN_CENTER);

            Image img = Image.getInstance("VETMED.png");

            img.scaleToFit(300f, 150f);
            doc.add(paragraph);
            PdfPTable table1 = new PdfPTable(2);
            table1.setWidthPercentage(100);
            PdfPCell cell = new PdfPCell(img);
            cell.setBorder(PdfPCell.NO_BORDER);
            table1.addCell(cell);

            String temp1 = "\tOwner: " + bull1[1][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64]
                    + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: "
                    + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n";

            table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT));
            doc.add(table1);

            if (dlm3.size() == 1) {
                String str;
                str = dlm3.get(0).toString();
                String[] parts = str.split(":");
                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                String[][] temp = new String[25][6];
                temp[0][0] = "Tag";
                temp[0][1] = bull1[row][7];
                temp[0][2] = "Comments";
                temp[0][3] = "";
                temp[0][4] = "Total Count";
                temp[0][5] = "";
                temp[1][0] = "Tatoo";
                temp[1][1] = bull1[row][8];
                temp[1][2] = "All Normal";
                temp[1][3] = "Yes";
                temp[2][0] = "RFID";
                temp[2][1] = bull1[row][6];
                temp[2][2] = "Eyes";
                temp[2][3] = bull1[row][10];
                temp[3][0] = "Lot#";
                temp[3][1] = bull1[row][5];
                temp[3][2] = "Feet";
                temp[3][3] = bull1[row][12];
                temp[4][0] = "Brand";
                temp[4][1] = bull1[row][2];
                temp[4][2] = "Legs";
                temp[4][3] = bull1[row][14];
                temp[5][0] = "Date of Birth";
                temp[5][1] = bull1[row][4];
                temp[5][2] = "Testicals";
                temp[5][3] = bull1[row][16];
                temp[6][0] = "Age";
                temp[6][1] = bull1[row][0];
                temp[6][2] = "Accessory Sex Glands";
                temp[6][3] = bull1[row][18];
                temp[7][0] = "Breed";
                temp[7][1] = bull1[row][3];
                temp[7][2] = "Inguinal";
                temp[7][3] = bull1[row][20];
                temp[8][0] = "Other";
                temp[8][1] = bull1[row][9];
                temp[8][2] = "Scrotal";
                temp[8][3] = bull1[row][22];
                temp[9][0] = "Clinic Info";
                temp[9][1] = "xx";
                temp[9][2] = "Epidydimides";
                temp[9][3] = bull1[row][24];
                temp[10][4] = "Measurements";
                temp[10][5] = "xx";
                temp[10][0] = "Clinic Name";
                temp[10][1] = bull1[row][73];
                temp[10][2] = "Penis";
                temp[10][3] = bull1[row][26];
                temp[11][4] = "Scrotal Cirumference";
                temp[11][5] = bull1[row][54];
                temp[11][0] = "Veterinarian Name";
                temp[11][1] = bull1[row][74] + " " + bull1[row][74];
                temp[11][2] = "Prepuce";
                temp[11][3] = bull1[row][28];
                temp[12][4] = "Body Condition";
                temp[12][5] = bull1[row][47];
                temp[12][0] = "Address";
                temp[12][1] = bull1[row][66] + " " + bull1[row][67];
                temp[12][2] = "Scrotum";
                temp[12][3] = bull1[row][30];
                temp[13][4] = "Pelvic X Measure";
                temp[13][5] = bull1[row][52];
                temp[13][0] = "City";
                temp[13][1] = bull1[row][68];
                temp[13][2] = "Sex Drive";
                temp[13][3] = "xx";
                temp[14][4] = "Pelvic Y Measure";
                temp[14][5] = bull1[row][53];
                temp[14][0] = "State";
                temp[14][1] = bull1[row][71];
                temp[14][2] = "Breeding seasons used";
                temp[14][3] = bull1[row][40];
                temp[15][4] = "Hip Hight";
                temp[15][5] = bull1[row][50];
                temp[15][0] = "Zip Code";
                temp[15][1] = bull1[row][72];
                temp[15][2] = "Performance last season";
                temp[15][3] = bull1[row][38];
                temp[16][4] = "Frame Score";
                temp[16][5] = bull1[row][49];
                temp[16][0] = "Email";
                temp[16][1] = bull1[row][69];
                temp[16][2] = "Single or Multi sire";
                temp[16][3] = bull1[row][41];
                temp[17][4] = "Other";
                temp[17][5] = bull1[row][48];
                temp[17][0] = "Phone";
                temp[17][1] = bull1[row][70];
                temp[17][2] = "Other";
                temp[17][3] = bull1[row][39];
                temp[18][4] = "Motility";
                temp[18][5] = "xx";
                temp[18][0] = "Classification";
                temp[18][1] = bull1[row][35];
                temp[18][2] = "Comments";
                temp[18][3] = bull1[row][37];
                temp[19][4] = "Individual Motility";
                temp[19][5] = bull1[row][45];
                temp[19][0] = "Comments";
                temp[19][1] = bull1[row][36];
                temp[19][2] = "";
                temp[19][3] = "";
                temp[20][4] = "Motility %";
                temp[20][5] = bull1[row][46];
                temp[20][0] = "";
                temp[20][1] = "";
                temp[20][2] = "";
                temp[20][3] = "";
                temp[21][4] = "Gross Motility";
                temp[21][5] = bull1[row][44];
                temp[21][0] = "";
                temp[21][1] = "";
                temp[21][2] = "";
                temp[21][3] = "";
                for (int i = 9; i <= 29; i += 2) {
                    if (bull1[row][i].equals("FALSE")) {
                        temp[1][4] = "No";
                        break;
                    }
                }
                int i;
                int total = 0;
                for (i = 77; i < header.length && i < bull1[row].length; i++) {

                    temp[i - 76][4] = header[i].split("_")[1];
                    temp[i - 76][5] = bull1[row][i];
                    total += Integer.parseInt(bull1[row][i]);

                }
                temp[0][5] = Integer.toString(total);
                for (int j = i; j <= 85; j++) {
                    temp[j - 76][4] = "";
                    temp[j - 76][5] = "";
                }
                PdfPTable table = new PdfPTable(6);
                PdfPCell cell11, cell12, cell13;
                cell11 = new PdfPCell(
                        new Phrase("Bull Info", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
                cell11.setColspan(2);
                cell11.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell11.setVerticalAlignment(Element.ALIGN_CENTER);

                table.addCell(cell11);
                cell12 = new PdfPCell(
                        new Phrase("Physical Exam", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
                cell12.setColspan(2);
                cell12.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell12.setVerticalAlignment(Element.ALIGN_CENTER);

                table.addCell(cell12);
                cell13 = new PdfPCell(
                        new Phrase("Morphology", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
                cell13.setColspan(2);
                cell13.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell13.setVerticalAlignment(Element.ALIGN_CENTER);

                table.addCell(cell13);
                for (int l = 0; l <= 21; l++) {
                    for (int j = 0; j < 6; j++) {
                        // System.out.println(l+" "+j);
                        if (!temp[l][j].equals("xx") && temp[l][j] != null) {
                            cell = new PdfPCell(
                                    new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 10)));

                            cell.setBorder(PdfPCell.NO_BORDER);
                            if ((l == 9 && j == 0) || (l == 13 && j == 2) || (l == 10 && j == 4)
                                    || (l == 18 && j == 4)) {
                                cell = new PdfPCell(new Phrase(temp[l][j],
                                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
                                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                                cell.setVerticalAlignment(Element.ALIGN_CENTER);
                                cell.setColspan(2);
                            }
                            table.addCell(cell);
                        }
                    }
                }
                table.setWidthPercentage(90f);
                Reporter re;
                re = new Reporter();
                doc.add(table);
                if (jCheckBox2.isSelected() || jCheckBox1.isSelected())
                    doc.newPage();
            }

            else {

                //specify column widths
                int temp = dlm2.size();

                float[] columnWidths = new float[temp];
                for (int x = 0; x < columnWidths.length; x++) {
                    columnWidths[x] = 2f;
                }

                //create PDF table with the given widths
                PdfPTable table = new PdfPTable(columnWidths);
                // set table width a percentage of the page width
                table.setWidthPercentage(90f);
                Reporter re;
                re = new Reporter();
                re.insertCell(table, "Bull Info", Element.ALIGN_CENTER, 1, bfBold12);
                for (int i = 0; i < dlm2.size(); i++) {
                    String[] parts = dlm2.get(i).toString().split(": ");
                    String part2 = parts[1];

                    re.insertCell(table, newhead[Integer.parseInt(part2)], Element.ALIGN_CENTER, 1, bfBold12);
                }

                table.setHeaderRows(1);
                //insert an empty row

                //create section heading by cell merging
                //just some random data to fill 
                for (int x = 0; x < dlm3.size(); x++) {
                    String str = dlm3.get(x).toString();
                    //System.out.println(str);
                    String[] parts = str.split(":");
                    String part2 = parts[1];
                    // System.out.println(part2);

                    int row = Integer.parseInt(part2) - 1;
                    re.insertCell(table, Bulls[row], Element.ALIGN_CENTER, 1, bf12);
                    for (int i = 0; i < dlm2.getSize(); i++) {

                        for (int j = 0; j < header.length && j < bull1[row].length; j++) {
                            String str1 = dlm2.get(i).toString();
                            String[] p1 = str1.split(": ");
                            String p2 = p1[0];
                            if (p2.equals(header[j])) {
                                re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12);
                            }
                        }
                    }
                    // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12);
                }

                doc.add(table);
            }

            if (jCheckBox2.isSelected()) {
                DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
                for (int i = 0; i < dlm3.size(); i++) {

                    String str = dlm3.get(i).toString();
                    System.out.println(str);
                    String[] parts = str.split(":");
                    String part1 = parts[0];
                    String part2 = parts[1];
                    System.out.println(part2);
                    int row = Integer.parseInt(part2) - 1;
                    float total = (float) 0.0;
                    for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                        if (bull1[row][j].equals("")) {
                            continue;
                        } else {
                            total += Integer.parseInt(bull1[row][j]);
                        }

                    }
                    System.out.println(total);
                    for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                        if (!bull1[row][j].equals("")) {

                            String[] Parts = header[j].split("_");
                            String Part2 = Parts[1];
                            dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1);
                        } else {
                            dataSet.setValue(0, "Percent", header[j]);

                        }
                    }

                }
                JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology",
                        "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false);

                if (dlm3.size() > 12) {
                    doc.newPage();
                }
                PdfContentByte contentByte = docWriter.getDirectContent();
                PdfTemplate template = contentByte.createTemplate(325, 250);
                PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
                Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

                chart.draw(graphics2d, rectangle2d);

                graphics2d.dispose();
                contentByte.addTemplate(template, 0, 0);
            }
            if (jCheckBox1.isSelected()) {

                for (int i = 0; i < dlm3.size(); i++) {
                    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
                    String str = dlm3.get(i).toString();
                    System.out.println(str);
                    String[] parts = str.split(":");
                    String part1 = parts[0];
                    String part2 = parts[1];
                    System.out.println(part2);
                    int row = Integer.parseInt(part2) - 1;
                    float total = (float) 0.0;
                    for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                        if (bull1[row][j].equals("")) {
                            continue;
                        } else {
                            total += Integer.parseInt(bull1[row][j]);
                        }

                    }
                    System.out.println(total);
                    for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                        if (!bull1[row][j].equals("")) {

                            String[] Parts = header[j].split("_");
                            String Part2 = Parts[1];
                            dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2);
                        } else {
                            dataSet.setValue(0, "Percent", header[j]);

                        }
                    }
                    JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1,
                            "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false);
                    if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) {
                        doc.newPage();
                    }
                    PdfContentByte contentByte = docWriter.getDirectContent();
                    PdfTemplate template = contentByte.createTemplate(325, 250);
                    PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
                    Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

                    chart.draw(graphics2d, rectangle2d);

                    graphics2d.dispose();
                    contentByte.addTemplate(template, 0, 0);

                    doc.newPage();
                }
            }

        } catch (DocumentException dex) {
            dex.printStackTrace();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (doc != null) {
                //close the document
                doc.close();
            }
            if (docWriter != null) {
                //close the writer
                docWriter.close();
            }

        }
    }
    // TODO add your handling code here:

}

From source file:edu.ksu.cs.a4vm.bse.reporter.Reporter.java

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    // build a controller
    SwingController controller = new SwingController();

    // Build a SwingViewFactory configured with the controller
    SwingViewBuilder factory = new SwingViewBuilder(controller);

    // Use the factory to build a JPanel that is pre-configured
    //with a complete, active Viewer UI.
    JPanel viewerComponentPanel = factory.buildViewerPanel();

    // add copy keyboard command
    ComponentKeyBinding.install(controller, viewerComponentPanel);

    // add interactive mouse link annotation support via callback
    controller.getDocumentViewController().setAnnotationCallback(
            new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController()));

    // Create a JFrame to display the panel in
    JFrame window = new JFrame("Using the Viewer Component");
    window.getContentPane().add(viewerComponentPanel);
    window.pack();/*from w w  w .  ja v  a2s.  co  m*/
    window.setVisible(true);

    String Path;
    JFileChooser chooser = new JFileChooser();
    FileSystemView view = chooser.getFileSystemView();
    Path = view.getDefaultDirectory() + "/reporter.pdf";

    try {
        br1 = new BufferedReader(new FileReader(f));
        BufferedReader b1 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {

    }

    String line = "";

    bull1 = new String[number_of_rows - 1][];
    int k = 0;
    BufferedReader br3 = null;
    try {
        br3 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {
    }
    try {
        while ((line = br3.readLine()) != null) {

            // use comma as separator
            String Bull[] = line.split(",");
            if (k != 0) {
                System.out.println(Bull.length);
                bull1[k - 1] = new String[Bull.length];
                for (int j = 0; j < Bull.length; j++) {

                    bull1[k - 1][j] = Bull[j];

                }
            }
            k++;
        }
    } catch (IOException ex) {
    }
    Document doc = new Document();
    PdfWriter docWriter = null;

    DecimalFormat df = new DecimalFormat("0.00");

    try {

        //special font sizes
        Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0));
        Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 6);
        Font bfBold20 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);

        //file path
        docWriter = PdfWriter.getInstance(doc, new FileOutputStream(Path));

        //document header attributes
        doc.addAuthor("Shubh Chopra");
        doc.addCreationDate();
        doc.addProducer();
        doc.addCreator("Shubh Chopra");
        doc.addTitle("BES");
        doc.setPageSize(PageSize.LETTER.rotate());

        //open document
        doc.open();
        //create a paragraph
        Paragraph paragraph = new Paragraph("BULL EVALUATION\n\n");
        paragraph.setFont(bfBold20);
        paragraph.setAlignment(Element.ALIGN_CENTER);

        Image img = Image.getInstance("VETMED.png");

        img.scaleToFit(300f, 150f);
        doc.add(paragraph);
        PdfPTable table1 = new PdfPTable(2);
        table1.setWidthPercentage(100);
        PdfPCell cell = new PdfPCell(img);
        cell.setBorder(PdfPCell.NO_BORDER);
        table1.addCell(cell);

        String temp1 = "\tOwner: " + bull1[1][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64]
                + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: "
                + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n";
        table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT));
        doc.add(table1);

        if (dlm3.size() == 1) {
            String str;
            str = dlm3.get(0).toString();
            String[] parts = str.split(":");
            String part2 = parts[1];
            System.out.println(part2);
            int row = Integer.parseInt(part2) - 1;
            String[][] temp = new String[25][6];
            temp[0][0] = "Tag";
            temp[0][1] = bull1[row][7];
            temp[0][2] = "Comments";
            temp[0][3] = "";
            temp[0][4] = "Total Count";
            temp[0][5] = "";
            temp[1][0] = "Tatoo";
            temp[1][1] = bull1[row][8];
            temp[1][2] = "All Normal";
            temp[1][3] = "Yes";
            temp[2][0] = "RFID";
            temp[2][1] = bull1[row][6];
            temp[2][2] = "Eyes";
            temp[2][3] = bull1[row][10];
            temp[3][0] = "Lot#";
            temp[3][1] = bull1[row][5];
            temp[3][2] = "Feet";
            temp[3][3] = bull1[row][12];
            temp[4][0] = "Brand";
            temp[4][1] = bull1[row][2];
            temp[4][2] = "Legs";
            temp[4][3] = bull1[row][14];
            temp[5][0] = "Date of Birth";
            temp[5][1] = bull1[row][4];
            temp[5][2] = "Testicals";
            temp[5][3] = bull1[row][16];
            temp[6][0] = "Age";
            temp[6][1] = bull1[row][0];
            temp[6][2] = "Accessory Sex Glands";
            temp[6][3] = bull1[row][18];
            temp[7][0] = "Breed";
            temp[7][1] = bull1[row][3];
            temp[7][2] = "Inguinal";
            temp[7][3] = bull1[row][20];
            temp[8][0] = "Other";
            temp[8][1] = bull1[row][9];
            temp[8][2] = "Scrotal";
            temp[8][3] = bull1[row][22];
            temp[9][0] = "Clinic Info";
            temp[9][1] = "xx";
            temp[9][2] = "Epidydimides";
            temp[9][3] = bull1[row][24];
            temp[10][4] = "Measurements";
            temp[10][5] = "xx";
            temp[10][0] = "Clinic Name";
            temp[10][1] = bull1[row][73];
            temp[10][2] = "Penis";
            temp[10][3] = bull1[row][26];
            temp[11][4] = "Scrotal Cirumference";
            temp[11][5] = bull1[row][54];
            temp[11][0] = "Veterinarian Name";
            temp[11][1] = bull1[row][74] + " " + bull1[row][74];
            temp[11][2] = "Prepuce";
            temp[11][3] = bull1[row][28];
            temp[12][4] = "Body Condition";
            temp[12][5] = bull1[row][47];
            temp[12][0] = "Address";
            temp[12][1] = bull1[row][66] + " " + bull1[row][67];
            temp[12][2] = "Scrotum";
            temp[12][3] = bull1[row][30];
            temp[13][4] = "Pelvic X Measure";
            temp[13][5] = bull1[row][52];
            temp[13][0] = "City";
            temp[13][1] = bull1[row][68];
            temp[13][2] = "Sex Drive";
            temp[13][3] = "xx";
            temp[14][4] = "Pelvic Y Measure";
            temp[14][5] = bull1[row][53];
            temp[14][0] = "State";
            temp[14][1] = bull1[row][71];
            temp[14][2] = "Breeding seasons used";
            temp[14][3] = bull1[row][40];
            temp[15][4] = "Hip Hight";
            temp[15][5] = bull1[row][50];
            temp[15][0] = "Zip Code";
            temp[15][1] = bull1[row][72];
            temp[15][2] = "Performance last season";
            temp[15][3] = bull1[row][38];
            temp[16][4] = "Frame Score";
            temp[16][5] = bull1[row][49];
            temp[16][0] = "Email";
            temp[16][1] = bull1[row][69];
            temp[16][2] = "Single or Multi sire";
            temp[16][3] = bull1[row][41];
            temp[17][4] = "Other";
            temp[17][5] = bull1[row][48];
            temp[17][0] = "Phone";
            temp[17][1] = bull1[row][70];
            temp[17][2] = "Other";
            temp[17][3] = bull1[row][39];
            temp[18][4] = "Motility";
            temp[18][5] = "xx";
            temp[18][0] = "Classification";
            temp[18][1] = bull1[row][35];
            temp[18][2] = "Comments";
            temp[18][3] = bull1[row][37];
            temp[19][4] = "Individual Motility";
            temp[19][5] = bull1[row][45];
            temp[19][0] = "Comments";
            temp[19][1] = bull1[row][36];
            temp[19][2] = "";
            temp[19][3] = "";
            temp[20][4] = "Motility %";
            temp[20][5] = bull1[row][46];
            temp[20][0] = "";
            temp[20][1] = "";
            temp[20][2] = "";
            temp[20][3] = "";
            temp[21][4] = "Gross Motility";
            temp[21][5] = bull1[row][44];
            temp[21][0] = "";
            temp[21][1] = "";
            temp[21][2] = "";
            temp[21][3] = "";
            for (int i = 9; i <= 29; i += 2) {
                if (bull1[row][i].equals("FALSE")) {
                    temp[1][4] = "No";
                    break;
                }
            }
            int i;
            int total = 0;
            for (i = 77; i < header.length && i < bull1[row].length; i++) {

                temp[i - 76][4] = header[i].split("_")[1];
                temp[i - 76][5] = bull1[row][i];
                total += Integer.parseInt(bull1[row][i]);

            }
            temp[0][5] = Integer.toString(total);
            for (int j = i; j <= 85; j++) {
                temp[j - 76][4] = "";
                temp[j - 76][5] = "";
            }
            PdfPTable table = new PdfPTable(6);
            PdfPCell cell11, cell12, cell13;
            cell11 = new PdfPCell(new Phrase("Bull Info", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
            cell11.setColspan(2);
            cell11.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell11.setVerticalAlignment(Element.ALIGN_CENTER);

            table.addCell(cell11);
            cell12 = new PdfPCell(
                    new Phrase("Physical Exam", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
            cell12.setColspan(2);
            cell12.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell12.setVerticalAlignment(Element.ALIGN_CENTER);

            table.addCell(cell12);
            cell13 = new PdfPCell(new Phrase("Morphology", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
            cell13.setColspan(2);
            cell13.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell13.setVerticalAlignment(Element.ALIGN_CENTER);

            table.addCell(cell13);
            for (int l = 0; l <= 21; l++) {
                for (int j = 0; j < 6; j++) {
                    // System.out.println(l+" "+j);
                    if (!temp[l][j].equals("xx") && temp[l][j] != null) {
                        cell = new PdfPCell(
                                new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 10)));

                        cell.setBorder(PdfPCell.NO_BORDER);
                        if ((l == 9 && j == 0) || (l == 13 && j == 2) || (l == 10 && j == 4)
                                || (l == 18 && j == 4)) {
                            cell = new PdfPCell(
                                    new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
                            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                            cell.setVerticalAlignment(Element.ALIGN_CENTER);
                            cell.setColspan(2);
                        }
                        table.addCell(cell);
                    }
                }
            }
            table.setWidthPercentage(90f);
            Reporter re;
            re = new Reporter();
            doc.add(table);
            if (jCheckBox2.isSelected() || jCheckBox1.isSelected())
                doc.newPage();
        } else {

            //specify column widths
            int temp = dlm2.size();

            float[] columnWidths = new float[temp + 1];
            for (int x = 0; x < columnWidths.length; x++) {
                columnWidths[x] = 2f;
            }

            //create PDF table with the given widths
            PdfPTable table = new PdfPTable(columnWidths);
            // set table width a percentage of the page width
            table.setWidthPercentage(90f);
            Reporter re;
            re = new Reporter();
            re.insertCell(table, "Bull Info", Element.ALIGN_CENTER, 1, bfBold12);
            for (int i = 0; i < dlm2.size(); i++) {
                String[] parts = dlm2.get(i).toString().split(": ");
                String part2 = parts[1];

                re.insertCell(table, newhead[Integer.parseInt(part2)], Element.ALIGN_CENTER, 1, bfBold12);
            }

            table.setHeaderRows(1);
            //insert an empty row

            //create section heading by cell merging
            //just some random data to fill 
            for (int x = 0; x < dlm3.size(); x++) {
                String str = dlm3.get(x).toString();
                //System.out.println(str);
                String[] parts = str.split(":");
                String part2 = parts[1];
                // System.out.println(part2);

                int row = Integer.parseInt(part2) - 1;
                re.insertCell(table, Bulls[row], Element.ALIGN_CENTER, 1, bf12);
                for (int i = 0; i < dlm2.getSize(); i++) {

                    for (int j = 0; j < header.length && j < bull1[row].length; j++) {
                        String str1 = dlm2.get(i).toString();
                        String[] p1 = str1.split(": ");
                        String p2 = p1[0];
                        if (p2.equals(header[j])) {
                            re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12);
                        }
                    }
                }
                // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12);
            }

            doc.add(table);
        }
        if (jCheckBox2.isSelected()) {
            DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
            for (int i = 0; i < dlm3.size(); i++) {

                String str = dlm3.get(i).toString();
                System.out.println(str);
                String[] parts = str.split(":");
                String part1 = parts[0];
                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                float total = (float) 0.0;
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                    if (bull1[row][j].equals("")) {
                        continue;
                    } else {
                        total += Integer.parseInt(bull1[row][j]);
                    }

                }
                System.out.println(total);
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                    if (!bull1[row][j].equals("")) {

                        String[] Parts = header[j].split("_");
                        String Part2 = Parts[1];
                        dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1);
                    } else {
                        dataSet.setValue(0, "Percent", header[j]);

                    }
                }

            }
            JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology",
                    "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false);

            if (dlm3.size() > 12) {
                doc.newPage();
            }
            PdfContentByte contentByte = docWriter.getDirectContent();
            PdfTemplate template = contentByte.createTemplate(325, 250);
            PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
            Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

            chart.draw(graphics2d, rectangle2d);

            graphics2d.dispose();
            contentByte.addTemplate(template, 0, 0);
        }
        if (jCheckBox1.isSelected()) {

            for (int i = 0; i < dlm3.size(); i++) {
                DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
                String str = dlm3.get(i).toString();
                System.out.println(str);
                String[] parts = str.split(":");
                String part1 = parts[0];
                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                float total = (float) 0.0;
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                    if (bull1[row][j].equals("")) {
                        continue;
                    } else {
                        total += Integer.parseInt(bull1[row][j]);
                    }

                }
                System.out.println(total);
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                    if (!bull1[row][j].equals("")) {

                        String[] Parts = header[j].split("_");
                        String Part2 = Parts[1];
                        dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2);
                    } else {
                        dataSet.setValue(0, "Percent", header[j]);

                    }
                }
                JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1,
                        "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false);
                if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) {
                    doc.newPage();
                }
                PdfContentByte contentByte = docWriter.getDirectContent();
                PdfTemplate template = contentByte.createTemplate(325, 250);
                PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
                Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

                chart.draw(graphics2d, rectangle2d);

                graphics2d.dispose();
                contentByte.addTemplate(template, 0, 0);

                doc.newPage();
            }
        }

    } catch (DocumentException dex) {
        dex.printStackTrace();
        JOptionPane.showMessageDialog(null, dex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(null, "ex");
    } finally {
        if (doc != null) {
            //close the document
            doc.close();
        }
        if (docWriter != null) {
            //close the writer
            docWriter.close();
        }

    }
    controller.openDocument(Path);

}

From source file:edu.ksu.cs.a4vm.bse.reporter.Reporter.java

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {

    // TODO add your handling code here:
    // build a controller
    SwingController controller = new SwingController();

    // Build a SwingViewFactory configured with the controller
    SwingViewBuilder factory = new SwingViewBuilder(controller);

    // Use the factory to build a JPanel that is pre-configured
    //with a complete, active Viewer UI.
    JPanel viewerComponentPanel = factory.buildViewerPanel();

    // add copy keyboard command
    ComponentKeyBinding.install(controller, viewerComponentPanel);

    // add interactive mouse link annotation support via callback
    controller.getDocumentViewController().setAnnotationCallback(
            new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController()));

    // Create a JFrame to display the panel in
    JFrame window = new JFrame("Using the Viewer Component");
    window.getContentPane().add(viewerComponentPanel);
    window.pack();/* w w w .j av  a 2s.co  m*/
    window.setVisible(true);

    String Path;
    JFileChooser fr = new JFileChooser();
    FileSystemView fw = fr.getFileSystemView();
    //    System.out.println(fw.getDefaultDirectory());

    Path = fw.getDefaultDirectory() + "/reporter.pdf";

    try {
        br1 = new BufferedReader(new FileReader(f));
        BufferedReader b1 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {

    }

    String line = "";

    bull1 = new String[number_of_rows - 1][];
    int k = 0;
    BufferedReader br3 = null;
    try {
        br3 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {
    }
    try {
        while ((line = br3.readLine()) != null) {

            // use comma as separator
            String Bull[] = line.split(",");
            if (k != 0) {
                System.out.println(Bull.length);
                bull1[k - 1] = new String[Bull.length];
                for (int j = 0; j < Bull.length; j++) {

                    bull1[k - 1][j] = Bull[j];

                }
            }
            k++;
        }
    } catch (IOException ex) {
    }
    Document doc = new Document();
    PdfWriter docWriter = null;

    DecimalFormat df = new DecimalFormat("0.00");

    try {

        //special font sizes
        Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0));
        Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 6);
        Font bfBold20 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);

        //file path
        docWriter = PdfWriter.getInstance(doc, new FileOutputStream(Path));

        //document header attributes
        doc.addAuthor("Shubh Chopra");
        doc.addCreationDate();
        doc.addProducer();
        doc.addCreator("Shubh Chopra");
        doc.addTitle("BES");
        doc.setPageSize(PageSize.LETTER.rotate());

        //open document
        doc.open();
        //create a paragraph
        Paragraph paragraph = new Paragraph("BULL EVALUATION\n\n");
        paragraph.setFont(bfBold20);
        paragraph.setAlignment(Element.ALIGN_CENTER);

        Image img = Image.getInstance("VETMED.png");

        img.scaleToFit(300f, 150f);
        doc.add(paragraph);
        PdfPTable table1 = new PdfPTable(2);
        table1.setWidthPercentage(100);
        PdfPCell cell = new PdfPCell(img);
        cell.setBorder(PdfPCell.NO_BORDER);
        table1.addCell(cell);

        String temp1 = "\tOwner: " + bull1[1][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64]
                + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: "
                + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n";

        table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT));
        doc.add(table1);
        if (dlm3.size() == 1) {
            String str;
            str = dlm3.get(0).toString();
            String[] parts = str.split(":");
            String part2 = parts[1];
            System.out.println(part2);
            int row = Integer.parseInt(part2) - 1;
            String[][] temp = new String[25][6];
            temp[0][0] = "Tag";
            temp[0][1] = bull1[row][7];
            temp[0][2] = "Comments";
            temp[0][3] = "";
            temp[0][4] = "Total Count";
            temp[0][5] = "";
            temp[1][0] = "Tatoo";
            temp[1][1] = bull1[row][8];
            temp[1][2] = "All Normal";
            temp[1][3] = "Yes";
            temp[2][0] = "RFID";
            temp[2][1] = bull1[row][6];
            temp[2][2] = "Eyes";
            temp[2][3] = bull1[row][10];
            temp[3][0] = "Lot#";
            temp[3][1] = bull1[row][5];
            temp[3][2] = "Feet";
            temp[3][3] = bull1[row][12];
            temp[4][0] = "Brand";
            temp[4][1] = bull1[row][2];
            temp[4][2] = "Legs";
            temp[4][3] = bull1[row][14];
            temp[5][0] = "Date of Birth";
            temp[5][1] = bull1[row][4];
            temp[5][2] = "Testicals";
            temp[5][3] = bull1[row][16];
            temp[6][0] = "Age";
            temp[6][1] = bull1[row][0];
            temp[6][2] = "Accessory Sex Glands";
            temp[6][3] = bull1[row][18];
            temp[7][0] = "Breed";
            temp[7][1] = bull1[row][3];
            temp[7][2] = "Inguinal";
            temp[7][3] = bull1[row][20];
            temp[8][0] = "Other";
            temp[8][1] = bull1[row][9];
            temp[8][2] = "Scrotal";
            temp[8][3] = bull1[row][22];
            temp[9][0] = "Clinic Info";
            temp[9][1] = "xx";
            temp[9][2] = "Epidydimides";
            temp[9][3] = bull1[row][24];
            temp[10][4] = "Measurements";
            temp[10][5] = "xx";
            temp[10][0] = "Clinic Name";
            temp[10][1] = bull1[row][73];
            temp[10][2] = "Penis";
            temp[10][3] = bull1[row][26];
            temp[11][4] = "Scrotal Cirumference";
            temp[11][5] = bull1[row][54];
            temp[11][0] = "Veterinarian Name";
            temp[11][1] = bull1[row][74] + " " + bull1[row][75];
            temp[11][2] = "Prepuce";
            temp[11][3] = bull1[row][28];
            temp[12][4] = "Body Condition";
            temp[12][5] = bull1[row][47];
            temp[12][0] = "Address";
            temp[12][1] = bull1[row][66] + " " + bull1[row][67];
            temp[12][2] = "Scrotum";
            temp[12][3] = bull1[row][30];
            temp[13][4] = "Pelvic X Measure";
            temp[13][5] = bull1[row][52];
            temp[13][0] = "City";
            temp[13][1] = bull1[row][68];
            temp[13][2] = "Sex Drive";
            temp[13][3] = "xx";
            temp[14][4] = "Pelvic Y Measure";
            temp[14][5] = bull1[row][53];
            temp[14][0] = "State";
            temp[14][1] = bull1[row][71];
            temp[14][2] = "Breeding seasons used";
            temp[14][3] = bull1[row][40];
            temp[15][4] = "Hip Hight";
            temp[15][5] = bull1[row][50];
            temp[15][0] = "Zip Code";
            temp[15][1] = bull1[row][72];
            temp[15][2] = "Performance last season";
            temp[15][3] = bull1[row][38];
            temp[16][4] = "Frame Score";
            temp[16][5] = bull1[row][49];
            temp[16][0] = "Email";
            temp[16][1] = bull1[row][69];
            temp[16][2] = "Single or Multi sire";
            temp[16][3] = bull1[row][41];
            temp[17][4] = "Other";
            temp[17][5] = bull1[row][48];
            temp[17][0] = "Phone";
            temp[17][1] = bull1[row][70];
            temp[17][2] = "Other";
            temp[17][3] = bull1[row][39];
            temp[18][4] = "Motility";
            temp[18][5] = "xx";
            temp[18][0] = "Classification";
            temp[18][1] = bull1[row][35];
            temp[18][2] = "Comments";
            temp[18][3] = bull1[row][37];
            temp[19][4] = "Individual Motility";
            temp[19][5] = bull1[row][45];
            temp[19][0] = "Comments";
            temp[19][1] = bull1[row][36];
            temp[19][2] = "";
            temp[19][3] = "";
            temp[20][4] = "Motility %";
            temp[20][5] = bull1[row][46];
            temp[20][0] = "";
            temp[20][1] = "";
            temp[20][2] = "";
            temp[20][3] = "";
            temp[21][4] = "Gross Motility";
            temp[21][5] = bull1[row][44];
            temp[21][0] = "";
            temp[21][1] = "";
            temp[21][2] = "";
            temp[21][3] = "";
            for (int i = 9; i <= 29; i += 2) {
                if (bull1[row][i].equals("FALSE")) {
                    temp[1][4] = "No";
                    break;
                }
            }
            int i;
            int total = 0;
            for (i = 77; i < header.length && i < bull1[row].length; i++) {

                temp[i - 76][4] = header[i].split("_")[1];
                temp[i - 76][5] = bull1[row][i];
                total += Integer.parseInt(bull1[row][i]);

            }
            temp[0][5] = Integer.toString(total);
            for (int j = i; j <= 85; j++) {
                temp[j - 76][4] = "";
                temp[j - 76][5] = "";
            }
            PdfPTable table = new PdfPTable(6);
            PdfPCell cell11, cell12, cell13;
            cell11 = new PdfPCell(new Phrase("Bull Info", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
            cell11.setColspan(2);
            cell11.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell11.setVerticalAlignment(Element.ALIGN_CENTER);

            table.addCell(cell11);
            cell12 = new PdfPCell(
                    new Phrase("Physical Exam", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
            cell12.setColspan(2);
            cell12.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell12.setVerticalAlignment(Element.ALIGN_CENTER);

            table.addCell(cell12);
            cell13 = new PdfPCell(new Phrase("Morphology", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
            cell13.setColspan(2);
            cell13.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell13.setVerticalAlignment(Element.ALIGN_CENTER);

            table.addCell(cell13);
            for (int l = 0; l <= 21; l++) {
                for (int j = 0; j < 6; j++) {
                    // System.out.println(l+" "+j);
                    if (!temp[l][j].equals("xx") && temp[l][j] != null) {
                        cell = new PdfPCell(
                                new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 10)));

                        cell.setBorder(PdfPCell.NO_BORDER);
                        if ((l == 9 && j == 0) || (l == 13 && j == 2) || (l == 10 && j == 4)
                                || (l == 18 && j == 4)) {
                            cell = new PdfPCell(
                                    new Phrase(temp[l][j], FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
                            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                            cell.setVerticalAlignment(Element.ALIGN_CENTER);
                            cell.setColspan(2);
                        }
                        table.addCell(cell);
                    }
                }
            }
            table.setWidthPercentage(90f);
            Reporter re;
            re = new Reporter();
            doc.add(table);
            if (jCheckBox2.isSelected() || jCheckBox1.isSelected())
                doc.newPage();
        } else {

            //specify column widths
            int temp = dlm2.size();

            float[] columnWidths = new float[temp];
            for (int x = 0; x < columnWidths.length; x++) {
                columnWidths[x] = 2f;
            }

            //create PDF table with the given widths
            PdfPTable table = new PdfPTable(columnWidths);
            // set table width a percentage of the page width
            table.setWidthPercentage(90f);
            Reporter re;
            re = new Reporter();
            re.insertCell(table, "Bull Info", Element.ALIGN_CENTER, 1, bfBold12);
            for (int i = 0; i < dlm2.size(); i++) {
                String[] parts = dlm2.get(i).toString().split(": ");
                String part2 = parts[1];

                re.insertCell(table, newhead[Integer.parseInt(part2)], Element.ALIGN_CENTER, 1, bfBold12);
            }

            table.setHeaderRows(1);
            //insert an empty row

            //create section heading by cell merging
            //just some random data to fill 
            for (int x = 0; x < dlm3.size(); x++) {
                String str = dlm3.get(x).toString();
                //System.out.println(str);
                String[] parts = str.split(":");
                String part2 = parts[1];
                // System.out.println(part2);

                int row = Integer.parseInt(part2) - 1;
                re.insertCell(table, Bulls[row], Element.ALIGN_CENTER, 1, bf12);
                for (int i = 0; i < dlm2.getSize(); i++) {

                    for (int j = 0; j < header.length && j < bull1[row].length; j++) {
                        String str1 = dlm2.get(i).toString();
                        String[] p1 = str1.split(": ");
                        String p2 = p1[0];
                        if (p2.equals(header[j])) {
                            re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12);
                        }
                    }
                }
                // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12);
            }

            doc.add(table);

        }
        if (jCheckBox2.isSelected()) {
            DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
            for (int i = 0; i < dlm3.size(); i++) {

                String str = dlm3.get(i).toString();
                System.out.println(str);
                String[] parts = str.split(":");
                String part1 = parts[0];
                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                float total = (float) 0.0;
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                    if (bull1[row][j].equals("")) {
                        continue;
                    } else {
                        total += Integer.parseInt(bull1[row][j]);
                    }

                }
                System.out.println(total);
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                    if (!bull1[row][j].equals("")) {

                        String[] Parts = header[j].split("_");
                        String Part2 = Parts[1];
                        dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1);
                    } else {
                        dataSet.setValue(0, "Percent", header[j]);

                    }
                }

            }
            JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology",
                    "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false);

            if (dlm3.size() > 12) {
                doc.newPage();
            }
            PdfContentByte contentByte = docWriter.getDirectContent();
            PdfTemplate template = contentByte.createTemplate(325, 250);
            PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
            Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

            chart.draw(graphics2d, rectangle2d);

            graphics2d.dispose();
            contentByte.addTemplate(template, 0, 0);
        }
        if (jCheckBox1.isSelected()) {

            for (int i = 0; i < dlm3.size(); i++) {
                DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
                String str = dlm3.get(i).toString();
                System.out.println(str);
                String[] parts = str.split(":");
                String part1 = parts[0];
                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                float total = (float) 0.0;
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                    if (bull1[row][j].equals("")) {
                        continue;
                    } else {
                        total += Integer.parseInt(bull1[row][j]);
                    }

                }
                System.out.println(total);
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                    if (!bull1[row][j].equals("")) {

                        String[] Parts = header[j].split("_");
                        String Part2 = Parts[1];
                        dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2);
                    } else {
                        dataSet.setValue(0, "Percent", header[j]);

                    }
                }
                JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1,
                        "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false);
                if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) {
                    doc.newPage();
                }
                PdfContentByte contentByte = docWriter.getDirectContent();
                PdfTemplate template = contentByte.createTemplate(325, 250);
                PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
                Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

                chart.draw(graphics2d, rectangle2d);

                graphics2d.dispose();
                contentByte.addTemplate(template, 0, 0);

                doc.newPage();
            }
        }

    } catch (DocumentException dex) {
        dex.printStackTrace();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (doc != null) {
            //close the document
            doc.close();
        }
        if (docWriter != null) {
            //close the writer
            docWriter.close();
        }

    }
    controller.openDocument(Path);
}

From source file:eeebees.PDFGen.java

public static void main(String[] args) {

    try {/*w  ww  .  j a v a 2s .c  o m*/

        OutputStream file = new FileOutputStream(new File("D:\\PDF_Java4s.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);

        //Inserting Image in PDF
        //Image image = Image.getInstance ("src/pdf/java4s.png");
        //image.scaleAbsolute(120f, 60f);//image width,height    

        //Inserting Table in PDF
        PdfPTable table = new PdfPTable(3);

        PdfPCell cell = new PdfPCell(new Paragraph("Java4s.com"));

        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(10.0f);
        cell.setBackgroundColor(new BaseColor(140, 221, 8));

        table.addCell(cell);

        table.addCell("Name");
        table.addCell("Address");
        table.addCell("Country");
        table.addCell("Java4s");
        table.addCell("NC");
        table.addCell("United States");
        table.setSpacingBefore(30.0f); // Space Before table starts, like margin-top in CSS
        table.setSpacingAfter(30.0f); // Space After table starts, like margin-Bottom in CSS                                          

        //Inserting List in PDF
        List list = new List(true, 30);
        list.add(new ListItem("Java4s"));
        list.add(new ListItem("Php4s"));
        list.add(new ListItem("Some Thing..."));

        //Text formating in PDF
        Chunk chunk = new Chunk("Welecome To Java4s Programming Blog...");
        chunk.setUnderline(+1f, -2f);//1st co-ordinate is for line width,2nd is space between
        Chunk chunk1 = new Chunk("Php4s.com");
        chunk1.setUnderline(+4f, -8f);
        chunk1.setBackground(new BaseColor(17, 46, 193));

        //Now Insert Every Thing Into PDF Document
        document.open();//PDF document opened........                   

        //document.add(image);

        document.add(Chunk.NEWLINE); //Something like in HTML :-)

        document.add(new Paragraph("Dear Java4s.com"));
        document.add(new Paragraph("Document Generated On - " + new Date().toString()));

        document.add(table);

        document.add(chunk);
        document.add(chunk1);

        document.add(Chunk.NEWLINE); //Something like in HTML :-)                                

        document.newPage(); //Opened new page
        document.add(list); //In the new page we are going to add list

        document.close();

        file.close();

        System.out.println("Pdf created successfully..");

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

From source file:es.baudlord.pcpartpicker.model.Build.java

License:Open Source License

public PdfPTable createPdfPTable(Font font) throws DocumentException {
    List<PdfPCell> cellList = new ArrayList<>();

    cellList.addAll(Arrays.asList(new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.Name"), font)),
            new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.UnitPrice"), font)),
            new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.Amount"), font)),
            new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.Price"), font))));

    for (Product.Category c : Product.Category.values()) {
        ArrayList<Part> parts = getParts(c);
        if (parts.isEmpty())
            continue;

        parts.forEach(product -> cellList
                .addAll(Arrays.asList(new PdfPCell(new Phrase(product.getDescription(), font)),
                        new PdfPCell(new Phrase(Coin.formatNet(product.getPrice()), font)),
                        new PdfPCell(new Phrase(String.valueOf(product.getAmount()), font)),
                        new PdfPCell(new Phrase(Coin.formatNet(product.getTotalPrice()), font)))));
    }/*from  w  ww .  j a va2  s  .  com*/
    PdfPCell line = new PdfPCell(new Phrase(""));
    line.setColspan(4);
    cellList.add(line);

    double totalPrice = this.getTotalPrice();
    font.setSize(font.getSize() + 2);

    PdfPCell total = new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("total.price").toUpperCase(), font));
    total.setColspan(3);
    cellList.addAll(Arrays.asList(total, new PdfPCell(new Phrase(Coin.formatNet(totalPrice), font))));

    PdfPCell totalTax = new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("total.tax").toUpperCase(), font));
    totalTax.setColspan(3);
    cellList.addAll(Arrays.asList(totalTax, new PdfPCell(new Phrase(Coin.formatTax(totalPrice), font))));

    PdfPCell totalPvp = new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("total.pvp").toUpperCase(), font));
    totalPvp.setColspan(3);
    cellList.addAll(Arrays.asList(totalPvp, new PdfPCell(new Phrase(Coin.formatGross(totalPrice), font))));

    PdfPTable table = new PdfPTable(4);
    table.setWidths(new int[] { 50, 10, 5, 10 });
    table.setHeaderRows(1);

    for (int i = 0; i < table.getNumberOfColumns(); i++) {
        cellList.get(i).setBorder(Rectangle.BOTTOM);
        table.addCell(cellList.get(i));
    }
    for (int i = table.getNumberOfColumns(); i < cellList.size() - 6; i++) {
        cellList.get(i).setBorder(0);
        table.addCell(cellList.get(i));
    }
    for (int i = cellList.size() - 6; i < cellList.size() - 4; i++) {
        cellList.get(i).setBorder(Rectangle.TOP);
        table.addCell(cellList.get(i));
    }
    for (int i = cellList.size() - 4; i < cellList.size(); i++) {
        cellList.get(i).setBorder(0);
        table.addCell(cellList.get(i));
    }

    return table;
}

From source file:es.clinica.veterinaria.albaranes.AlbaranPdf.java

public PdfPTable createTable() throws DocumentException {
    // a table with three columns
    int iva = 0, iva2 = 0;
    DecimalFormat df = new DecimalFormat("0.00");
    PdfPTable table = new PdfPTable(5);
    table.setTotalWidth(new float[] { 55, 150, 200, 70, 70 });
    table.setLockedWidth(true);/*www .ja  va  2s .c  o  m*/

    // the cell object
    // we add a cell with colspan 3
    PdfPCell cell = new PdfPCell(new Phrase("CANT."));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("CONCEPTO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("DESCRIPCIN"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("PRECIO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("IMPORTE"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    HashSet<VentaLinea> listVenta = getVenta().getVenta_lineas();

    for (VentaLinea vlinea : listVenta) {
        if (vlinea.getTipo() == 1) {
            if (vlinea.getProducto().getIva() != null) {
                iva2 = vlinea.getProducto().getIva().getValor();
                //                    System.out.println("IVA: " +iva2);
            }
        } else if (vlinea.getTipo() == 2) {
            if (vlinea.getServicio().getIva() != null) {
                iva2 = vlinea.getServicio().getIva().getValor();
                //                    System.out.println("IVA: " +iva2);
            }
        }

        //Para hacer el calculo nos vamos a quedar con el IVA mayor
        if (iva < iva2) {
            iva = iva2;
        }

        cell = new PdfPCell(new Phrase(vlinea.getCantidad() + "", small));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPaddingBottom(5);
        table.addCell(cell);

        table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small)));

        String descripcion = vlinea.getDescripcion();
        if (descripcion == null || "null".equals(descripcion)) {
            table.addCell(new PdfPCell(new Phrase(" ", small)));
            //                System.out.println("null:" + descripcion);
        } else {
            table.addCell(new PdfPCell(new Phrase(descripcion, small)));
            //                System.out.println("!null:" + descripcion);
        }

        cell = new PdfPCell(new Phrase(df.format(vlinea.getPvp()) + " ", small));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setPaddingBottom(5);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(df.format(vlinea.getPreciototalNoIVA()) + " ", small));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setPaddingBottom(5);
        table.addCell(cell);
    }

    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("SUMA"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(venta.getCostesinIva()) + " "));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* IVA */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    //        float costetotal = (float) (venta.getCoste() * (1+(iva*0.01)));

    cell = new PdfPCell(new Phrase("IVA " + iva + "%"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(venta.getIvas()) + " "));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* COSTE TOTAL */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("TOTAL"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(venta.getCoste()) + " "));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    return table;
}

From source file:es.clinica.veterinaria.facturas.FacturaPdf.java

public PdfPTable createTable() throws DocumentException {
    // a table with three columns
    int iva = 0, iva2 = 0;
    DecimalFormat df = new DecimalFormat("0.00");
    PdfPTable table = new PdfPTable(6);
    table.setTotalWidth(new float[] { 50, 65, 150, 150, 65, 70 });
    table.setLockedWidth(true);//ww  w . j a  v a 2  s.  c o  m

    // the cell object
    // we add a cell with colspan 3
    PdfPCell cell = new PdfPCell(new Phrase("CANT."));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("FECHA"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("CONCEPTO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("DESCRIPCIN"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("PRECIO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("IMPORTE"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    HashSet<Venta> ventas = this.getFactura().getVentas();
    for (Venta venta : ventas) {
        HashSet<VentaLinea> listVenta = venta.getVenta_lineas();

        for (VentaLinea vlinea : listVenta) {
            if (vlinea.getTipo() == 1) {
                if (vlinea.getProducto().getIva() != null) {
                    iva2 = vlinea.getProducto().getIva().getValor();
                    //                    System.out.println("IVA: " +iva2);
                }
            } else if (vlinea.getTipo() == 2) {
                if (vlinea.getServicio().getIva() != null) {
                    iva2 = vlinea.getServicio().getIva().getValor();
                    //                    System.out.println("IVA: " +iva2);
                }
            }

            //Para hacer el calculo nos vamos a quedar con el IVA mayor
            if (iva < iva2) {
                iva = iva2;
            }

            cell = new PdfPCell(new Phrase(vlinea.getCantidad() + "", small));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setPaddingBottom(5);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(new SimpleDateFormat("dd-MM-yyyy").format(vlinea.getFecha()), small));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setPaddingBottom(5);
            table.addCell(cell);

            if (vlinea.getTipo() == 2) { //Servicio
                table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small)));

                String descripcion = vlinea.getDescripcion();
                if (descripcion == null || "null".equals(descripcion)) {
                    table.addCell(new PdfPCell(new Phrase(" ", small)));
                    //                System.out.println("null:" + descripcion);
                } else {
                    table.addCell(new PdfPCell(new Phrase(descripcion, small)));
                    //                System.out.println("!null:" + descripcion);
                }
            } else if (vlinea.getTipo() == 1) { //Producto
                //Si el producto es Tratamiento
                if (vlinea.getProducto().getFamilia().isTratamiento()) {
                    table.addCell(new PdfPCell(new Phrase("Tratamiento", small)));
                    table.addCell(new PdfPCell(new Phrase("", small)));
                } else {

                    table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small)));

                    String descripcion = vlinea.getDescripcion();
                    if (descripcion == null || "null".equals(descripcion)) {
                        table.addCell(new PdfPCell(new Phrase(" ", small)));
                        //                System.out.println("null:" + descripcion);
                    } else {
                        table.addCell(new PdfPCell(new Phrase(descripcion, small)));
                        //                System.out.println("!null:" + descripcion);
                    }
                }
            }
            cell = new PdfPCell(new Phrase(df.format(vlinea.getPvp()) + " ", small));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setPaddingBottom(5);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(df.format(vlinea.getPreciototalNoIVA()) + " ", small));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setPaddingBottom(5);
            table.addCell(cell);
        }
    }

    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("SUMA"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(factura.getCoste()) + " ", smallBold));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* IVA */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    float costetotal = (float) (factura.getCostetotal());

    cell = new PdfPCell(new Phrase("IVA " + iva + "%"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(factura.getIvas()) + " ", smallBold));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* COSTE TOTAL */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("TOTAL"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(costetotal) + " ", smallBold));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    return table;
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java

License:Open Source License

protected void addTableCaption(PdfPTable table, String caption) {

    PdfPCell cell = getContentCell();
    cell.setColspan(table.getNumberOfColumns());
    table.addCell(cell);/*w ww  .j a va  2  s  .  co  m*/
    PdfPCell captionCell = new PdfPCell(new Phrase(caption, TABLE_CAPTION));
    captionCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    captionCell.setPaddingBottom(5);
    captionCell.setBorder(Rectangle.TOP);
    captionCell.setBorderWidthTop(1.5f);
    captionCell.setPaddingBottom(7);
    captionCell.setPaddingTop(2);
    captionCell.setColspan(table.getNumberOfColumns());
    table.addCell(captionCell);
}

From source file:Export.CertificadoViatura.java

public String criarDoc(String numApolice, String numCliente, Contrato c, VeiculoBean vf, String user,
        String moeda, String arquivo) {
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH'.'mm'.'ss");
    SimpleDateFormat sdfPT = new SimpleDateFormat("dd/MM/yyyy");

    try {//from w w w . j  ava  2s  .  c  om
        Document documento = new Document();
        documento.setPageSize(PageSize.A4);
        documento.setMargins(2f, 2f, 35f, 5f);

        //            File ff= new File("Documentos\\"+user+"\\Seguro Automovel\\");
        //            ff.mkdirs();
        //            ff =new File(ff.getAbsoluteFile()+"\\"+"Certificado Seguro Automovel "+sdf.format(new Date())+".pdf");
        File ff = new File(arquivo + "/" + user + "/Seguro Automovel/");
        ff.mkdirs();
        String Ddata = sdf.format(new Date());
        ff = new File(ff.getAbsoluteFile() + "/" + "Certificado Seguro Automovel " + Ddata + ".pdf");

        reString = "../Documentos/" + user + "/Seguro Automovel/" + "Certificado Seguro Automovel " + Ddata
                + ".pdf";

        OutputStream outputStraem = new FileOutputStream(ff);
        PdfWriter writer = PdfWriter.getInstance(documento, outputStraem);

        if (MarcaDAgua.isSimulation) {
            MarcaDAgua.SimulacaoVertical v = new MarcaDAgua.SimulacaoVertical();
            writer.setPageEvent(v);
        }

        if (MarcaDAgua.isCanceled) {
            MarcaDAgua.AnulacaoVertical v = new MarcaDAgua.AnulacaoVertical();
            writer.setPageEvent(v);
        }

        //            MyFooter event = new MyFooter();
        //            writer.setPageEvent(event);

        Font fontCabecalhoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 10.5f);
        Font fontCorpo = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f);
        Font fontCorpoP = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 7f);
        Font fontCorpoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 7.5f);
        Font fontCorpoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 11f);
        Font fontCabecalhoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 16f,
                Font.UNDERLINE);
        Font fontUK = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 5f, Font.ITALIC);

        documento.open();
        int total = vf.getInfo().size();
        int i = 0;
        for (Veiculo v : vf.getInfo()) {
            i++;
            PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 25f, 75f });
            pTableEmpresaPricipal.setWidthPercentage(93f);
            PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1);
            //                PdfPTable pTableEmpresaInforImpres2 = new PdfPTable(1);
            PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1);

            PdfPTable pTableNull = new PdfPTable(1);
            PdfPCell cellNull = new PdfPCell(new Phrase(" ", fontCorpo));
            cellNull.setBorder(0);
            pTableNull.addCell(cellNull);

            PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(Empresa.NOME, fontCabecalhoNG));
            pCellNomeEmpresa.setBorder(0);

            PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(Empresa.ENDERECO, fontCabecalhoN));
            pCellNomeEndereco.setBorder(0);

            PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(Empresa.CAIXAPOSTAL, fontCabecalhoN));
            pCellCaixaPostal.setBorder(0);

            PdfPCell pCellTeleFax = new PdfPCell(
                    new Phrase(Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN));
            pCellTeleFax.setBorder(0);

            PdfPCell pCellSociedade = new PdfPCell(new Phrase(Empresa.SOCIEDADE, fontCabecalhoN));
            pCellSociedade.setBorder(0);

            PdfPCell pCellPolice = new PdfPCell(new Phrase(Empresa.APOLICE + numApolice, fontCabecalhoN));
            pCellPolice.setBorder(0);

            Image imageEmpresa = Image.getInstance("logo.png");
            imageEmpresa.scaleToFit(190f, 100f);

            pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa);
            pTableEmpresaInforImpres1.addCell(pCellNomeEndereco);
            pTableEmpresaInforImpres1.addCell(pCellCaixaPostal);
            pTableEmpresaInforImpres1.addCell(pCellTeleFax);
            pTableEmpresaInforImpres1.addCell(pCellSociedade);

            pTableEmpresaInforImpres1.addCell(pCellPolice);

            PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1);
            cellTabela3.setBorder(0);

            pTableEmpresaInforImpres5.addCell(cellTabela3);

            PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5);
            cellTabela5.setBorder(0);

            PdfPCell cellTabela6 = new PdfPCell(imageEmpresa);
            cellTabela6.setBorder(0);

            pTableEmpresaPricipal.addCell(cellTabela6);
            pTableEmpresaPricipal.addCell(cellTabela5);

            PdfPTable pTableTitulo = new PdfPTable(1);

            Paragraph PTitulo = new Paragraph(new Phrase("", fontCorpo));
            Phrase pTitulo = new Phrase("Certificado Seguro de automvel".toUpperCase(), fontCorpoNG);
            Phrase pTituloUK = new Phrase("\nCertificate of motor insurance".toUpperCase(), fontUK);
            PTitulo.add(pTitulo);
            PTitulo.add(pTituloUK);

            PdfPCell cellTitulo = new PdfPCell(PTitulo);
            cellTitulo.setBorder(0);
            cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER);
            pTableTitulo.addCell(cellTitulo);

            PdfPTable pTableDetalhes = new PdfPTable(new float[] { 55, 45 });
            pTableDetalhes.setWidthPercentage(93f);

            Paragraph pNunCetificado = new Paragraph(new Phrase("", fontCorpo));
            pNunCetificado.add(new Phrase("1. Certificado: ", fontCorpo));
            pNunCetificado.add(new Phrase(v.getCertificado() == null || v.getCertificado().equals("") ? ""
                    : v.getCertificado().toUpperCase(), fontCorpoN));
            pNunCetificado.add(new Phrase("\n1. Certificate NO".toUpperCase(), fontUK));
            pNunCetificado.setPaddingTop(0f);

            ClienteI ci = new ClienteI(numCliente);
            Paragraph pNomeSegurado = new Paragraph(new Phrase("", fontCorpo));
            pNomeSegurado.add(new Phrase("3. Segurado: ", fontCorpo));
            pNomeSegurado.add(new Phrase(ci.getNOME_().toUpperCase(), fontCorpoN));
            pNomeSegurado.add(new Phrase("\n3. Insured".toUpperCase(), fontUK));
            pNomeSegurado.setPaddingTop(0f);

            Paragraph pMarca = new Paragraph(new Phrase("", fontCorpo));
            pMarca.add(new Phrase("5. Marca do Veiculo: ", fontCorpo));
            pMarca.add(new Phrase((v.getMarca() == null) ? " " : v.getMarca().toUpperCase(), fontCorpoN));
            pMarca.add(new Phrase("\n5. vehicle mark".toUpperCase(), fontUK));
            //                pMarca.setPaddingTop(1f);

            Paragraph pModelo = new Paragraph(new Phrase("", fontCorpo));
            pModelo.add(new Phrase("7. Modelo do Veiculo: ", fontCorpo));
            pModelo.add(new Phrase((v.getModelo() == null) ? " " : v.getModelo().toUpperCase(), fontCorpoN));
            pModelo.add(new Phrase("\n7. Model Vehicle".toUpperCase(), fontUK));
            pModelo.setPaddingTop(0f);

            Paragraph pPeriodo = new Paragraph(new Phrase("", fontCorpo));
            pPeriodo.add(new Phrase("9. Perodo de Seguro - De: ", fontCorpo));
            pPeriodo.add(new Phrase(
                    (sdfPT.format(c.getDataInicio()) + "  " + sdfPT.format(c.getDataFim())).toUpperCase(),
                    fontCorpoN));
            pPeriodo.add(new Phrase("\n9. period of insurance - from  to".toUpperCase(), fontUK));
            pPeriodo.setPaddingTop(0f);

            Paragraph pCategoria = new Paragraph(new Phrase("", fontCorpo));
            pCategoria.add(new Phrase("11. Categoria/Uso do Veculo: ", fontCorpo));
            pCategoria.add(new Phrase(" ", fontCorpoN));
            pCategoria.add(new Phrase("\n11. category/use of vehicle".toUpperCase(), fontUK));
            pCategoria.setPaddingTop(0f);

            PdfPCell cellDetalhesRi = new PdfPCell();
            cellDetalhesRi.addElement(pNunCetificado);
            cellDetalhesRi.addElement(pNomeSegurado);
            cellDetalhesRi.addElement(pMarca);
            cellDetalhesRi.addElement(pModelo);
            cellDetalhesRi.addElement(pPeriodo);
            cellDetalhesRi.addElement(pCategoria);

            Paragraph pNumApolice = new Paragraph(new Phrase("", fontCorpo));
            pNumApolice.add(new Phrase("2. Aplice N ", fontCorpo));
            pNumApolice.add(new Phrase(numApolice, fontCorpoN));
            pNumApolice.add(new Phrase("\n2. policy no".toUpperCase(), fontUK));
            pNumApolice.setPaddingTop(0f);

            Paragraph pOcupacaoSegurado = new Paragraph(new Phrase("", fontCorpo));
            pOcupacaoSegurado.add(new Phrase("4. Ocupao do Seguros: ", fontCorpo));
            pOcupacaoSegurado.add(new Phrase(ci.getPROFISSAO_().toUpperCase(), fontCorpoN));
            pOcupacaoSegurado.add(new Phrase("\n4. insured's occupation".toUpperCase(), fontUK));
            pOcupacaoSegurado.setPaddingTop(0f);

            Paragraph pNumChassi = new Paragraph(new Phrase("", fontCorpo));
            pNumChassi.add(new Phrase("6. N de Chassi/Motor: ", fontCorpo));
            pNumChassi.add(new Phrase(v.getChassi()
                    + ((v.getNumMotor() == null || v.getNumMotor().isEmpty()) ? " " : "/" + v.getNumMotor()),
                    fontCorpoN));
            pNumChassi.add(new Phrase("\n6 EnGINE", fontUK));
            pNumChassi.setPaddingTop(0f);

            Paragraph pDataFabrico = new Paragraph(new Phrase("", fontCorpo));
            pDataFabrico.add(new Phrase("8. Data de Fabrico: ", fontCorpo));
            pDataFabrico.add(new Phrase(((v.getAnoFabrico() == null) ? " " : v.getAnoFabrico()), fontCorpo));
            pDataFabrico.add(new Phrase("\n8. Date of manofacturing", fontUK));
            pDataFabrico.setPaddingTop(0f);

            Paragraph pTipoCobertura = new Paragraph(new Phrase("", fontCorpo));
            pTipoCobertura.add(new Phrase("10. Tipo de Cobertura: ", fontCorpo));
            pTipoCobertura
                    .add(new Phrase(
                            ((v.getTipoCobertura() != null) ? (vf.getVeiculo().getTipoCobertura().equals("41")
                                    ? "Contra Terceiros".toUpperCase()
                                    : (vf.getVeiculo().getTipoCobertura().equals("42")
                                            ? "CONTRA Todos os riscos".toUpperCase()
                                            : (vf.getVeiculo().getTipoCobertura().equals("43")
                                                    ? "Compreensivo limitado".toUpperCase()
                                                    : vf.getVeiculo().getTipoCobertura())))
                                    : " "),
                            fontCorpoN));
            pTipoCobertura.add(new Phrase("\n10. Tipo of Cover".toUpperCase(), fontUK));
            pTipoCobertura.setPaddingTop(0f);

            PdfPCell cellDetalhesLe = new PdfPCell();
            cellDetalhesLe.addElement(pNumApolice);
            cellDetalhesLe.addElement(pOcupacaoSegurado);
            cellDetalhesLe.addElement(pNumChassi);
            cellDetalhesLe.addElement(pDataFabrico);
            cellDetalhesLe.addElement(pTipoCobertura);

            pTableDetalhes.addCell(cellDetalhesRi);
            pTableDetalhes.addCell(cellDetalhesLe);
            String f = "";

            Paragraph para = new Paragraph(new Phrase("", fontCorpo));
            para.add(new Phrase("12. Pessoas ou Classe de Pessoas Habilitadas Para Conduzir", fontCorpoN));
            para.add(new Phrase("\n12. Persons or Class of Persons Entitled to Drive", fontUK));
            pTableDetalhes.addCell(new PdfPCell(para));

            para = new Paragraph(new Phrase("", fontCorpo));
            para.add(new Phrase("14. Categorias/Uso de Veculos", fontCorpoN));
            para.add(new Phrase("\n14. Categories / Use of Vehicles", fontUK));
            pTableDetalhes.addCell(new PdfPCell(para));

            Paragraph p11 = new Paragraph(new Phrase("", fontCorpo));
            p11.add(new Phrase(
                    "Qualquer pessoa que conduza sob a ordem do detentor da aplice ou com a sua permisso:",
                    fontCorpo));
            p11.add(new Phrase("\nAny person who is driving on the policy holder's or with his permission",
                    fontUK));
            p11.setPaddingTop(0f);

            Paragraph p12 = new Paragraph(new Phrase("", fontCorpo));
            p12.add(new Phrase(
                    "Desde que o/a condutor/a esteja habilitado/a para conduzir de acordo com a licena/normas que regulam "
                            + "a conduo de veculos a motor ou instrues para conduo lhe tenha sido passada e no esteja impedido de conduzir por"
                            + " ordem do tribunal ou por alguma outra razo.",
                    fontCorpo));
            p12.add(new Phrase(
                    "\nProvided that the person diving is permitted in accodance with the licensing or outher laws or regulations to dive the"
                            + "motor vehicles or has been premitted and is not disiqualified by order of a court of law or reason of any enactment or regulation in that behalf from diving such motor vehice",
                    fontUK));
            p12.setPaddingTop(0f);

            Paragraph p13 = new Paragraph(new Phrase("", fontCorpo));
            p13.add(new Phrase("13. Limite para uso:", fontCorpoN));
            p13.add(new Phrase("\n13. Limitation as to use", fontUK));
            p13.setPaddingTop(0f);

            Paragraph p14 = new Paragraph(new Phrase("", fontCorpo));
            p14.add(new Phrase("  - Usado apenas como descrito na categoria aqui indicada.", fontCorpo));
            p14.add(new Phrase("\n  - Used only as prescribed under the applicable category stated there in.",
                    fontUK));
            p14.setPaddingTop(0f);

            Paragraph p15 = new Paragraph(new Phrase("", fontCorpo));
            p15.add(new Phrase(
                    "  - Em todo caso, a aplice no cobre corridas, prova de segurana teste de velocidade, nem para qualquer outro propsito relacionado com a venda do automvel.",
                    fontCorpo));
            p15.add(new Phrase(
                    "\n  - In all cases, the policy does not cover racing, pace-making, reliability trial, speed testing, nor use for any purpose in connection with the trade",
                    fontUK));
            p15.setPaddingTop(0f);

            cellDetalhesRi = new PdfPCell();
            cellDetalhesRi.addElement(p11);
            cellDetalhesRi.addElement(p12);
            cellDetalhesRi.addElement(p13);
            cellDetalhesRi.addElement(p14);
            cellDetalhesRi.addElement(p15);

            Paragraph p21 = new Paragraph(new Phrase("", fontCorpo));
            p21.add(new Phrase("CATEGORIA 1 ", fontCorpoN));
            p21.add(new Paragraph(
                    "- Veculos usados para actividade social, domstica e de lazer e do segurado incluindo uso comercial.",
                    fontCorpo));
            p21.add(new Phrase(
                    "Vehicles used for social, domestic and pleasure including business use of the insured.",
                    fontUK));
            p21.setPaddingTop(0f);

            Paragraph p22 = new Paragraph(new Phrase("", fontCorpo));
            p22.add(new Phrase("CATEGORIA 2 ", fontCorpoN));
            p22.add(new Paragraph("- Veculo pertence ao segurado e usado no transporte de mercadorias.",
                    fontCorpo));
            p22.add(new Phrase("Vehicle used for transportation of good and belonging to the insured", fontUK));
            p22.setPaddingTop(0f);

            Paragraph p23 = new Paragraph(new Phrase("", fontCorpo));
            p23.add(new Phrase("CATEGORIA 3 ", fontCorpoN));
            p23.add(new Paragraph(
                    "- Veculos alugados utilizados no transporte Comercial de mercadorias pertencente  terceiros.",
                    fontCorpo));
            p23.add(new Phrase(
                    "Vehicles used for commercial transportation of good belonging to third parteis fare paying.",
                    fontUK));
            p23.setPaddingTop(0f);

            Paragraph p24 = new Paragraph(new Phrase("", fontCorpo));
            p24.add(new Phrase("CATEGORIA 5 ", fontCorpoN));
            p24.add(new Paragraph(
                    "- Veculos a motor com duas ou trs rodas para o transporte pblico de passageiro (mediante pagamento de bilhetes).",
                    fontCorpo));
            p24.add(new Phrase("Motor vehicles with two or three wheels for carrying fare paying pessengers.",
                    fontUK));
            p24.setPaddingTop(0f);

            Paragraph p25 = new Paragraph(new Phrase("", fontCorpo));
            p25.add(new Phrase("CATEGORIA 6-10 ", fontCorpoN));
            p25.add(new Paragraph(
                    "- Veculos para fins especiais: Garagem (6), Escola de Conduo (7), Para Aluguer sem motorista (8), Veculo Pesado (9) e Ambulncia, Transporte de distribuio de mercadoria, etc. (10).",
                    fontCorpo));
            p25.add(new Phrase(
                    "To special purposes vehicles: Garage (6) Driving School (7) Haring without driver ( 8) , Heavy trucks ( 9) and ambulance, refuse disposal vans etc. ( 10).",
                    fontUK));
            p25.setPaddingTop(0f);

            cellDetalhesLe = new PdfPCell();
            cellDetalhesLe.addElement(p21);
            cellDetalhesLe.addElement(p22);
            cellDetalhesLe.addElement(p23);
            cellDetalhesLe.addElement(p24);
            cellDetalhesLe.addElement(p25);

            pTableDetalhes.addCell(cellDetalhesRi);
            pTableDetalhes.addCell(cellDetalhesLe);

            PdfPTable pTableArtigo = new PdfPTable(1);
            pTableArtigo.setWidthPercentage(93f);
            Paragraph pArtigoCetificado = new Paragraph(new Phrase("", fontCorpo));
            pArtigoCetificado.add(new Phrase(
                    "O Contrato de seguro cessa, nos termos da legislao em vigor, os efeitos s 24 horas do dia da alienao do veculo.",
                    fontCorpo));
            pArtigoCetificado.add(new Phrase(
                    "\nThe insurance contract ceases, according to law in force, from its effects from 24 hours from the date of alienation of the vehicle.",
                    fontUK));
            PdfPCell cellArtigoCetificado = new PdfPCell(pArtigoCetificado);
            cellArtigoCetificado.setBorder(0);

            Paragraph pLeis = new Paragraph(new Phrase("", fontCorpo));
            pLeis.add(new Phrase(
                    "Este certificado foi emitido em conformidade com os Artigos 1 a 36, lei n 30/2000 da Repblica Democrtica de So Tom e Prncipe e que institui a existncia de uma cobertura pelo seguro",
                    fontCorpo));
            pLeis.add(new Phrase(
                    "\nThis certificate is issurd in pursuat to the prevision of Articles 1 to 36 , Law No. 30/2000 of the Democratic Republic of Sao Tome and Principe and it constitutes the existence of an insurance cover",
                    fontUK));
            PdfPCell cellLeis = new PdfPCell(pLeis);
            cellLeis.setBorder(0);

            pTableArtigo.addCell(cellArtigoCetificado);
            pTableArtigo.addCell(cellLeis);

            PdfPTable pTableAssinaturaTitulo = new PdfPTable(1);
            PdfPTable pTableAssinatura = new PdfPTable(new float[] { 50f, 50f });
            PdfPCell cellAssinatora = new PdfPCell(
                    new Phrase("Assinaturas e Carimbo".toUpperCase(), fontCorpoN));
            cellAssinatora.setBorder(0);
            cellAssinatora.setHorizontalAlignment(Element.ALIGN_CENTER);
            PdfPCell celllinha1 = new PdfPCell(
                    new Phrase("___________________________________".toUpperCase(), fontCorpo));
            celllinha1.setBorder(0);
            celllinha1.setHorizontalAlignment(Element.ALIGN_CENTER);
            PdfPCell celllinha2 = new PdfPCell(
                    new Phrase("___________________________________".toUpperCase(), fontCorpo));
            celllinha2.setBorder(0);
            celllinha2.setHorizontalAlignment(Element.ALIGN_CENTER);

            PdfPCell celllinha11 = new PdfPCell(new Phrase("Nicon Seguros sa STP".toUpperCase(), fontCorpoP));
            celllinha11.setBorder(0);
            celllinha11.setHorizontalAlignment(Element.ALIGN_CENTER);
            PdfPCell celllinha21 = new PdfPCell(new Phrase("o segurado ".toUpperCase(), fontCorpoP));
            celllinha21.setBorder(0);
            celllinha21.setHorizontalAlignment(Element.ALIGN_CENTER);

            PdfPCell assinaturaUK = new PdfPCell(
                    new Phrase("Signature of Insurer and stamp".toUpperCase(), fontUK));
            assinaturaUK.setBorder(0);
            assinaturaUK.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            assinaturaUK.setColspan(2);

            pTableAssinaturaTitulo.addCell(cellAssinatora);
            pTableAssinatura.addCell(celllinha1);
            pTableAssinatura.addCell(celllinha2);
            pTableAssinatura.addCell(celllinha11);
            pTableAssinatura.addCell(celllinha21);
            pTableAssinatura.addCell(assinaturaUK);

            documento.add(pTableEmpresaPricipal);
            documento.add(pTableNull);
            documento.add(pTableTitulo);
            documento.add(pTableNull);
            documento.add(pTableNull);
            documento.add(pTableDetalhes);
            documento.add(pTableNull);
            documento.add(pTableArtigo);
            documento.add(pTableNull);
            documento.add(pTableAssinaturaTitulo);
            documento.add(pTableNull);
            documento.add(pTableNull);
            documento.add(pTableAssinatura);
            if (i != total)
                documento.newPage();
        }
        documento.close();

        //           PrintPdf printPdf = new PrintPdf(ff.getAbsolutePath(), ff.getAbsolutePath(), 0, 595f,842f,"Enviar Para o OneNote 2013",1); 
        //           //PrintPdf printPdf = new PrintPdf(ff.getAbsolutePath(), ff.getAbsolutePath(), 0, 595f,842f,"Hewlett-Packard HP LaserJet P2035",1); 
        //             
        //            printPdf.print();
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(SeguroAPG.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(SeguroAPG.class.getName()).log(Level.SEVERE, null, ex);
    }
    return reString;
}