Example usage for com.itextpdf.text BaseColor BaseColor

List of usage examples for com.itextpdf.text BaseColor BaseColor

Introduction

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

Prototype

public BaseColor(final float red, final float green, final float blue) 

Source Link

Document

Construct a BaseColor with float values.

Usage

From source file:client.welcome2.java

private void genRepButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genRepButtonActionPerformed
    Document doc = new Document();
    PdfWriter docWriter = null;//from w w  w  .  j  ava2  s  .co  m
    int repID = ThreadLocalRandom.current().nextInt(10000, 99999 + 1);
    DecimalFormat df = new DecimalFormat("0.00");
    //Date d = Calendar.getInstance().getTime();
    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    Date date = new Date();

    try {

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

        //file path
        String dt = dateFormat.format(date);
        sFileName = "Report No- " + repID + " Project Report- " + dt + " Status " + report_status + " .pdf";
        String path = "src/ProjectReports/" + sFileName;
        docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path));

        DateFormat dateFormat3 = new SimpleDateFormat("dd/MM/yyyy HH:mm");
        String d = dateFormat3.format(Calendar.getInstance().getTime());

        //document header attributes
        doc.addCreationDate();
        doc.setPageSize(PageSize.LETTER);

        //open document
        doc.open();

        //create a paragraph
        DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy");
        String sd2 = dateFormat2.format(pBeginDateChooser.getDate());
        String ed2 = dateFormat2.format(pEndDateChooser.getDate());
        Image image = Image.getInstance("src/Images/logo for pdf.png");
        Font font1 = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD);
        Paragraph paragraph = new Paragraph();
        Paragraph paragraph2 = new Paragraph("This report was generated by " + loginGUI.username + " at " + d
                + "\nYou can see all projects from " + sd2 + " to " + ed2);
        image.setAlignment(Image.RIGHT);
        doc.add(image);

        //specify column widths
        float[] columnWidths = { 2f, 2f, 2f, 2f, 2f };
        //create PDF table with the given widths
        PdfPTable table = new PdfPTable(columnWidths);
        // set table width a percentage of the page width
        table.setWidthPercentage(100f);

        //insert column headings
        insertCell(table, "Project ID", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Project Name", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Start Date", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Due Date", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Status", Element.ALIGN_CENTER, 1, bfBold12);
        table.setHeaderRows(1);

        //insert an empty row
        /* insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);*/
        //create section heading by cell merging
        /* insertCell(table, "New York Orders ...", Element.ALIGN_LEFT, 4, bfBold12);*/
        /*double orderTotal, total = 0;*/

        String add1, add2, add3, add4, add5;
        DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
        String sd = dateFormat1.format(pBeginDateChooser.getDate());
        String ed = dateFormat1.format(pEndDateChooser.getDate());

        if (report_status.equals("All")) {
            try {

                String sql = "select project_id,project_name,start_date,due_date,status from projects where due_date >= '"
                        + sd + "' and due_date <= '" + ed + "' and start_date >= '" + sd
                        + "'and start_date <= '" + ed + "'";
                pst = conn.prepareStatement(sql);
                rs = pst.executeQuery();
                while (rs.next()) {
                    add1 = rs.getString("project_id");
                    add2 = rs.getString("project_name");
                    add3 = dateFormat.format(rs.getDate("start_date"));
                    add4 = dateFormat.format(rs.getDate("due_date"));
                    add5 = rs.getString("status");
                    insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12);

                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }
        } else {
            try {

                String sql = "select project_id,project_name,start_date,due_date,status from projects where status = '"
                        + report_status + "' and due_date >= '" + sd + "' and due_date <= '" + ed
                        + "' and start_date >= '" + sd + "'and start_date <= '" + ed + "'";
                pst = conn.prepareStatement(sql);
                rs = pst.executeQuery();
                while (rs.next()) {
                    add1 = rs.getString("project_id");
                    add2 = rs.getString("project_name");
                    add3 = dateFormat.format(rs.getDate("start_date"));
                    add4 = dateFormat.format(rs.getDate("due_date"));
                    add5 = rs.getString("status");
                    insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12);

                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }
        }

        //add the PDF table to the paragraph
        paragraph2.add(table);

        // add the paragraph to the document
        doc.add(new Paragraph("\nProject Status Report " + dt + "\n", font1));
        doc.add(paragraph2);
    } catch (DocumentException dex) {
        dex.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (doc != null) {
            //close the document
            doc.close();
            JOptionPane.showMessageDialog(null, "Report No " + repID + " Generated!");
        }
        if (docWriter != null) {
            //close the writer
            docWriter.close();
        }
    }
    saveToDB(report_status, date, repID);
}

