1 3 import java.io.*; 4 import java.awt.*; 5 import java.awt.color.*; 6 import org.faceless.pdf2.*; 7 8 public class Colors 16 { 17 public static void main(String [] args) throws Exception  18 { 19 PDF pdf = new PDF(); 20 PDFPage page = pdf.newPage(PDF.PAGESIZE_A4); 21 22 PDFStyle text = new PDFStyle(); 23 text.setFont(new StandardFont(StandardFont.HELVETICA), 9); 24 text.setFillColor(Color.black); 25 26 PDFStyle color = new PDFStyle(); 30 color.setLineColor(Color.black); 31 color.setFillColor(Color.red); 32 page.setStyle(color); 33 page.drawRectangle(50,750,100,700); 34 page.setStyle(text); 35 page.drawText("Red in the default sRGB colorspace", 120, 720); 36 37 PDFStyle gradient = new PDFStyle(); 41 gradient.setLineColor(Color.black); 42 gradient.setFillColor(new GradientPaint(50,700,Color.red, 150,700,Color.blue)); 43 page.setStyle(gradient); 44 page.drawRectangle(50,650,100,600); 45 page.setStyle(text); 46 page.drawText("A red-blue gradient in the sRGB colorspace", 120, 620); 47 48 PDFStyle pattern = new PDFStyle(); 52 pattern.setLineColor(Color.black); 53 pattern.setFillColor(new PDFPattern("Star",0,0,50,50,Color.red, Color.blue)); 54 page.setStyle(pattern); 55 page.drawRectangle(50,550,100,500); 56 page.setStyle(text); 57 page.drawText("A pattern using the ColorPattern class", 120, 520); 58 59 PDFStyle cmyk = new PDFStyle(); 66 cmyk.setLineColor(Color.black); 67 Color cmykblue = CMYKColorSpace.getColor(1.0f, 0.72f, 0f, 0.06f); 68 cmyk.setFillColor(cmykblue); 69 page.setStyle(cmyk); 70 page.drawRectangle(50,450,100,400); 71 page.setStyle(text); 72 page.drawText("A color in the uncalibrated CMYK ColorSpace", 120, 420); 73 74 PDFStyle spot = new PDFStyle(); 79 spot.setLineColor(Color.black); 80 spot.setFillColor(new SpotColorSpace("PANTONE Reflex Blue CVC", cmykblue).getColor(1)); 81 page.setStyle(spot); 82 page.drawRectangle(50,350,100,300); 83 page.setStyle(text); 84 page.drawText("The PANTONE Reflex Blue spot color", 120, 320); 85 86 87 93 try { 97 ColorSpace grayspace = ColorSpace.getInstance(ColorSpace.CS_GRAY); 98 PDFStyle gray = new PDFStyle(); 99 gray.setLineColor(Color.black); 100 float[] comp = { 0.5f }; 101 gray.setFillColor(new Color(grayspace, comp, 1)); 102 page.setStyle(gray); 103 page.drawRectangle(50,250,100,200); 104 } catch (Throwable e) { 105 System.err.println("WARNING: Gray ColorSpace: Caught "+e); 106 } 107 page.setStyle(text); 108 page.drawText("A 50% gray color in the grayscale ColorSpace", 120, 220); 109 110 try { 113 ICC_Profile prof = ICC_Profile.getInstance("resources/NTSC.icm"); 114 ICC_ColorSpace ntsc = new ICC_ColorSpace(prof); 115 float[] comp = { 1.0f, 0.0f, 0.0f }; 116 117 PDFStyle icc = new PDFStyle(); 118 icc.setLineColor(Color.black); 119 icc.setFillColor(new Color(ntsc, comp, 1)); 120 page.setStyle(icc); 121 page.drawRectangle(50,150,100,100); 122 } catch (Throwable e) { 123 System.err.println("WARNING: ICC ColorSpace: Caught " + e); 124 } 125 page.setStyle(text); 126 page.drawText("A color in the NTSC ICC ColorSpace", 120, 120); 127 OutputStream fo = new FileOutputStream("Colors.pdf"); 128 pdf.render(fo); 129 fo.close(); 130 } 131 } 132
| Popular Tags
|