Example usage for com.itextpdf.text Document setPageSize

List of usage examples for com.itextpdf.text Document setPageSize

Introduction

In this page you can find the example usage for com.itextpdf.text Document setPageSize.

Prototype


public boolean setPageSize(Rectangle pageSize) 

Source Link

Document

Sets the pagesize.

Usage

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 va2  s.c om
    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();/*from w  w w.ja va2  s.  c  o 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:edu.ksu.cs.a4vm.bse.reporter.ReporterArchive.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    File1 = jTextField1.getText();
    JFileChooser chooser = new JFileChooser();
    int option = chooser.showOpenDialog(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
        File file = new File(File1);

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

        }
        int number_of_rows1 = 0;
        String line = "";
        String cvsSplitBy = ",";
        try {
            while ((line = br1.readLine()) != null) {

                // use comma as separator
                number_of_rows1++;
            }

        } catch (IOException ex) {
            Logger.getLogger(ReporterArchive.class.getName()).log(Level.SEVERE, null, ex);
        }

        bull1 = new String[number_of_rows1][];
        int k = 0;
        BufferedReader br2 = null;
        try {
            br2 = new BufferedReader(new FileReader(file));
        } catch (FileNotFoundException ex) {
        }
        try {
            while ((line = br2.readLine()) != null) {

                // use comma as separator
                String Bull[] = line.split(",");
                System.out.println(Bull.length);
                bull1[k] = new String[93];
                if (Bull.length < 10) {
                    for (int j = 0; j < 92; j++) {
                        bull1[k][j] = "";
                        //System.out.println(Bull[j]);
                    }
                } else {
                    for (int j = 0; j < Bull.length; j++) {
                        bull1[k][j] = Bull[j];
                        //System.out.println(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(FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0));
            Font bf12 = new Font(FontFamily.TIMES_ROMAN, 6);
            Font bfBold20 = new Font(FontFamily.TIMES_ROMAN, 12, 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(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][78] + " " + bull1[1][79] + "\n\n\tRanch: " + bull1[1][80]
                    + "\n\n\tAddress: " + bull1[1][71] + "\n\n\tCity: " + bull1[1][73] + "\n\n\tState: "
                    + bull1[1][76] + "\tZip: " + bull1[1][77] + "\n\n\tPhone: " + bull1[1][75] + "\n\n";

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

            boolean[] checkboxs = { jCheckBox1.isSelected(), jCheckBox2.isSelected(), jCheckBox3.isSelected(),
                    jCheckBox4.isSelected(), jCheckBox5.isSelected(), jCheckBox6.isSelected(),
                    jCheckBox7.isSelected(), jCheckBox8.isSelected(), jCheckBox9.isSelected(),
                    jCheckBox10.isSelected(), jCheckBox11.isSelected(), jCheckBox12.isSelected(),
                    jCheckBox13.isSelected() };
            //specify column widths
            int temp = 0;
            for (int x = 0; x < checkboxs.length; x++) {
                if (checkboxs[x] == true) {
                    temp++;
                }
            }
            float[] columnWidths = new float[temp + 5];
            for (int x = 0; x < columnWidths.length; x++) {
                if (x < 5)
                    columnWidths[x] = 1f;
                else if (jCheckBox1.isSelected() && x == 5)
                    columnWidths[x] = 2f;
                else if (jCheckBox2.isSelected() && jCheckBox3.isSelected() && x == 7)
                    columnWidths[x] = 2f;
                else if (!jCheckBox2.isSelected() && jCheckBox3.isSelected() && x == 6)
                    columnWidths[x] = 2f;
                else if (jCheckBox4.isSelected() && x == columnWidths.length - 2)
                    columnWidths[x] = 2f;
                else if (jCheckBox5.isSelected() && x == columnWidths.length - 1)
                    columnWidths[x] = 2f;
                else
                    columnWidths[x] = 1f;
            }

            //create PDF table with the given widths
            PdfPTable table = new PdfPTable(columnWidths);
            // set table width a percentage of the page width
            table.setWidthPercentage(90f);
            ReporterArchive re;
            re = new ReporterArchive();
            //insert column headings
            re.insertCell(table, "ID-Tag", Element.ALIGN_CENTER, 1, bfBold12);
            re.insertCell(table, "ID-Tatto", Element.ALIGN_CENTER, 1, bfBold12);
            re.insertCell(table, "ID-RFID", Element.ALIGN_CENTER, 1, bfBold12);
            re.insertCell(table, "ID-Brand", Element.ALIGN_CENTER, 1, bfBold12);
            re.insertCell(table, "ID-Other", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox1.isSelected())
                re.insertCell(table, "Age", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox2.isSelected())
                re.insertCell(table, "Scrotal", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox3.isSelected())
                re.insertCell(table, "Motility", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox6.isSelected())
                re.insertCell(table, "Normal", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox7.isSelected())
                re.insertCell(table, "M2", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox8.isSelected())
                re.insertCell(table, "M3", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox9.isSelected())
                re.insertCell(table, "M4", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox10.isSelected())
                re.insertCell(table, "M5", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox11.isSelected())
                re.insertCell(table, "M6", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox12.isSelected())
                re.insertCell(table, "M7", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox13.isSelected())
                re.insertCell(table, "M8", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox4.isSelected())
                re.insertCell(table, "Comments", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox5.isSelected())
                re.insertCell(table, "Classification", 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 = 1; x < number_of_rows1; x++) {

                re.insertCell(table, bull1[x][7], Element.ALIGN_CENTER, 1, bf12);
                re.insertCell(table, bull1[x][8], Element.ALIGN_CENTER, 1, bf12);
                re.insertCell(table, bull1[x][6], Element.ALIGN_CENTER, 1, bf12);
                re.insertCell(table, bull1[x][2], Element.ALIGN_CENTER, 1, bf12);
                re.insertCell(table, bull1[x][9], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox1.isSelected())
                    re.insertCell(table, bull1[x][0], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox2.isSelected())
                    re.insertCell(table, bull1[x][70], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox3.isSelected())
                    re.insertCell(table, bull1[x][61], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox6.isSelected())
                    re.insertCell(table, bull1[x][43], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox7.isSelected())
                    re.insertCell(table, bull1[x][45], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox8.isSelected())
                    re.insertCell(table, bull1[x][47], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox9.isSelected())
                    re.insertCell(table, bull1[x][49], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox10.isSelected())
                    re.insertCell(table, bull1[x][51], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox11.isSelected())
                    re.insertCell(table, bull1[x][53], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox12.isSelected())
                    re.insertCell(table, bull1[x][55], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox13.isSelected())
                    re.insertCell(table, bull1[x][57], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox4.isSelected())
                    re.insertCell(table, "", Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox5.isSelected())
                    re.insertCell(table, bull1[x][35], Element.ALIGN_CENTER, 1, bf12);
            }
            doc.add(table);

        } 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:
    } //GEN-LAST:event_jButton1ActionPerformed
}

From source file:emailworkshop.EmailWorkshop.java

public static void gerarPDF(String nome, int numCert) {
    Calendar data = Calendar.getInstance();

    // criao do objeto documento
    Document document = new Document() {
    };/*from  w  w  w. j a  v a2s . c o m*/
    document.setPageSize(new Rectangle(800, 500));
    try {

        PdfWriter.getInstance(document, new FileOutputStream("Certificado.pdf"));
        document.open();

        // adicionando um pargrafo ao documento
        Image img = Image.getInstance("logo.png");

        img.scaleAbsoluteWidth(620);
        img.scaleAbsoluteHeight(130);
        Paragraph texto1 = new Paragraph("\n Conferimos o presente Certificado a " + nome + " por ter "
                + "participado do II Workshop de Inovao, com durao de 4 horas. Onde foram apresentadas as palestras: ");
        Paragraph texto2 = new Paragraph(
                "Economia compartilha & Inovao Disruptiva - Arthur Schuler da Igreja.\n"
                        + "Empreendedorismo: Um case de sucesso - Cludio Kopp.");
        Paragraph texto3 = new Paragraph(
                "\n\n\n\n\nRegistrado na UFPR Setor Palotina Livro 4 certificado Nr " + numCert + ".");

        Paragraph localData = new Paragraph("\nPalotina, " + new SimpleDateFormat("dd").format(data.getTime())
                + " de " + new SimpleDateFormat("MMMM").format(data.getTime()) + " de "
                + new SimpleDateFormat("yyyy").format(data.getTime()) + ".\n\n");

        texto1.setAlignment("center");
        texto2.setAlignment("center");
        texto3.setAlignment("right");
        localData.setAlignment("center");

        Image assinatura = Image.getInstance("assinatura.png");
        assinatura.scaleAbsoluteHeight(75);
        assinatura.scaleAbsoluteWidth(250);
        assinatura.setAbsolutePosition(275, 110);

        document.add(img);
        document.add(texto1);
        document.add(texto2);
        document.add(localData);

        document.add(assinatura);
        document.add(texto3);

        document.close();
    } catch (DocumentException | IOException de) {
        System.err.println(de.getMessage());
    }

}

