Example usage for java.awt Color Color

List of usage examples for java.awt Color Color

Introduction

In this page you can find the example usage for java.awt Color Color.

Prototype

public Color(ColorSpace cspace, float[] components, float alpha) 

Source Link

Document

Creates a color in the specified ColorSpace with the color components specified in the float array and the specified alpha.

Usage

From source file:RenderingTEXT_RENDER_MODE_STROKE.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from  ww  w  . j  a  va 2s  . com
        PdfWriter.getInstance(document, new FileOutputStream("RenderingTEXT_RENDER_MODE_STROKE.pdf"));

        document.open();

        Paragraph p = new Paragraph("Text Rendering:");
        document.add(p);
        Chunk chunk = new Chunk("rendering test");
        chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_STROKE, 0.3f, new Color(0x00, 0x00, 0xFF));
        document.add(chunk);

    } catch (Exception ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:RenderingTEXT_RENDER_MODE_FILL_STROKE.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from  w w  w  .j a  v  a 2 s .c  o m*/
        PdfWriter.getInstance(document, new FileOutputStream("RenderingTEXT_RENDER_MODE_FILL_STROKE.pdf"));

        document.open();

        Paragraph p = new Paragraph("Text Rendering:");
        document.add(p);
        Chunk chunk = new Chunk("rendering test");
        chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 100f, new Color(0xFF, 0x00, 0x00));
        document.add(chunk);

    } catch (Exception ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:RenderingTEXT_RENDER_MODE_FILL_STROKE5.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from w w  w  . j a v a 2  s  .  c  o  m
        PdfWriter.getInstance(document, new FileOutputStream("RenderingTEXT_RENDER_MODE_FILL_STROKE5.pdf"));

        document.open();

        Paragraph p = new Paragraph("Text Rendering:");
        document.add(p);
        Chunk chunk = new Chunk("rendering test");
        chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 0.5f, new Color(0x00, 0x00, 0x00));
        document.add(chunk);

    } catch (Exception ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:ChapterSectionPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {/*w ww  .  j a va2s  .c o m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ChapterSectionPDF.pdf"));
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        document.open();
        Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 24, Font.NORMAL, new Color(255, 0, 0));
        Font sectionFont = FontFactory.getFont(FontFactory.HELVETICA, 20, Font.NORMAL, new Color(0, 0, 255));
        Font subsectionFont = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, new Color(0, 64, 64));

        Paragraph paragraph1 = new Paragraph("text 1");
        Paragraph paragraph2 = new Paragraph("text 2");

        Paragraph cTitle = new Paragraph("This is a chapter ", chapterFont);
        Chapter chapter = new Chapter(cTitle, 1);

        paragraph2.setAlignment(Element.ALIGN_JUSTIFIED);
        paragraph1.setAlignment(Element.ALIGN_JUSTIFIED);
        chapter.add(paragraph1);

        Paragraph sTitle = new Paragraph("This is section 1 in chapter 1", sectionFont);
        Section section = chapter.addSection(sTitle, 1);
        section.add(paragraph1);

        Paragraph subTitle = new Paragraph("This is subsection 1 of section 1", subsectionFont);
        Section subsection = section.addSection(subTitle, 3);

        document.add(chapter);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();//from  w  w w  .  j  a v a2  s .  co m
    PdfContentByte cb = writer.getDirectContent();
    cb.setColorFill(new GrayColor(0));
    cb.rectangle(36, 770, 36, 36);
    cb.fillStroke();

    cb.setGrayFill(1);
    cb.rectangle(470, 716, 36, 36);
    cb.fillStroke();

    cb.setColorFill(new Color(1f, 1f, 1f));
    cb.rectangle(416, 662, 36, 36);
    cb.fillStroke();

    cb.setRGBColorFillF(1f, 1f, 1f);
    cb.rectangle(416, 608, 36, 36);
    cb.fillStroke();

    cb.setColorFill(new CMYKColor(0f, 0f, 0f, 1f));
    cb.rectangle(416, 554, 36, 36);
    cb.fillStroke();

    cb.setCMYKColorFillF(0f, 0f, 0f, 1f);
    cb.rectangle(416, 500, 36, 36);
    cb.fillStroke();
    document.close();
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    StyledDocument doc = new DefaultStyledDocument();
    JTextPane textPane = new JTextPane(doc);
    textPane.setText("this is a test.");

    Random random = new Random();
    for (int i = 0; i < textPane.getDocument().getLength(); i++) {
        SimpleAttributeSet set = new SimpleAttributeSet();
        StyleConstants.setForeground(set,
                new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
        StyleConstants.setFontSize(set, random.nextInt(12) + 12);
        StyleConstants.setBold(set, random.nextBoolean());
        StyleConstants.setItalic(set, random.nextBoolean());
        StyleConstants.setUnderline(set, random.nextBoolean());

        doc.setCharacterAttributes(i, 1, set, true);
    }//from   w  w  w.jav a2s  . co m

    frame.add(new JScrollPane(textPane));
    frame.setSize(500, 400);
    frame.setVisible(true);
}

From source file:TableCellAlignmentPDF.java

public static void main(String[] args) {
    Document.compress = false;/*from ww  w  .jav a2 s  . com*/
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream("TableCellAlignmentPDF.pdf"));

        document.open();

        Image img = Image.getInstance("logo.png");
        img.scalePercent(10);

        PdfPTable table = new PdfPTable(3);
        PdfPCell cell = new PdfPCell();
        cell.addElement(new Chunk("cell "));
        cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);

        table.addCell("a cell");
        table.addCell(cell);
        table.addCell("a cell");

        document.add(table);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:TableCellWithBackgroundPDF.java

