Java 类com.lowagie.text.pdf.GrayColor 实例源码

项目:itext2    文件:PatternTest.java   
/**
 * Painting Patterns.
 * 
 * @param args
 *            no arguments needed
 */
@Test
public void main() throws Exception {


    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    // step 2:
    // we create a writer that listens to the document
    // and directs a PDF-stream to a file
    PdfWriter writer = PdfWriter.getInstance(document,
            PdfTestBase.getOutputStream("pattern.pdf"));

    // step 3: we open the document
    document.open();

    // step 4: we add some content
    PdfContentByte cb = writer.getDirectContent();
    PdfTemplate tp = cb.createTemplate(400, 300);
    PdfPatternPainter pat = cb.createPattern(15, 15, null);
    pat.rectangle(5, 5, 5, 5);
    pat.fill();
    pat.sanityCheck();

    PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV",
            new CMYKColor(0.9f, .2f, .3f, .1f));
    SpotColor spot = new SpotColor(spc_cmyk, 0.25f);
    tp.setPatternFill(pat, spot, .9f);
    tp.rectangle(0, 0, 400, 300);
    tp.fill();
    tp.sanityCheck();

    cb.addTemplate(tp, 50, 50);
    PdfPatternPainter pat2 = cb.createPattern(10, 10, null);
    pat2.setLineWidth(2);
    pat2.moveTo(-5, 0);
    pat2.lineTo(10, 15);
    pat2.stroke();
    pat2.moveTo(0, -5);
    pat2.lineTo(15, 10);
    pat2.stroke();
    cb.setLineWidth(1);
    cb.setColorStroke(Color.black);
    cb.setPatternFill(pat2, Color.red);
    cb.rectangle(100, 400, 30, 210);
    cb.fillStroke();
    cb.setPatternFill(pat2, Color.green);
    cb.rectangle(150, 400, 30, 100);
    cb.fillStroke();
    cb.setPatternFill(pat2, Color.blue);
    cb.rectangle(200, 400, 30, 130);
    cb.fillStroke();
    cb.setPatternFill(pat2, new GrayColor(0.5f));
    cb.rectangle(250, 400, 30, 80);
    cb.fillStroke();
    cb.setPatternFill(pat2, new GrayColor(0.7f));
    cb.rectangle(300, 400, 30, 170);
    cb.fillStroke();
    cb.setPatternFill(pat2, new GrayColor(0.9f));
    cb.rectangle(350, 400, 30, 40);
    cb.fillStroke();

    cb.sanityCheck();

    // step 5: we close the document
    document.close();
}
项目:itext2    文件:FormTextFieldTest.java   
/**
 * Generates an Acroform with a TextField
 */
@Test
public void main() throws Exception {

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4);

    // step 2:
    PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("textfield.pdf"));

    // step 3: we open the document
    document.open();

    // step 4:
    BaseFont helv = BaseFont.createFont("Helvetica", "winansi", false);
    PdfContentByte cb = writer.getDirectContent();
    cb.moveTo(0, 0);
    String text = "Some start text";
    float fontSize = 12;
    Color textColor = new GrayColor(0f);
    PdfFormField field = PdfFormField.createTextField(writer, false, false, 0);
    field.setWidget(new Rectangle(171, 750, 342, 769), PdfAnnotation.HIGHLIGHT_INVERT);
    field.setFlags(PdfAnnotation.FLAGS_PRINT);
    field.setFieldName("ATextField");
    field.setValueAsString(text);
    field.setDefaultValueAsString(text);
    field.setBorderStyle(new PdfBorderDictionary(2, PdfBorderDictionary.STYLE_SOLID));
    field.setPage();
    PdfAppearance tp = cb.createAppearance(171, 19);
    PdfAppearance da = (PdfAppearance) tp.getDuplicate();
    da.setFontAndSize(helv, fontSize);
    da.setColorFill(textColor);
    field.setDefaultAppearanceString(da);
    tp.beginVariableText();
    tp.saveState();
    tp.rectangle(2, 2, 167, 15);
    tp.clip();
    tp.newPath();
    tp.beginText();
    tp.setFontAndSize(helv, fontSize);
    tp.setColorFill(textColor);
    tp.setTextMatrix(4, 5);
    tp.showText(text);
    tp.endText();
    tp.restoreState();
    tp.endVariableText();
    field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
    writer.addAnnotation(field);

    // step 5: we close the document
    document.close();
}
项目:PDFTestForAndroid    文件:Pattern.java   
/**
 * Painting Patterns.
 * 
 * @param args
 *            no arguments needed
 */