From source file:es.jscan.Pantallas.PantallaPrincipal.java

License:Apache License

@Action
public Boolean guardarPdf() {
    if (contimagen < 1) {
        return false;
    }//from w w w . j  a  v  a2s  .  c o m

    final PantallaBarra pantbarra = new PantallaBarra(PantallaPrincipal.this, false);
    pantbarra.setTitle("Generando fichero de destino");
    pantbarra.botonParar.setVisible(false);
    errorpdf = false;

    new Thread() {
        @Override
        public void run() {
            Document pdfDocument = new Document();
            //                Document pdfDocument = new Document(PageSize.A4, 0, 0, 0, 0);
            Calendar cal = Calendar.getInstance();
            String anio = String.valueOf(cal.get(Calendar.YEAR));
            String mes = String.valueOf((cal.get(Calendar.MONTH) + 1)).length() == 1
                    ? "0" + String.valueOf((cal.get(Calendar.MONTH) + 1))
                    : String.valueOf((cal.get(Calendar.MONTH) + 1));
            String dia = String.valueOf(cal.get(Calendar.DAY_OF_MONTH)).length() == 1
                    ? "0" + String.valueOf(cal.get(Calendar.DAY_OF_MONTH))
                    : String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
            String hora = String.valueOf(cal.get(Calendar.HOUR_OF_DAY)).length() == 1
                    ? "0" + String.valueOf(cal.get(Calendar.HOUR_OF_DAY))
                    : String.valueOf(cal.get(Calendar.HOUR_OF_DAY));
            String minuto = String.valueOf(cal.get(Calendar.MINUTE)).length() == 1
                    ? "0" + String.valueOf(cal.get(Calendar.MINUTE))
                    : String.valueOf(cal.get(Calendar.MINUTE));
            String segundo = String.valueOf(cal.get(Calendar.SECOND)).length() == 1
                    ? "0" + String.valueOf(cal.get(Calendar.SECOND))
                    : String.valueOf(cal.get(Calendar.SECOND));

            try {
                if (DEBUG) {
                    Utilidades.escribeLog("Generando PDFs -guardarPdf-");
                }
                if (contimagen < 2) {
                    pantbarra.barra.setMinimum(1);
                    pantbarra.barra.setMaximum(2);
                } else {
                    pantbarra.barra.setMinimum(1);
                    pantbarra.barra.setMaximum(rutaboton.length);
                }
                pantbarra.barra.setValue(1);
                pantbarra.setTitle(pantbarra.getTitle());
                pantbarra.validate();

                String nombrefichero = "Documentacion.pdf";
                String ruta = rutalote + separador + nombrefichero + ".pdf";

                if (!textoFichero.getText().isEmpty()) {
                    nombrefichero = textoFichero.getText() + ".pdf";
                }

                if (!textoDirectorio.getText().isEmpty()) {
                    ruta = textoDirectorio.getText();
                    ruta = ruta + separador + nombrefichero;
                }

                FileOutputStream ficheroPdf = new FileOutputStream(ruta);
                File filename = new File(rutaboton[0].toString());
                java.awt.image.BufferedImage imagen = javax.imageio.ImageIO.read(filename);
                com.itextpdf.text.Image imagenpdf = com.itextpdf.text.Image.getInstance(imagen, null);
                pdfDocument.setPageSize(new Rectangle(imagenpdf.getWidth(), imagenpdf.getHeight()));
                PdfWriter writer = PdfWriter.getInstance(pdfDocument, ficheroPdf);
                writer.open();
                pdfDocument.open();
                pdfDocument.addHeader("IP", lote.substring(16, 19) + "." + lote.substring(19, 22) + "."
                        + lote.substring(22, 25) + "." + lote.substring(25, 28));
                pdfDocument.addHeader("fechadigita",
                        lote.substring(6, 8) + "/" + lote.substring(4, 6) + "/" + lote.substring(0, 4) + " "
                                + lote.substring(9, 11) + ":" + lote.substring(11, 13) + ":"
                                + lote.substring(13, 15));
                pdfDocument.addHeader("fechacreacion",
                        dia + "/" + mes + "/" + anio + " " + hora + ":" + minuto + ":" + segundo);

                for (int i = 0; i < rutaboton.length; i++) {
                    filename = new File(rutaboton[i].toString());
                    imagen = javax.imageio.ImageIO.read(filename);
                    imagenpdf = com.itextpdf.text.Image.getInstance(imagen, null);
                    //                        imagenpdf.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight());
                    //                        imagenpdf.setAlignment(com.itextpdf.text.Image.ALIGN_JUSTIFIED_ALL);
                    //                        com.itextpdf.text.Image instance = com.itextpdf.text.Image.getInstance(imagenpdf);
                    //                        pdfDocument.setPageSize(new com.itextpdf.text.Rectangle(PageSize.A4.getWidth(), PageSize.A4.getHeight()));
                    pantbarra.barra.setValue(i);
                    pantbarra.setTitle(titulo + "     " + (i + 1) + " de " + rutaboton.length);
                    pdfDocument.setPageSize(new Rectangle(imagenpdf.getWidth(), imagenpdf.getHeight()));
                    //                        pdfDocument.add(instance);
                    pdfDocument.add(imagenpdf);
                    pdfDocument.newPage();
                    pantbarra.validate();
                }
                pdfDocument.close();
                writer.close();
            } catch (Exception e) {
                Utilidades.escribeLog("Error Generando PDFs -guardarPdf- " + e.getMessage());
                errorpdf = true;
            }
            pantbarra.dispose();
        }
    }.start();
    pantbarra.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
    pantbarra.setVisible(false);
    pantbarra.setVisible(true);
    return !errorpdf;
}