From source file:client.welcome3.java

private void genRepButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genRepButtonActionPerformed
    Document doc = new Document();
    PdfWriter docWriter = null;/*from   ww  w.  j  a  va2  s .co m*/
    int repID = ThreadLocalRandom.current().nextInt(10000, 99999 + 1);
    DecimalFormat df = new DecimalFormat("0.00");
    //Date d = Calendar.getInstance().getTime();
    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    Date date = new Date();

    try {

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

        //file path
        String dt = dateFormat.format(date);
        sFileName = "Report No- " + repID + " Project Report- " + dt + " Status " + report_status + " .pdf";
        String path = "src/ProjectReports/" + sFileName;
        docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path));

        DateFormat dateFormat3 = new SimpleDateFormat("dd/MM/yyyy HH:mm");
        String d = dateFormat3.format(Calendar.getInstance().getTime());

        //document header attributes
        doc.addCreationDate();
        doc.setPageSize(PageSize.LETTER);

        //open document
        doc.open();

        //create a paragraph
        DateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy");
        String sd2 = dateFormat2.format(pBeginDateChooser.getDate());
        String ed2 = dateFormat2.format(pEndDateChooser.getDate());
        Image image = Image.getInstance("src/Images/logo for pdf.png");
        Font font1 = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD);
        Paragraph paragraph = new Paragraph();
        Paragraph paragraph2 = new Paragraph("This report was generated by " + loginGUI.username + " at " + d
                + "\nYou can see all projects from " + sd2 + " to " + ed2);
        image.setAlignment(Image.RIGHT);
        doc.add(image);

        //specify column widths
        float[] columnWidths = { 2f, 2f, 2f, 2f, 2f };
        //create PDF table with the given widths
        PdfPTable table = new PdfPTable(columnWidths);
        // set table width a percentage of the page width
        table.setWidthPercentage(100f);

        //insert column headings
        insertCell(table, "Project ID", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Project Name", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Start Date", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Due Date", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Status", Element.ALIGN_CENTER, 1, bfBold12);
        table.setHeaderRows(1);

        //insert an empty row
        /* insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);*/
        //create section heading by cell merging
        /* insertCell(table, "New York Orders ...", Element.ALIGN_LEFT, 4, bfBold12);*/
        /*double orderTotal, total = 0;*/

        String add1, add2, add3, add4, add5;
        DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
        String sd = dateFormat1.format(pBeginDateChooser.getDate());
        String ed = dateFormat1.format(pEndDateChooser.getDate());

        if (report_status.equals("All")) {
            try {

                String sql = "select project_id,project_name,start_date,due_date,status from projects where due_date >= '"
                        + sd + "' and due_date <= '" + ed + "' and start_date >= '" + sd
                        + "'and start_date <= '" + ed + "'";
                pst = conn.prepareStatement(sql);
                rs = pst.executeQuery();
                while (rs.next()) {
                    add1 = rs.getString("project_id");
                    add2 = rs.getString("project_name");
                    add3 = dateFormat.format(rs.getDate("start_date"));
                    add4 = dateFormat.format(rs.getDate("due_date"));
                    add5 = rs.getString("status");
                    insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12);

                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }
        } else {
            try {

                String sql = "select project_id,project_name,start_date,due_date,status from projects where status = '"
                        + report_status + "' and due_date >= '" + sd + "' and due_date <= '" + ed
                        + "' and start_date >= '" + sd + "'and start_date <= '" + ed + "'";
                pst = conn.prepareStatement(sql);
                rs = pst.executeQuery();
                while (rs.next()) {
                    add1 = rs.getString("project_id");
                    add2 = rs.getString("project_name");
                    add3 = dateFormat.format(rs.getDate("start_date"));
                    add4 = dateFormat.format(rs.getDate("due_date"));
                    add5 = rs.getString("status");
                    insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12);

                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }
        }

        //add the PDF table to the paragraph 
        paragraph2.add(table);

        // add the paragraph to the document
        doc.add(new Paragraph("\nProject Status Report " + dt + "\n", font1));
        doc.add(paragraph2);
    } catch (DocumentException dex) {
        dex.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (doc != null) {
            //close the document
            doc.close();
            JOptionPane.showMessageDialog(null, "Report No " + repID + " Generated!");
        }
        if (docWriter != null) {
            //close the writer
            docWriter.close();
        }
    }
    saveToDB(report_status, date, repID);
}