public static void main(String[] args) {
    Document.compress = false;/*w  w w  .jav a 2s. c  o  m*/
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream("TableCellWithBackgroundPDF.pdf"));

        document.open();

        Image img = Image.getInstance("logo.png");
        img.scalePercent(10);

        PdfPTable table = new PdfPTable(3);
        PdfPCell cell = new PdfPCell();
        cell.addElement(new Chunk("cell "));
        cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);

        table.addCell("a cell");
        table.addCell(cell);
        table.addCell("a cell");

        document.add(table);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:ChapterSectionAlignmentPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {//from ww  w.  j  a v  a2s. co m
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("ChapterSectionAlignmentPDF.pdf"));
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        document.open();
        Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 24, Font.NORMAL, new Color(255, 0, 0));
        Font sectionFont = FontFactory.getFont(FontFactory.HELVETICA, 20, Font.NORMAL, new Color(0, 0, 255));
        Font subsectionFont = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, new Color(0, 64, 64));

        Paragraph paragraph1 = new Paragraph("text 1");
        Paragraph paragraph2 = new Paragraph("text 2");

        Paragraph cTitle = new Paragraph("This is a chapter ", chapterFont);
        Chapter chapter = new Chapter(cTitle, 1);

        paragraph2.setAlignment(Element.ALIGN_CENTER);
        paragraph1.setAlignment(Element.ALIGN_RIGHT);
        chapter.add(paragraph1);

        Paragraph sTitle = new Paragraph("This is section 1 in chapter 1", sectionFont);
        Section section = chapter.addSection(sTitle, 1);
        section.add(paragraph1);

        Paragraph subTitle = new Paragraph("This is subsection 1 of section 1", subsectionFont);
        Section subsection = section.addSection(subTitle, 3);

        document.add(chapter);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:PdfContentByteColor.java

public static void main(String[] args) {
    Document document = new Document();
    try {// w  w w  . ja va 2  s .  c o  m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("PdfContentByteColor.pdf"));
        document.open();

        BaseFont bf = FontFactory.getFont(FontFactory.COURIER).getCalculatedBaseFont(false);

        PdfContentByte cb = writer.getDirectContent();
        cb.beginText();
        cb.setColorFill(new Color(0x00, 0xFF, 0x00));
        cb.setFontAndSize(bf, 12);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "Grass is green", 50, 70, 0);
        cb.endText();

    } catch (Exception ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}