From source file:es.jscan.Pantallas.PantallaPrincipal.java

License:Apache License

private void tiffToPdf(String origen, String destino) {
    try {/*from   ww w.  j  a  v  a  2 s . c o  m*/
        //Read the Tiff File
        RandomAccessFileOrArray myTiffFile = new RandomAccessFileOrArray(origen);
        //Find number of images in Tiff file
        int numberOfPages = TiffImage.getNumberOfPages(myTiffFile);
        //  System.out.println("Number of Images in Tiff File" + numberOfPages);
        com.itextpdf.text.Image tempImage = TiffImage.getTiffImage(myTiffFile, 1);
        Document TifftoPDF = new Document();
        TifftoPDF.setPageSize(new Rectangle(tempImage.getWidth(), tempImage.getHeight()));
        PdfWriter.getInstance(TifftoPDF, new FileOutputStream(destino));
        TifftoPDF.open();
        for (int i = 1; i <= numberOfPages; i++) {
            tempImage = TiffImage.getTiffImage(myTiffFile, i);
            TifftoPDF.setPageSize(new Rectangle(tempImage.getWidth(), tempImage.getHeight()));
            TifftoPDF.add(tempImage);
        }
        TifftoPDF.close();
    } catch (Exception ex) {
        Utilidades.escribeLog("Error al convertir de Tiff a PDF -tiffToPdf- Error " + ex.getMessage());
    }

}

From source file:Evento.action.ZapisDoPdfAction.java

License:Apache License

public void createPDF(String[] imgURL, String place, String album) throws DocumentException {
    Document document = new Document();
    Rectangle pageSize = new Rectangle(szerokosc, wysokosc);
    document.setPageSize(pageSize);

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

        PdfWriter.getInstance(document, new FileOutputStream(new File(place, "nowy.pdf")));
        document.open();

        Image tlo = Image.getInstance(new URL(zdjecieTla));
        tlo.setAbsolutePosition(0f, 0f);
        document.add(tlo);
        Paragraph preface = new Paragraph(album,
                new Font(FontFamily.HELVETICA, 72, Font.BOLDITALIC, new BaseColor(255, 255, 255)));
        preface.setAlignment(Element.ALIGN_CENTER);
        document.add(preface);
        document.newPage();
        for (int i = 0; i < imgURL.length; i++) {

            Image tlo2 = Image.getInstance(new URL(zdjecieTla));
            tlo2.setAbsolutePosition(0f, 0f);
            document.add(tlo2);
            Image image2 = Image.getInstance(new URL(imgURL[i]));
            if (szerokosc * 1.5f <= image2.getWidth() || wysokosc * 1.5f <= image2.getHeight()) {
                image2.scaleAbsolute(image2.getWidth() * 0.25f, image2.getHeight() * 0.25f);
                image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth() * 0.25f) / 2,
                        wysokosc / 2 - (image2.getHeight() * 0.25f) / 2);
            } else if ((szerokosc * 0.8f <= image2.getWidth() || wysokosc * 0.8f <= image2.getHeight())
                    && (szerokosc * 1.2f >= image2.getWidth() || wysokosc * 1.2f >= image2.getHeight())) {
                image2.scaleAbsolute(image2.getWidth() * 0.8f, image2.getHeight() * 0.8f);
                image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth() * 0.8f) / 2,
                        wysokosc / 2 - (image2.getHeight() * 0.8f) / 2);
            } else if ((szerokosc * 0.4f >= image2.getWidth() || wysokosc * 0.4f >= image2.getHeight())
                    && (szerokosc * 0.7f <= image2.getWidth() || wysokosc * 0.7f <= image2.getHeight())) {
                image2.scaleAbsolute(image2.getWidth() * 1.4f, image2.getHeight() * 1.4f);
                image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth() * 1.4f) / 2,
                        wysokosc / 2 - (image2.getHeight() * 1.4f) / 2);
            } else {
                image2.scaleAbsolute(image2.getWidth(), image2.getHeight());
                image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth()) / 2,
                        wysokosc / 2 - (image2.getHeight()) / 2);
            }
            for (int k = 0; k <= 1000; k++)
                ;
            for (int j = 0; j <= 1000; j++)
                ;
            document.add(image2);
            document.newPage();
        }

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