From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java

License:Apache License

/**
 * //  www.j  ava2  s  . c  o m
 * PDF Title Page 
 *
 * @param doc
 * @param writer
 */
public static void setTitleMainPage(Document doc, PdfWriter writer, PDFCommonEventHelper event, Upload upload)
        throws Exception {

    Font fnTitle = new Font(bfKorean, 20, Font.BOLD);
    Font fnLabel = new Font(bfKorean, 11, Font.BOLD);
    Font fnText = new Font(bfKorean, 11);
    LineSeparator UNDERLINE = new LineSeparator(1, 80, null, com.itextpdf.text.Element.ALIGN_CENTER, -5);
    doc.newPage();
    doc.add(Chunk.NEWLINE);

    event.setTitleFlag(true);

    int toc = writer.getPageNumber();
    Image img = Image.getInstance(PDFDocGenerator.class.getResource("/image/title.gif"));
    img.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
    img.scalePercent(80, 80);
    doc.add(img);

    Paragraph titlePh = new Paragraph(MessageUtil.getMessage("pdf.message.main.title"), fnTitle);
    titlePh.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
    titlePh.setSpacingBefore(50);
    titlePh.setSpacingAfter(30);
    doc.add(titlePh);

    doc.add(UNDERLINE);

    PdfPTable t1 = new PdfPTable(2);
    t1.setSpacingBefore(20);
    t1.setWidths(new int[] { 110, 290 });
    t1.getDefaultCell().setBorder(0);
    t1.getDefaultCell().setFixedHeight(32);

    t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_name"), fnLabel));
    t1.addCell(new Phrase(upload.getProjectNm(), fnText));
    t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.department"), fnLabel));
    t1.addCell(new Phrase(upload.getDepartment(), fnText));
    t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.focus_name"), fnLabel));
    t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.focus_name"), fnText));
    t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.product"), fnLabel));
    t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.product", upload.getBeforeWas(),
            upload.getAfterWas()), fnText));
    doc.add(t1);

    doc.add(UNDERLINE);

    Paragraph executedPh = new Paragraph(MessageUtil.getMessage("pdf.message.main.label.executed"), fnLabel);
    executedPh.setSpacingBefore(30);
    executedPh.setSpacingAfter(15);
    executedPh.setIndentationLeft(50);
    doc.add(executedPh);

    PdfPTable t2 = new PdfPTable(2);
    t2.getDefaultCell().setFixedHeight(28);
    t2.getDefaultCell().setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);

    t2.getDefaultCell().setBackgroundColor(new BaseColor(217, 217, 217));
    t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.owner"), fnLabel));
    t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_role"), fnLabel));
    t2.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255));
    t2.addCell(new Phrase(upload.getPerson(), fnText));
    t2.addCell(new Phrase(upload.getOrgRole(), fnText));
    doc.add(t2);

    doc.newPage();
    int total = writer.reorderPages(null);

    int[] order = new int[total];
    for (int i = 0; i < total; i++) {
        order[i] = i + toc;
        if (order[i] > total)
            order[i] -= total;
    }
    // apply the new order
    writer.reorderPages(order);

}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * Default  ?(RED)/*from  w w w. j a v  a 2  s  .com*/
 *
 * @param text  text
 * @param style Font style
 * @return Paragraph
 */
public static Paragraph getDefaultRed(String text, int style) {
    Font font = new Font(bfKorean, 10, style);
    font.setColor(new BaseColor(255, 0, 0));

    Paragraph ph = new Paragraph(text, font);
    ph.setMultipliedLeading(1.8F);
    ph.setIndentationLeft(45);
    ph.setSpacingAfter(14);
    return ph;
}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * /*from   w  w  w.ja v  a  2s. c o m*/
 *  box 
 *
 * @param section box  section ?
 * @param e box   element
 * @throws Exception
 */