public static void main(String[] args) {

    System.out.println("Stencil");

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {

        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "pattern.pdf"));

        // step 3: we open the document
        document.open();

        // step 4: we add some content
        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(400, 300);
        PdfPatternPainter pat = cb.createPattern(15, 15, null);
        pat.rectangle(5, 5, 5, 5);
        pat.fill();
        pat.sanityCheck();

        PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV", 0.25f, new CMYKColor(0.9f, .2f, .3f, .1f));
        SpotColor spot = new SpotColor(spc_cmyk);
        tp.setPatternFill(pat, spot, .9f);
        tp.rectangle(0, 0, 400, 300);
        tp.fill();
        tp.sanityCheck();

        cb.addTemplate(tp, 50, 50);
        PdfPatternPainter pat2 = cb.createPattern(10, 10, null);
        pat2.setLineWidth(2);
        pat2.moveTo(-5, 0);
        pat2.lineTo(10, 15);
        pat2.stroke();
        pat2.moveTo(0, -5);
        pat2.lineTo(15, 10);
        pat2.stroke();
        cb.setLineWidth(1);
        cb.setColorStroke(Color.black);
        cb.setPatternFill(pat2, Color.red);
        cb.rectangle(100, 400, 30, 210);
        cb.fillStroke();
        cb.setPatternFill(pat2, Color.green);
        cb.rectangle(150, 400, 30, 100);
        cb.fillStroke();
        cb.setPatternFill(pat2, Color.blue);
        cb.rectangle(200, 400, 30, 130);
        cb.fillStroke();
        cb.setPatternFill(pat2, new GrayColor(0.5f));
        cb.rectangle(250, 400, 30, 80);
        cb.fillStroke();
        cb.setPatternFill(pat2, new GrayColor(0.7f));
        cb.rectangle(300, 400, 30, 170);
        cb.fillStroke();
        cb.setPatternFill(pat2, new GrayColor(0.9f));
        cb.rectangle(350, 400, 30, 40);
        cb.fillStroke();

        cb.sanityCheck();
    } catch (Exception de) {
        de.printStackTrace();
    }
    // step 5: we close the document
    document.close();
}
项目:itext2    文件:Rectangle.java   
/**
 * Gets the grayscale.
 * 
 * @return the grayscale color of the background
    * or 0 if the background has no grayscale color.
 */
public float getGrayFill() {
       if (backgroundColor instanceof GrayColor)
           return ((GrayColor)backgroundColor).getGray();
       return 0;
}
项目:PDFTestForAndroid    文件:FormTextField.java   
/**
 * Generates an Acroform with a TextField
 * 
 * @param args
 *            no arguments needed here
 */
public static void main(String[] args) {

    System.out.println("Textfield");

    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4);

    try {

        // step 2:
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "textfield.pdf"));

        // step 3: we open the document
        document.open();

        // step 4:
        BaseFont helv = BaseFont.createFont("Helvetica", "winansi", false);
        PdfContentByte cb = writer.getDirectContent();
        cb.moveTo(0, 0);
        String text = "Some start text";
        float fontSize = 12;
        Color textColor = new GrayColor(0f);
        PdfFormField field = PdfFormField.createTextField(writer, false, false, 0);
        field.setWidget(new Rectangle(171, 750, 342, 769), PdfAnnotation.HIGHLIGHT_INVERT);
        field.setFlags(PdfAnnotation.FLAGS_PRINT);
        field.setFieldName("ATextField");
        field.setValueAsString(text);
        field.setDefaultValueAsString(text);
        field.setBorderStyle(new PdfBorderDictionary(2, PdfBorderDictionary.STYLE_SOLID));
        field.setPage();
        PdfAppearance tp = cb.createAppearance(171, 19);
        PdfAppearance da = (PdfAppearance) tp.getDuplicate();
        da.setFontAndSize(helv, fontSize);
        da.setColorFill(textColor);
        field.setDefaultAppearanceString(da);
        tp.beginVariableText();
        tp.saveState();
        tp.rectangle(2, 2, 167, 15);
        tp.clip();
        tp.newPath();
        tp.beginText();
        tp.setFontAndSize(helv, fontSize);
        tp.setColorFill(textColor);
        tp.setTextMatrix(4, 5);
        tp.showText(text);
        tp.endText();
        tp.restoreState();
        tp.endVariableText();
        field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
        writer.addAnnotation(field);

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();
}
项目:itext2    文件:Rectangle.java   
/**
 * Sets the the background color to a grayscale value.
 * 
 * @param value the new grayscale value
 */
public void setGrayFill(float value) {
       backgroundColor = new GrayColor(value);
}
项目:DroidText    文件:Rectangle.java   
/**
 * Gets the grayscale.
 * 
 * @return the grayscale color of the background
    * or 0 if the background has no grayscale color.
 */
public float getGrayFill() {
       if (backgroundColor instanceof GrayColor)
           return ((GrayColor)backgroundColor).getGray();
       return 0;
}
项目:DroidText    文件:Rectangle.java   
/**
 * Sets the the background color to a grayscale value.
 * 
 * @param value the new grayscale value
 */
public void setGrayFill(float value) {
       backgroundColor = new GrayColor(value);
}