From source file:Excel.pdfsJavaGenerador.java

public void run() {
    Document documento = new Document();
    documento.setPageSize(PageSize.A4.rotate());
    int i = 1;/*from  w  w  w. j a v a  2  s  .  c  o  m*/
    String arch = periodo + "_Iva Ventas.pdf";

    File fich = new File(arch);

    FileOutputStream fichero;
    try {
        pdfsJavaGenerador pdf;

        ArrayList listado = new ArrayList();
        String sql = "select * from ivaventas where periodo='" + periodo + "' order by numero";
        Transaccionable tra = new ConeccionLocal();
        ResultSet rs = tra.leerConjuntoDeRegistros(sql);
        while (rs.next()) {
            pdf = new pdfsJavaGenerador();
            pdf.setComprobante(rs.getString("comprobante"));
            pdf.setFecha(rs.getString("fecha"));
            pdf.setNumeroFactura(rs.getString("numero"));
            pdf.setRazonSocial(rs.getString("cliente"));
            pdf.setCondicionIva(rs.getString("condicion"));
            pdf.setCuit(rs.getString("cuit"));
            pdf.setNeto(rs.getString("neto"));
            pdf.setIva(rs.getString("iva"));
            pdf.setTotal(rs.getString("total"));
            listado.add(pdf);
        }
        rs.close();
        Integer totalItems = listado.size();
        Integer totalPaginas = totalItems / 46;
        Integer contadorPaginas = 1;
        totalPaginas = totalPaginas + 1;
        System.out.println(" items " + totalItems + " paginas " + totalPaginas);
        fichero = new FileOutputStream(arch);
        PdfWriter writer = PdfWriter.getInstance(documento, fichero);

        documento.open();
        //writer.addPageDictEntry(PdfName.ROTATE,PdfPage.SEASCAPE);
        writer.addPageDictEntry(PdfName.ROTATE, null);
        PdfContentByte cb = writer.getDirectContent();

        BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.setFontAndSize(bf, 12);
        cb.beginText();
        //cb.setTextMatrix(250,820);
        //cb.showText("Subdiario de IVA Ventas");
        cb.setFontAndSize(bf, 10);

        cb.setTextMatrix(20, 480);
        cb.showText("Periodo " + periodo);
        //cb.setTextMatrix(750,550);
        //cb.showText("Hoja "+contadorPaginas+" de "+totalPaginas);

        int renglon = 460;
        String vencimiento;
        String descripcion;
        String monto;
        String recargo;
        String total;
        String totalFinal;
        Double tot = 0.00;
        String razonSocial;
        int itt = 0;
        //aca empieza la iteracion

        //encabezados
        bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.setFontAndSize(bf, 8);
        cb.setTextMatrix(20, renglon);
        cb.showText("Cbte");
        cb.setTextMatrix(50, renglon);
        cb.showText("Fecha");
        cb.setTextMatrix(90, renglon);
        cb.showText("Nro Factura");
        cb.setTextMatrix(150, renglon);
        cb.showText("Cliente");
        cb.setTextMatrix(500, renglon);
        //tot=saldo.getCantidad() * saldo.getPrecioUnitario();
        cb.showText("Cond");
        cb.setTextMatrix(540, renglon);
        cb.showText("C.U.I.T.");
        cb.setTextMatrix(610, renglon);
        cb.showText("Neto");
        cb.setTextMatrix(660, renglon);
        cb.showText("I.V.A.");
        cb.setTextMatrix(700, renglon);
        cb.showText("Imp. Int.");
        cb.setTextMatrix(760, renglon);
        cb.showText("Total");
        renglon = renglon - 20;

        //fin encabezados
        bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.setFontAndSize(bf, 6);
        Iterator itl = listado.listIterator();
        //vencimiento="Esta cotizacin tendr vigencia 30 das ";
        Double montoCIva = 0.00;
        Double descuento = 0.00;
        Double descUnitario = 0.00;
        Double descTotal = 0.00;
        Double montoCIvaTotal = 0.00;
        Double descuentoTotal = 0.00;
        Double descUnitarioTotal = 0.00;
        Double descTotalTotal = 0.00;
        String descripcionArt = null;
        while (itl.hasNext()) {
            pdf = (pdfsJavaGenerador) itl.next();

            //vencimiento=saldo.getVencimientoString();
            /*
            descripcion="Numero Resumen de cta ";
            montoCIva=saldo.getPrecioUnitario() * 1.21;
            monto=Numeros.ConvertirNumero(montoCIva);
            recargo="10%";
            total="nada";
            */

            //recargo=String.valueOf(saldo.getRecargo());
            //tot=tot + saldo.getTotal();
            //total=String.valueOf(saldo.getTotal());

            cb.setTextMatrix(20, renglon);
            cb.showText(pdf.getComprobante());
            cb.setTextMatrix(45, renglon);
            cb.showText(pdf.getFecha());
            cb.setTextMatrix(90, renglon);
            cb.showText(pdf.getNumeroFactura());
            cb.setTextMatrix(150, renglon);

            razonSocial = pdf.getRazonSocial();

            cb.showText(razonSocial);
            cb.setTextMatrix(500, renglon);

            cb.showText(pdf.getCondicionIva());
            cb.setTextMatrix(540, renglon);
            cb.showText(pdf.getCuit());
            cb.setTextMatrix(600, renglon);

            if (pdf.getComprobante().equals("N.C.")) {
                String neto = pdf.getNeto();
                String iva = pdf.getIva();
                String totalP = pdf.getTotal();
                pdf.setNeto("-" + neto.trim());
                pdf.setIva("-" + iva.trim());
                pdf.setTotal("-" + totalP.trim());
            }
            montoCIva = montoCIva + Numeros.ConvertirStringADouble(pdf.getNeto());
            descuento = descuento + Numeros.ConvertirStringADouble(pdf.getIva());
            descTotal = descTotal + Numeros.ConvertirStringADouble(pdf.getTotal());

            cb.showText(pdf.getNeto());
            cb.setTextMatrix(650, renglon);

            cb.showText(pdf.getIva());
            cb.setTextMatrix(710, renglon);
            cb.showText("0.00");
            cb.setTextMatrix(750, renglon);

            cb.showText(pdf.getTotal());

            //descuento=descuento+saldo.getDescuento();
            renglon = renglon - 10;
            if (renglon < 30) {
                bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                cb.setFontAndSize(bf, 7);
                cb.setTextMatrix(550, renglon);
                cb.showText("Subtotal:");
                cb.setTextMatrix(600, renglon);
                cb.showText(Numeros.ConvetirNumeroDosDigitos(montoCIva));
                cb.setTextMatrix(650, renglon);
                cb.showText(Numeros.ConvetirNumeroDosDigitos(descuento));
                cb.setTextMatrix(710, renglon);
                cb.showText("0.00");
                cb.setTextMatrix(750, renglon);
                cb.showText(Numeros.ConvetirNumeroDosDigitos(descTotal));
                montoCIvaTotal = montoCIvaTotal + montoCIva;
                descuentoTotal = descuentoTotal + descuento;

                descTotalTotal = descTotalTotal + descTotal;
                descuento = 0.00;
                descTotal = 0.00;
                montoCIva = 0.00;
                renglon = 460;
                cb.endText();
                documento.newPage();
                documento.setPageSize(PageSize.A4.rotate());
                cb.beginText();

                contadorPaginas++;
                cb.setFontAndSize(bf, 12);
                //cb.setTextMatrix(250,820);
                //cb.showText("Subdiario de IVA Ventas");
                cb.setFontAndSize(bf, 10);
                cb.setTextMatrix(20, 480);
                cb.showText("Periodo " + periodo);
                //cb.setTextMatrix(750,550);
                //cb.showText("Hoja "+contadorPaginas+" de "+totalPaginas);

                //aca empieza la iteracion

                //encabezados
                bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                cb.setFontAndSize(bf, 8);
                cb.setTextMatrix(20, renglon);
                cb.showText("Cbte");
                cb.setTextMatrix(50, renglon);
                cb.showText("Fecha");
                cb.setTextMatrix(90, renglon);
                cb.showText("Nro Factura");
                cb.setTextMatrix(150, renglon);
                cb.showText("Cliente");
                cb.setTextMatrix(500, renglon);
                //tot=saldo.getCantidad() * saldo.getPrecioUnitario();
                cb.showText("Cond");
                cb.setTextMatrix(540, renglon);
                cb.showText("C.U.I.T.");
                cb.setTextMatrix(610, renglon);
                cb.showText("Neto");
                cb.setTextMatrix(660, renglon);
                cb.showText("I.V.A.");
                cb.setTextMatrix(700, renglon);
                cb.showText("Imp. Int.");
                cb.setTextMatrix(760, renglon);
                cb.showText("Total");
                renglon = renglon - 20;

                //fin encabezados
                bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                cb.setFontAndSize(bf, 6);
            }
        }

        bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.setFontAndSize(bf, 7);
        cb.setTextMatrix(540, renglon);
        cb.showText("Subtotal:");
        cb.setTextMatrix(600, renglon);
        cb.showText(Numeros.ConvetirNumeroDosDigitos(montoCIva));
        cb.setTextMatrix(650, renglon);
        cb.showText(Numeros.ConvetirNumeroDosDigitos(descuento));
        cb.setTextMatrix(710, renglon);
        cb.showText("0.00");
        cb.setTextMatrix(750, renglon);
        cb.showText(Numeros.ConvetirNumeroDosDigitos(descTotal));
        renglon = renglon - 10;

        montoCIvaTotal = montoCIvaTotal + montoCIva;
        descuentoTotal = descuentoTotal + descuento;

        descTotalTotal = descTotalTotal + descTotal;
        cb.setTextMatrix(540, renglon);
        cb.showText("Total:");
        cb.setTextMatrix(600, renglon);
        cb.showText(Numeros.ConvetirNumeroDosDigitos(montoCIvaTotal));
        cb.setTextMatrix(650, renglon);
        cb.showText(Numeros.ConvetirNumeroDosDigitos(descuentoTotal));
        cb.setTextMatrix(710, renglon);
        cb.showText("0.00");
        cb.setTextMatrix(750, renglon);
        cb.showText(Numeros.ConvetirNumeroDosDigitos(descTotalTotal));

        descuento = 0.00;
        descTotal = 0.00;
        montoCIva = 0.00;

        cb.endText();
        documento.close();

        File f = new File(arch);
        if (f.exists()) {

            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + arch);
        }
        int confirmacion = 0;
        /*
        if(doc.getArchivo().isEmpty()){
                
        }else{
        confirmacion=JOptionPane.showConfirmDialog(null, "DESEA NOTIFICAR POR MAIL?");
        if(confirmacion==0){
        //JOptionPane.showMessageDialog(null,"acepto");
                
        }
        }
            */
        System.out.println("eligio " + confirmacion);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(pdfsJavaGenerador.class.getName()).log(Level.SEVERE, null, ex);

    } catch (DocumentException ex) {
        Logger.getLogger(pdfsJavaGenerador.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(pdfsJavaGenerador.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(pdfsJavaGenerador.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:Export.CertificadoCargaMaritima.java

public String criarDoc(String numApolice, String numCliente, Contrato c, CargaMaritimaBean cm, String user,
        String moeda, String arquivo) {
    try {// w  w  w .  ja v a 2 s  .  co  m
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss");

        Font fontCabecalhoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.5f);
        Font fontCorpo = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f);
        Font fontCorpoP = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f);
        Font fontCorpoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f);
        Font fontCorpoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 10f);
        Font fontCabecalhoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 16f,
                Font.UNDERLINE);
        Font fontUK = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 5.5f, Font.ITALIC);

        PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 25f, 75f });
        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(120f, 85f);

        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);
        Phrase pTitulo = new Phrase("CErtificado Seguro de Carga Maritima".toUpperCase(), fontCorpoNG);
        pTitulo.add(new Phrase("\nMARINE CARGO CERTIFICATE", fontUK));
        PdfPCell cellTitulo = new PdfPCell(pTitulo);
        cellTitulo.setBorder(0);
        cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER);
        pTableTitulo.addCell(cellTitulo);

        PdfPTable pTableCorpoUm = new PdfPTable(new float[] { 100 });
        PdfPTable pTableCorpoDois = new PdfPTable(new float[] { 50, 50 });
        PdfPTable pTableCorpoTres = new PdfPTable(new float[] { 100 });

        PdfPCell cellCorpopUm = new PdfPCell();
        cellCorpopUm.setBorder(0);
        PdfPCell cellCorpopDois1 = new PdfPCell();
        cellCorpopDois1.setBorder(0);
        PdfPCell cellCorpopDois2 = new PdfPCell();
        cellCorpopDois2.setBorder(0);
        PdfPCell cellCorpopTres = new PdfPCell();
        cellCorpopTres.setBorder(0);

        Paragraph pCorpoUm1 = new Paragraph(
                "Certificado de seguro emitido sob contracto aberto n".toUpperCase(), fontCorpoN);
        pCorpoUm1.add(
                new Phrase("\ncertificate OF insurance issued under contract open No.".toUpperCase(), fontUK));
        Paragraph pCorpoUm2 = new Paragraph("mbito da cobertura: ".toUpperCase(), fontCorpoN);
        pCorpoUm2.add(new Phrase("\nSCOPE OF COVER", fontUK));
        Paragraph pCorpoUm3 = new Paragraph(
                "Este certificado atesta que a Companhia tem as mencionadas, sob seguro para viagem (s) e valore (s) declarados em favor de",
                fontCorpo);
        pCorpoUm3.add(new Phrase(
                "\nTHIS IS TO CERTIFY THAT THE COMPANY HAS INSURED THE UNDER MENTIONED GOODS FOR THE VOYGE (S) AND VALUE (S) STATED ON BEHALF OF",
                fontUK));

        cellCorpopUm.addElement(pCorpoUm1);
        cellCorpopUm.addElement(pCorpoUm2);
        cellCorpopUm.addElement(pCorpoUm3);
        pTableCorpoUm.addCell(cellCorpopUm);

        Paragraph pCorpoDois11 = new Paragraph("Taxa Maritima: ", fontCorpo);
        pCorpoDois11.add(new Phrase("\nMARINE RATE", fontUK));
        Paragraph pCorpoDois12 = new Paragraph("Taxa Guerra: ", fontCorpo);
        pCorpoDois12.add(new Phrase("\nWAR RATE", fontUK));

        cellCorpopDois1.addElement(pCorpoDois11);
        cellCorpopDois1.addElement(pCorpoDois12);
        pTableCorpoDois.addCell(cellCorpopDois1);

        cellCorpopUm.addElement(pCorpoUm1);
        cellCorpopUm.addElement(pCorpoUm2);

        Paragraph pCorpoDois21 = new Paragraph("Nota de Bebito: ", fontCorpo);
        pCorpoDois21.add(new Phrase("\nDEBIT NOTE NO", fontUK));
        Paragraph pCorpoDois22 = new Paragraph("Total de Prmio: ", fontCorpo);
        pCorpoDois22.add(new Phrase("\nGROSS PREMIUM", fontUK));

        cellCorpopDois2.addElement(pCorpoDois21);
        cellCorpopDois2.addElement(pCorpoDois22);
        pTableCorpoDois.addCell(cellCorpopDois2);

        Paragraph pCorpoTres1 = new Paragraph("Taxa Superintendente: ", fontCorpo);
        pCorpoTres1.add(new Phrase("\nSuperintendent RATE".toUpperCase(), fontUK));
        Paragraph pCorpoTres2 = new Paragraph("Taxa Interna de Trnsito: ", fontCorpo);
        pCorpoTres2.add(new Phrase("\nINLANDTraffic Rate", fontUK));
        Paragraph pCorpoTres3 = new Paragraph("Taxa Total: ", fontCorpo);
        pCorpoTres3.add(new Phrase("\nTOTAL RATE", fontUK));
        Paragraph pCorpoTres4 = new Paragraph("Segurado: ", fontCorpo);
        pCorpoTres4.add(new Phrase("\nInsured".toUpperCase(), fontUK));
        Paragraph pCorpoTres5 = new Paragraph("Meio de Transporte: " + cm.getCargaMaritima().getFormaEnvio(),
                fontCorpo);
        pCorpoTres5.add(new Phrase("\nMODE OF CONVEYANCE", fontUK));

        //Paragraph pCorpoTres6_1 = new Paragraph("Medadoria Assegurada: ",fontCorpo);
        Paragraph pCorpoTres6 = new Paragraph("De " + cm.getCargaMaritima().getPaisOrigem() + " Para: "
                + cm.getCargaMaritima().getPaisDestino(), fontCorpo);
        pCorpoTres6.add(new Phrase("\nFROM                         TO", fontUK));
        Paragraph pCorpoTres7 = new Paragraph("Juros: ", fontCorpo);
        pCorpoTres7.add(new Phrase("\nINTEREST", fontUK));
        Paragraph pCorpoTres8 = new Paragraph("Valor Segurado: ", fontCorpo);
        pCorpoTres8.add(new Phrase("\nINSURED VALUE", fontUK));
        Paragraph pCorpoTres9 = new Paragraph(
                "CONDIES: Sujeitas as seguintes clsulas e garantias (Ver anexo A)", fontCorpoN);
        pCorpoTres9.add(new Phrase(
                "\nCONDITIONS : Subject to the following clsulas and warranteis (SEE APPENDICIX A)", fontUK));
        Paragraph pCorpoTres10 = new Paragraph(
                "No caso de perda ou dano que se presume a companhia ser reponsvel, deve-se comunicar de imediato  NICOM SEGUROS STP"
                        + " para ser feita a vistoria (Por favor volte).",
                fontCorpo);
        pCorpoTres10.add(new Phrase(
                "\nIn the event of loss or damage for which company is presumed to be liable, immediate resquest for survey must be made to  NICON SEGUROS STP (PLEASE TURN OVER).",
                fontUK));

        Paragraph pCorpoTres11 = new Paragraph(
                "No caso de perda ou dano este certificado, depois de autenticado, deve ser anexo a reclamao acompanhado"
                        + " de relatrio de auditoria e da factura original do desembarque, a cpia autenticada ou original da factura e uaisquer outros documentos relativo.",
                fontCorpo);
        pCorpoTres10.add(new Phrase(
                "\nIn case of loss or damage this certificate, must be annexed to the claim note accompaneid by the repost, original bill of landing, true copy"
                        + " or original invoice and any other relevant documenent.",
                fontUK));

        Paragraph pCorpoTres12 = new Paragraph();
        Phrase p1 = new Phrase("Nota: ", fontCorpoN);
        Phrase p2 = new Phrase(
                "A Empresa compromete-se a emitir uma aplice que cobre as mercadorias descritas no pedido",
                fontCorpo);
        Phrase p3 = new Phrase(
                "\nThe Company undertakes to issue a policy covering the good described herein on request.",
                fontUK);
        pCorpoTres12.add(p1);
        pCorpoTres12.add(p2);
        pCorpoTres12.add(p3);

        cellCorpopTres.addElement(pCorpoTres1);
        cellCorpopTres.addElement(pCorpoTres2);
        cellCorpopTres.addElement(pCorpoTres3);
        cellCorpopTres.addElement(pCorpoTres4);
        cellCorpopTres.addElement(pCorpoTres5);
        //cellCorpopTres.addElement(pCorpoTres6_1);
        cellCorpopTres.addElement(pCorpoTres6);
        cellCorpopTres.addElement(pCorpoTres7);
        cellCorpopTres.addElement(pCorpoTres8);
        cellCorpopTres.addElement(cellNull.getPhrase());
        cellCorpopTres.addElement(pCorpoTres9);
        cellCorpopTres.addElement(pCorpoTres10);
        cellCorpopTres.addElement(cellNull.getPhrase());
        cellCorpopTres.addElement(pCorpoTres11);
        cellCorpopTres.addElement(cellNull.getPhrase());
        cellCorpopTres.addElement(pCorpoTres12);
        pTableCorpoTres.addCell(cellCorpopTres);

        PdfPTable pTableAssinaturaTitulo = new PdfPTable(1);
        PdfPTable pTableAssinatura = new PdfPTable(new float[] { 50f, 50f });

        Paragraph pUK = new Paragraph("", fontCorpo);
        pUK.add(new Phrase("Assinaturas", fontCorpoN));
        pUK.add(new Phrase("Signature", fontUK));
        PdfPCell cellAssinatora = new PdfPCell(pUK);
        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);

        pUK = new Paragraph("", fontCorpo);
        pUK.add(new Phrase("Pela NICON SEGUROS STP", fontCorpoN));
        pUK.add(new Phrase("For NICON SEGUROS STP", fontUK));
        PdfPCell celllinha11 = new PdfPCell(pUK);
        celllinha11.setBorder(0);
        celllinha11.setHorizontalAlignment(Element.ALIGN_CENTER);

        pUK = new Paragraph("", fontCorpo);
        pUK.add(new Phrase("O Segurado", fontCorpoN));
        pUK.add(new Phrase("Insured", fontUK));
        PdfPCell celllinha21 = new PdfPCell(pUK);
        celllinha21.setBorder(0);
        celllinha21.setHorizontalAlignment(Element.ALIGN_CENTER);

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

        Document documento = new Document();
        documento.setPageSize(PageSize.A4);
        documento.setMargins(20f, 20f, 35f, 5f);

        File f = new File(arquivo + "/" + user + "/Seguro Carga Maritima/");
        f.mkdirs();
        String Ddata = sdf.format(new Date());
        f = new File(f.getAbsoluteFile() + "/" + "Certificado Carga Maritima " + Ddata + ".pdf");

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

        OutputStream outputStraem = new FileOutputStream(f);
        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);
        }

        documento.open();
        documento.add(pTableEmpresaPricipal);
        documento.add(pTableNull);
        documento.add(pTableTitulo);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableCorpoUm);
        documento.add(pTableNull);
        documento.add(pTableCorpoDois);
        documento.add(pTableCorpoTres);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableAssinaturaTitulo);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableAssinatura);
        documento.close();

        //           PrintPdf printPdf = new PrintPdf(f.getAbsolutePath(), f.getAbsolutePath(), 0, 595f,842f,"Enviar Para o OneNote 2013",1); 
        //           //PrintPdf printPdf = new PrintPdf(f.getAbsolutePath(), f.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;
}