public static void setBox(Section section, Element e) throws Exception {

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(1);
    t.setSpacingAfter(12);

    if (e.getAttributeValue("width") != null)
        t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width")));

    PdfPCell cell = new PdfPCell();
    if (e.getAttributeValue("option") != null) {

        ColumnText col = new ColumnText(null);
        for (Element e1 : e.getChildren()) {
            if (e1.getAttributeValue("type").equals("red"))
                col.addText(new Phrase(e1.getText(), fnBoxRed));
            else
                col.addText(new Phrase(e1.getText(), fnBox));
        }
        cell.setColumn(col);

    } else {
        cell.setPhrase(new Phrase(e.getText(), fnBox));
    }

    cell.setPaddingLeft(10);
    cell.setLeading(0.0F, 1.8F);
    cell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(new BaseColor(238, 236, 225));

    t.addCell(cell);

    section.add(t);

}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * //  ww w. ja va  2  s .  com
 * box (Backgroud : Black)
 *
 * @param section box  section ?
 * @param e box   element
 * @throws Exception
 */
public static void setBoxB(Section section, Element e) throws Exception {

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(1);
    t.setSpacingAfter(12);

    if (e.getAttributeValue("width") != null)
        t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width")));

    PdfPCell cell = new PdfPCell();
    if (e.getAttributeValue("option") != null) {

        ColumnText col = new ColumnText(null);
        for (Element e1 : e.getChildren()) {
            if (e1.getAttributeValue("type").equals("red"))
                col.addText(new Phrase(e1.getText(), fnBoxRed));
            else
                col.addText(new Phrase(e1.getText(), fnBoxWhite));
        }
        cell.setColumn(col);

    } else {
        cell.setPhrase(new Phrase(e.getText(), fnBoxWhite));
    }

    cell.setPaddingLeft(10);
    cell.setLeading(0.0F, 1.8F);
    cell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(new BaseColor(0, 0, 0));

    t.addCell(cell);

    section.add(t);

}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * /*from  w w w.j  a v  a  2  s. c  o m*/
 * box (Backgroud : White)
 *
 * @param section box  section ?
 * @param e box   element
 * @throws Exception
 */
public static void setBoxW(Section section, Element e) throws Exception {

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(1);
    t.setSpacingAfter(12);

    if (e.getAttributeValue("width") != null)
        t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width")));

    PdfPCell cell = new PdfPCell();
    if (e.getAttributeValue("option") != null) {

        ColumnText col = new ColumnText(null);
        for (Element e1 : e.getChildren()) {
            if (e1.getAttributeValue("type").equals("red"))
                col.addText(new Phrase(e1.getText(), fnBoxRed));
            else
                col.addText(new Phrase(e1.getText(), fnBoxBlack));
        }
        cell.setColumn(col);

    } else {
        cell.setPhrase(new Phrase(e.getText(), fnBoxBlack));
    }

    cell.setPaddingLeft(10);
    cell.setLeading(0.0F, 1.8F);
    cell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(new BaseColor(255, 255, 255));

    t.addCell(cell);

    section.add(t);

}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * /*from   ww  w.j a va 2 s  .  com*/
 * ?? header 
 *
 * @param e table   element
 * @param t header  table ?
 * @param colCount column 
 * @throws Exception
 */
public static void setTableHeader(Element e, PdfPTable t, int colCount) throws Exception {

    t.getDefaultCell().setBackgroundColor(new BaseColor(217, 217, 217));
    t.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);

    ArrayList<Integer> colWidth = new ArrayList<Integer>();
    for (Element e1 : e.getChild("header").getChildren()) {
        t.addCell(new Phrase(e1.getText(), fnNormalBold));

        if (e1.getAttributeValue("width") != null)
            colWidth.add(Integer.parseInt(e1.getAttributeValue("width")));
    }

    if (colCount == colWidth.size()) {
        int[] col = new int[colCount];
        for (int i = 0; i < colCount; i++)
            col[i] = colWidth.get(i);

        t.setWidths(col);
    }

}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * // ww w . j  a  va2s  .  c o m
 * ?? row 
 *
 * @param e table   element
 * @param t header  table ?
 * @throws Exception
 */
public static void setTableRow(Element e, PdfPTable t) throws Exception {

    t.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255));
    t.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_LEFT);

    for (Element e1 : e.getChild("row").getChildren()) {
        t.addCell(new Phrase(e1.getText(), fnNormal));
    }

}

From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java

License:Open Source License

private static PdfPCell createTableHeader(String header, int alignment) {
    PdfPCell cell = new PdfPCell(new Paragraph(header,
            FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.BOLD, BaseColor.BLACK)));
    cell.setBorderColor(new BaseColor(224, 224, 224));
    cell.setBorderWidth(1);//from  www.  j  av  a  2 s .  c  om
    cell.setPadding(5);
    cell.setHorizontalAlignment(alignment);
    return cell;
}