Example usage for com.itextpdf.text Document addAuthor

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

Introduction

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

Prototype


public boolean addAuthor(String author) 

Source Link

Document

Adds the author to a Document.

Usage

From source file:cis_690_report.DynamicReporter.java

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

    // 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  www . j av a  2 s .c om*/
    window.setVisible(true);

    String Path;
    Path = "C:/Users/Shubh Chopra/Documents/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);

        //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);
        DynamicReporter re;
        re = new DynamicReporter();

        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;
            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(Reporter.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Reporter.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:cis_690_report.DynamicReporter.java

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

    // 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  ww.j a va 2  s.c o  m*/
    window.setVisible(true);

    String Path;
    Path = "C:/Users/Shubh Chopra/Documents/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);

        //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);
        DynamicReporter re;
        re = new DynamicReporter();

        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;
            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(Reporter.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Reporter.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:cis_690_report.Reporter.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();
        }/*from ww w  . java  2s. c  om*/
        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(Reporter.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);
            Reporter re;
            re = new Reporter();
            //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(Reporter.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Reporter.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:climbingcompranking.model.ranking.RankingGenerator.java

License:Open Source License

public void createRankingPDF(String competitionName, CompetitionType compType) {
    doTheRanking(compType);//from  ww w.ja  va  2s .c o m
    try {
        Document document = new Document(PageSize.A4.rotate()); // Landscape
        Date date = new Date();
        String dateStr = "";
        if (Locale.getDefault().equals(Locale.FRANCE)) {
            dateStr = new SimpleDateFormat("dd-MM-yyyy").format(date);
        } else {
            dateStr = new SimpleDateFormat("yyyy-MM-dd").format(date);
        }
        PdfWriter.getInstance(document,
                new FileOutputStream("data/pdf/" + competitionName + '-' + dateStr + ".pdf"));

        document.open();
        // Meta data
        document.addTitle(competitionName);
        document.addSubject(competitionName + " ranking.");
        document.addKeywords(competitionName + ", ranking, climbingcompetition, climbcompranking");
        document.addAuthor("ClimbingCompRanking - https://github.com/Yaty/ClimbingCompRanking");
        document.addCreator("ClimbingCompRanking - https://github.com/Yaty/ClimbingCompRanking");
        document.addCreationDate();
        document.setMargins(0, 0, 0, 0);

        PdfPCell club = new PdfPCell(new Phrase(I18n.MODEL.getString("Club")));
        PdfPCell climberName = new PdfPCell(new Phrase(I18n.MODEL.getString("ClimberName")));
        PdfPCell ranking = new PdfPCell(new Phrase(I18n.MODEL.getString("Ranking")));

        for (Map.Entry<Category, ArrayList<Climber>> climbersCategory : climbersMap.entrySet()) {
            if (climbersCategory.getValue().isEmpty())
                continue;
            document.newPage();
            // Title
            Paragraph title = new Paragraph(
                    competitionName + " : " + climbersCategory.getKey().getCategoryName());
            title.setAlignment(Element.ALIGN_CENTER);
            title.setFont(new Font(Font.FontFamily.HELVETICA, 36));
            title.setSpacingAfter(20);

            // Table
            PdfPTable table = null;
            switch (compType) {
            case BOULDERING:
            case LEAD:
            case SPEED:
                table = new PdfPTable(3); // Club | Full name | Ranking
                table.addCell(club);
                table.addCell(climberName);
                table.addCell(ranking);
                for (Climber climber : climbersCategory.getValue()) {
                    table.addCell(new PdfPCell(new Phrase(climber.getClubName())));
                    table.addCell(new PdfPCell(new Phrase(climber.getFullName())));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank()))));
                }
                break;
            case LEAD_AND_BOULDERING:
                table = new PdfPTable(6); // Club | Full name | Ranking
                table.addCell(club);
                table.addCell(climberName);
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum"))));
                table.addCell(ranking);
                for (Climber climber : climbersCategory.getValue()) {
                    table.addCell(new PdfPCell(new Phrase(climber.getClubName())));
                    table.addCell(new PdfPCell(new Phrase(climber.getFullName())));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank()))));
                    table.addCell(
                            new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank()))));
                    table.addCell(new PdfPCell(
                            new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType)))));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank()))));
                }
                break;
            case SPEED_AND_BOULDERING:
                table = new PdfPTable(6); // Club | Full name | Ranking
                table.addCell(club);
                table.addCell(climberName);
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum"))));
                table.addCell(ranking);
                for (Climber climber : climbersCategory.getValue()) {
                    table.addCell(new PdfPCell(new Phrase(climber.getClubName())));
                    table.addCell(new PdfPCell(new Phrase(climber.getFullName())));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank()))));
                    table.addCell(
                            new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank()))));
                    table.addCell(new PdfPCell(
                            new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType)))));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank()))));
                }
                break;
            case SPEED_AND_LEAD:
                table = new PdfPTable(6); // Club | Full name | Ranking
                table.addCell(club);
                table.addCell(climberName);
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum"))));
                table.addCell(ranking);
                for (Climber climber : climbersCategory.getValue()) {
                    table.addCell(new PdfPCell(new Phrase(climber.getClubName())));
                    table.addCell(new PdfPCell(new Phrase(climber.getFullName())));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank()))));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank()))));
                    table.addCell(new PdfPCell(
                            new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType)))));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank()))));
                }
                break;
            case COMBINED:
                table = new PdfPTable(7); // Club | Full name | Ranking
                table.addCell(club);
                table.addCell(climberName);
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking"))));
                table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum"))));
                table.addCell(ranking);
                for (Climber climber : climbersCategory.getValue()) {
                    table.addCell(new PdfPCell(new Phrase(climber.getClubName())));
                    table.addCell(new PdfPCell(new Phrase(climber.getFullName())));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank()))));
                    table.addCell(
                            new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank()))));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank()))));
                    table.addCell(new PdfPCell(
                            new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType)))));
                    table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank()))));
                }
                break;
            }

            // Alignment
            for (PdfPRow row : table.getRows()) {
                PdfPCell[] cells = row.getCells();
                for (PdfPCell cellToAlign : cells) {
                    cellToAlign.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cellToAlign.setVerticalAlignment(Element.ALIGN_CENTER);
                }
            }

            table.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.setHeaderRows(1);

            document.add(title);
            document.add(table);
        }
        document.close();
    } catch (DocumentException | FileNotFoundException ex) {
        Logger.getLogger(RankingGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:co.ordinate.printer.NewJFrame.java

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

    new SwingWorker<Object, Object>() {
        String filename;//from   w  ww  .j a  va  2 s  . c o m

        @Override
        protected void done() {

            ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. ");

        }

        @Override
        protected Object doInBackground() throws Exception {

            Document doc = new Document();
            try {
                PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("A4.pdf"));
                doc.open();
                doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : ");
                doc.addSubject("Confidential Report Eyes Only");
                doc.addKeywords("");
                doc.addAuthor("SOS");
                doc.addCreator("SOS");

                // A4 = 210mm x 297mm ~ 605points x 855points
                doc.setPageSize(PageSize.A4);
                doc.setMargins(10f, 10f, 10f, 10f);

                /////////////////////////////////////////////////////////////
                int pageno = 1;

                for (int i = 0; i == pageno; i++) {

                    //    doc.add(imageRight);
                }

                PdfContentByte cb = writer.getDirectContent();

                int i = 1;
                while (i <= pageno) {
                    doc.newPage();

                    i++;
                }
                BaseFont labelFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", true);
                float width = doc.getPageSize().getWidth();
                float height = doc.getPageSize().getHeight();
                for (float h = 0; h <= height; h++) {
                    for (float w = 0; w <= width; w++) {
                        cb.beginText();
                        // cb.setColorFill(TITLE_COLOR);
                        cb.setFontAndSize(labelFont, 2);
                        cb.setTextMatrix(w, h);

                        cb.showText(String.valueOf(h) + ":" + String.valueOf(w));
                        cb.endText();
                        w += 15;
                    }
                    h += 2;
                }
                cb.beginText();
                // cb.setColorFill(TITLE_COLOR);
                cb.setFontAndSize(labelFont, 4);
                cb.setTextMatrix(20f, 220f);
                cb.showText("abcd");
                cb.endText();

            } catch (Exception e) {
                System.err.println(e.getMessage());

                ConsoleMsg(e.getMessage());
            } finally {
                doc.close();
            }

            ConsoleMsg("PDF... GENERATED");

            return null;
            //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }.execute();

    // TODO add your handling code here:
}

From source file:co.ordinate.printer.NewJFrame.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    new SwingWorker<Object, Object>() {
        String filename;/*from w ww  .  ja  va2 s  .c o m*/

        @Override
        protected void done() {

            ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. ");

        }

        @Override
        protected Object doInBackground() throws Exception {

            Document doc = new Document();
            try {
                PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("letter.pdf"));
                doc.open();
                doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : ");
                doc.addSubject("Confidential Report Eyes Only");
                doc.addKeywords("");
                doc.addAuthor("SOS");
                doc.addCreator("SOS");

                // A4 = 210mm x 297mm ~ 605points x 855points
                doc.setPageSize(PageSize.LETTER);
                doc.setMargins(10f, 10f, 10f, 10f);

                /////////////////////////////////////////////////////////////
                int pageno = 1;

                for (int i = 0; i == pageno; i++) {

                    //    doc.add(imageRight);
                }

                PdfContentByte cb = writer.getDirectContent();

                int i = 1;
                while (i <= pageno) {
                    doc.newPage();

                    i++;
                }
                BaseFont labelFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", true);
                float width = doc.getPageSize().getWidth();
                float height = doc.getPageSize().getHeight();
                for (float h = 0; h <= height; h++) {
                    for (float w = 0; w <= width; w++) {
                        cb.beginText();
                        // cb.setColorFill(TITLE_COLOR);
                        cb.setFontAndSize(labelFont, 4);
                        cb.setTextMatrix(w, h);

                        cb.showText(String.valueOf(h) + ":" + String.valueOf(w));
                        cb.endText();
                        w += 25;
                    }
                    h += 5;
                }
                cb.beginText();
                // cb.setColorFill(TITLE_COLOR);
                cb.setFontAndSize(labelFont, 4);
                cb.setTextMatrix(20f, 220f);
                cb.showText("abcd");
                cb.endText();

            } catch (Exception e) {
                System.err.println(e.getMessage());

                ConsoleMsg(e.getMessage());
            } finally {
                doc.close();
            }

            ConsoleMsg("PDF... GENERATED");

            return null;
            //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }.execute();

    // TODO add your handling code here:
}

From source file:co.ordinate.printer.NewJFrame.java

private void printA6Sheet() {
    new SwingWorker<Object, Object>() {
        String filename;//from  w ww.ja v a2  s  . c  om

        @Override
        protected void done() {

            ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. ");
            System.err.println("Printing Done");
        }

        @Override
        protected Object doInBackground() throws Exception {

            Document doc = new Document();
            try {
                PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("A6.pdf"));
                doc.open();
                doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : ");
                doc.addSubject("Confidential Report Eyes Only");
                doc.addKeywords("");
                doc.addAuthor("SOS");
                doc.addCreator("SOS");

                // A4 = 210mm x 297mm ~ 605points x 855points
                doc.setPageSize(PageSize.A5);
                doc.setMargins(10f, 10f, 10f, 10f);

                /////////////////////////////////////////////////////////////
                int pageno = 1;

                for (int i = 0; i == pageno; i++) {

                    //    doc.add(imageRight);
                }

                PdfContentByte cb = writer.getDirectContent();

                int i = 1;
                while (i <= pageno) {
                    doc.newPage();

                    i++;
                }
                BaseFont labelFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", true);
                float width = doc.getPageSize().getWidth();
                float height = doc.getPageSize().getHeight();
                for (float h = 0; h <= height; h++) {
                    for (float w = 0; w <= width; w++) {
                        cb.beginText();
                        // cb.setColorFill(TITLE_COLOR);
                        cb.setFontAndSize(labelFont, 4);
                        cb.setTextMatrix(w, h);

                        cb.showText(String.valueOf(h) + ":" + String.valueOf(w));
                        cb.endText();
                        w += 30;
                    }
                    h += 8;
                }
                cb.beginText();
                // cb.setColorFill(TITLE_COLOR);
                cb.setFontAndSize(labelFont, 4);
                cb.setTextMatrix(20f, 220f);
                cb.showText("abcd");
                cb.endText();

            } catch (Exception e) {
                System.err.println(e.getMessage());

                ConsoleMsg(e.getMessage());
            } finally {
                doc.close();
            }

            ConsoleMsg("PDF... GENERATED");
            System.err.println("Printing Done");
            return null;
            //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }.execute(); // TODO add your handling code here:

}

From source file:co.unicauca.proyectobase.entidades.MetodosPDF.java

public void createPdf(String filename) throws IOException, DocumentException {
    // step 1: Crear el objeto
    Document document = new Document();
    // step 2: instanciar para escritura con el objeto creado 
    PdfWriter.getInstance(document, new FileOutputStream(filename));
    // step 3: agregar los metadatos
    document.addTitle("Hello World example");
    document.addAuthor("Bruno Lowagie");
    document.addSubject("This example shows how to add metadata");
    document.addKeywords("Metadata, iText, PDF");
    document.addCreator("My program using iText");
    document.open();//from  w  ww .j  av a  2s .c  om
    // step 4: agregar el conteido, en este caso "Parrafo 1"
    document.add(new Paragraph("Parrafo 1"));
    // step 5: cerrar el archivo que se creo
    document.close();
}

From source file:com.ainfosec.macresponse.report.PdfGenerator.java

License:Open Source License

private static void addMetaData(String caseName, String authorName, Document document) {
    document.addTitle(caseName);//  w  w  w .j a  v a  2 s . c  o  m
    document.addSubject("MacResponse Console");
    document.addKeywords("");
    document.addAuthor(authorName);
    document.addCreator(System.getProperty("user.name"));
}

From source file:com.algoboss.erp.util.report.PDFExporter.java

License:Apache License

public void export(FacesContext context, DataTable table, String filename, String encodingType)
        throws IOException {
    try {//from w ww  . j  av a 2  s.  c o  m
        Document document = new Document(PageSize.A4, 25f, 25f, 25f, 25f);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);

        if (!document.isOpen()) {
            document.open();
        }
        document.addAuthor("Algo Boss");
        document.addCreator("Real's HowTo");
        document.addSubject("Thanks for your support");
        document.addCreationDate();
        document.addTitle(filename);
        //document.setMargins(1f, 1f, 1f, 1f);
        //document.setPageSize(PageSize.A4);
        document.add(exportPDFTable(context, table, false, false, false, encodingType));
        //document.setMargins(1f, 1f, 1f, 1f);
        //document.setPageSize(PageSize.A4);

        document.close();

        //writePDFToResponse(context.getExternalContext(), baos, filename);
        writePDFToResponseNew(context.getExternalContext(), baos, filename);

    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
}