From source file:Export.CertificadoMaritimo.java

public String criarDoc(String numApolice, String numCliente, MaritimoBean mb, Contrato c, String user,
        String moeda, String arquivo) {
    try {/*from ww  w. j a  va2 s  . com*/
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss");

        Font fontCabecalhoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.5f);
        Font fontCorpo = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f);
        Font fontCorpoP = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f);
        Font fontCorpoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f);
        Font fontCorpoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 10f);
        Font fontCabecalhoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 16f,
                Font.UNDERLINE);

        PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 25f, 75f });
        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(120f, 85f);

        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);
        Phrase pTitulo = new Phrase("CErtificado Seguro de Maritimo".toUpperCase(), fontCorpoNG);
        PdfPCell cellTitulo = new PdfPCell(pTitulo);
        cellTitulo.setBorder(0);
        cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER);
        pTableTitulo.addCell(cellTitulo);

        PdfPTable pTableCorpoUm = new PdfPTable(new float[] { 100 });
        PdfPTable pTableCorpoDois = new PdfPTable(new float[] { 50, 50 });
        PdfPTable pTableCorpoTres = new PdfPTable(new float[] { 100 });

        PdfPCell cellCorpopUm = new PdfPCell();
        cellCorpopUm.setBorder(0);
        PdfPCell cellCorpopDois1 = new PdfPCell();
        cellCorpopDois1.setBorder(0);
        PdfPCell cellCorpopDois2 = new PdfPCell();
        cellCorpopDois2.setBorder(0);
        PdfPCell cellCorpopTres = new PdfPCell();
        cellCorpopTres.setBorder(0);

        Paragraph pCorpoUm1 = new Paragraph(
                "Certificado de seguro emitido sob contracto aberto n".toUpperCase(), fontCorpoN);
        Paragraph pCorpoUm2 = new Paragraph("Abimto de Cortura: ".toUpperCase(), fontCorpoN);
        Paragraph pCorpoUm3 = new Paragraph(
                "Este certificado atesta que a Companhia tem as mencionadas, sob seguro para viagem (s) e valore (s) declarados em favor de",
                fontCorpo);

        cellCorpopUm.addElement(pCorpoUm1);
        cellCorpopUm.addElement(pCorpoUm2);
        cellCorpopUm.addElement(pCorpoUm3);
        pTableCorpoUm.addCell(cellCorpopUm);

        Paragraph pCorpoDois11 = new Paragraph("Taxa Maritima: ", fontCorpo);
        Paragraph pCorpoDois12 = new Paragraph("Taxa Guerra: ", fontCorpo);
        cellCorpopDois1.addElement(pCorpoDois11);
        cellCorpopDois1.addElement(pCorpoDois12);
        pTableCorpoDois.addCell(cellCorpopDois1);

        cellCorpopUm.addElement(pCorpoUm1);
        cellCorpopUm.addElement(pCorpoUm2);

        Paragraph pCorpoDois21 = new Paragraph("Nota de Bebito: ", fontCorpo);
        Paragraph pCorpoDois22 = new Paragraph("Total de Prmio: ", fontCorpo);
        cellCorpopDois2.addElement(pCorpoDois21);
        cellCorpopDois2.addElement(pCorpoDois22);
        pTableCorpoDois.addCell(cellCorpopDois2);

        Paragraph pCorpoTres1 = new Paragraph("Taxa Superintendente: ", fontCorpo);
        Paragraph pCorpoTres2 = new Paragraph("Taxa Interna de Trnsito: ", fontCorpo);
        Paragraph pCorpoTres3 = new Paragraph("Taxa Total: ", fontCorpo);
        Paragraph pCorpoTres4 = new Paragraph("Segurado: ", fontCorpo);
        Paragraph pCorpoTres5 = new Paragraph("Meio de Transporte: ", fontCorpo);
        Paragraph pCorpoTres6 = new Paragraph("De   Para: ", fontCorpo);
        Paragraph pCorpoTres7 = new Paragraph("Juros: ", fontCorpo);
        Paragraph pCorpoTres8 = new Paragraph("Valor Segurado: ", fontCorpo);
        Paragraph pCorpoTres9 = new Paragraph(
                "CONDIES: Sujeitas as seguintes clsulas e garantias (Ver anexo A)", fontCorpoN);
        Paragraph pCorpoTres10 = new Paragraph(
                "No caso de perda ou dano que se presume a companhia ser reponsvel, deve-se comunicar de imediato  NICOM SEGUROS STP"
                        + " para ser feita a vistoria (Por favor volte).",
                fontCorpo);
        Paragraph pCorpoTres11 = new Paragraph(
                "No caso de perda ou dano este certificado, depois de autenticado, deve ser anexo a reclamao acompanhado"
                        + " de relatrio de auditoria e da factura original do desembarque, a cpia autenticada ou original da factura e uaisquer outros documentos relativo.",
                fontCorpo);
        Paragraph pCorpoTres12 = new Paragraph();
        Phrase p1 = new Phrase("Nota: ", fontCorpoN);
        Phrase p2 = new Phrase(
                "A Empresa compromete-se a emitir uma aplice que cobre as mercadorias descritas no pedido",
                fontCorpo);
        pCorpoTres12.add(p1);
        pCorpoTres12.add(p2);

        cellCorpopTres.addElement(pCorpoTres1);
        cellCorpopTres.addElement(pCorpoTres2);
        cellCorpopTres.addElement(pCorpoTres3);
        cellCorpopTres.addElement(pCorpoTres4);
        cellCorpopTres.addElement(pCorpoTres5);
        cellCorpopTres.addElement(pCorpoTres6);
        cellCorpopTres.addElement(pCorpoTres7);
        cellCorpopTres.addElement(pCorpoTres8);
        cellCorpopTres.addElement(cellNull.getPhrase());
        cellCorpopTres.addElement(pCorpoTres9);
        cellCorpopTres.addElement(cellNull.getPhrase());
        cellCorpopTres.addElement(pCorpoTres10);
        cellCorpopTres.addElement(cellNull.getPhrase());
        cellCorpopTres.addElement(pCorpoTres11);
        cellCorpopTres.addElement(cellNull.getPhrase());
        cellCorpopTres.addElement(pCorpoTres12);
        pTableCorpoTres.addCell(cellCorpopTres);

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

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

        Document documento = new Document();
        documento.setPageSize(PageSize.A4);
        documento.setMargins(20f, 20f, 35f, 5f);

        //            File f= new File("Documentos\\"+user+"\\Seguro Maritimo\\");
        //            f.mkdirs();
        //            f =new File(f.getAbsoluteFile()+"\\"+"Certificado Seguro Maritimo "+sdf.format(new Date())+".pdf");

        File f = new File(arquivo + "/" + user + "/Seguro Maritimo/");
        f.mkdirs();
        String Ddata = sdf.format(new Date());
        f = new File(f.getAbsoluteFile() + "/" + "Certificado Seguro Maritimo " + Ddata + ".pdf");

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

        OutputStream outputStraem = new FileOutputStream(f);
        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);
        }

        documento.open();
        documento.add(pTableEmpresaPricipal);
        documento.add(pTableNull);
        documento.add(pTableTitulo);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableCorpoUm);
        documento.add(pTableNull);
        documento.add(pTableCorpoDois);
        documento.add(pTableCorpoTres);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableAssinaturaTitulo);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableAssinatura);
        documento.close();

        //           PrintPdf printPdf = new PrintPdf(f.getAbsolutePath(), f.getAbsolutePath(), 0, 595f,842f,"Enviar Para o OneNote 2013",1); 
        //           //PrintPdf printPdf = new PrintPdf(f.getAbsolutePath(), f.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;
}