Example usage for com.lowagie.text.pdf TextField setTextColor

List of usage examples for com.lowagie.text.pdf TextField setTextColor

Introduction

In this page you can find the example usage for com.lowagie.text.pdf TextField setTextColor.

Prototype

public void setTextColor(Color textColor) 

Source Link

Document

Sets the text color.

Usage

From source file:classroom.filmfestival_c.Movies22.java

public static void main(String[] args) {
    // step 1/*from w  ww  .  j a v a 2s.co m*/
    Document document = new Document(new Rectangle(WIDTH, HEIGHT));
    try {
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FORM));
        writer.setViewerPreferences(PdfWriter.PageLayoutSinglePage);
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();

        // top part of the card
        cb.setColorFill(RED);
        cb.rectangle(0, mm2pt(57f), WIDTH, HEIGHT - mm2pt(57f));
        cb.fill();
        cb.setColorFill(BLACK);
        cb.rectangle(0, mm2pt(61), WIDTH, mm2pt(21f));
        cb.fill();
        cb.setColorFill(WHITE);

        Image kubrick = Image.getInstance(KUBRICK);
        kubrick.scaleToFit(WIDTH, mm2pt(21));
        kubrick.setAbsolutePosition(0, mm2pt(61));
        cb.addImage(kubrick);

        Image logo = Image.getInstance(LOGO);
        logo.scaleToFit(mm2pt(14), mm2pt(14));
        logo.setAbsolutePosition(mm2pt(37), mm2pt(65));
        cb.addImage(logo);

        cb.beginText();
        cb.setFontAndSize(FONT, 7);
        cb.showTextAligned(Element.ALIGN_CENTER, "Flanders International Film Festival-Ghent", WIDTH / 2,
                mm2pt(58.5f), 0);
        cb.endText();

        // bottom part of the card

        TextField filmfestival = new TextField(writer, new Rectangle(0, 0, WIDTH, mm2pt(9)), "filmfestival");
        filmfestival.setBackgroundColor(GRAY);
        filmfestival.setTextColor(WHITE);
        filmfestival.setText("www.filmfestival.be");
        filmfestival.setFontSize(14);
        filmfestival.setOptions(TextField.READ_ONLY);
        filmfestival.setAlignment(Element.ALIGN_CENTER);
        writer.addAnnotation(filmfestival.getTextField());

        cb.beginText();
        cb.moveText(mm2pt(1.5f), mm2pt(12));
        cb.setFontAndSize(FONT, 21);
        cb.setColorFill(RED);
        cb.showText("10");
        cb.setColorFill(BLUE);
        cb.showText("/");
        cb.setColorFill(RED);
        cb.showText("21");
        cb.setColorFill(BLUE);
        cb.showText("OCT");
        cb.setColorFill(GREEN);
        cb.showText("2006");
        cb.endText();
        cb.setColorStroke(BLUE);
        cb.moveTo(mm2pt(24.5f), mm2pt(29));
        cb.lineTo(mm2pt(24.5f), mm2pt(36));
        cb.moveTo(mm2pt(24.5f), mm2pt(48));
        cb.lineTo(mm2pt(24.5f), mm2pt(54));
        cb.stroke();

        // central part of the card
        PushbuttonField photo = new PushbuttonField(writer,
                new Rectangle(mm2pt(3), mm2pt(29), mm2pt(24), mm2pt(54)), "photo");
        PdfTemplate t1 = cb.createTemplate(mm2pt(21), mm2pt(25));
        t1.setColorFill(GRAY);
        t1.rectangle(0, 0, mm2pt(21), mm2pt(25));
        t1.fill();
        photo.setTemplate(t1);
        photo.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
        writer.addAnnotation(photo.getField());

        TextField type = new TextField(writer,
                new Rectangle(mm2pt(26), mm2pt(46), WIDTH - mm2pt(1.5f), mm2pt(54)), "type");
        type.setTextColor(GRAY);
        type.setText("TYPE");
        type.setFontSize(0);
        writer.addAnnotation(type.getTextField());

        TextField number = new TextField(writer,
                new Rectangle(mm2pt(26), mm2pt(44), WIDTH - mm2pt(1.5f), mm2pt(48)), "number");
        number.setText("N\u00b0 0000000");
        number.setFontSize(8);
        writer.addAnnotation(number.getTextField());

        TextField name = new TextField(writer,
                new Rectangle(mm2pt(26), mm2pt(28), WIDTH - mm2pt(1.5f), mm2pt(40)), "name");
        name.setText("Name");
        name.setFontSize(8);
        name.setOptions(TextField.MULTILINE);
        writer.addAnnotation(name.getTextField());

        PushbuttonField barcode = new PushbuttonField(writer,
                new Rectangle(mm2pt(3), mm2pt(23), WIDTH - mm2pt(3), mm2pt(28)), "barcode");
        PdfTemplate t2 = cb.createTemplate(WIDTH - mm2pt(6), mm2pt(5));
        t2.setColorFill(GRAY);
        t2.rectangle(0, 0, WIDTH - mm2pt(6), mm2pt(5));
        t2.fill();
        barcode.setTemplate(t2);
        barcode.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
        writer.addAnnotation(barcode.getField());

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // step 4
    document.close();
}

From source file:classroom.filmfestival_c.Movies25.java

public static void createTemplate() {
    // our template will be 35 x 50 mm
    Document document = new Document(
            new Rectangle(Utilities.millimetersToPoints(35), Utilities.millimetersToPoints(50)));
    try {/*from  w  w w.java  2s . co  m*/
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(TEMPLATE));
        writer.setViewerPreferences(PdfWriter.PageLayoutSinglePage);
        // step 3
        document.open();
        // step 4

        // space reserved for the film poster
        PushbuttonField foto = new PushbuttonField(writer,
                new Rectangle(Utilities.millimetersToPoints(0), Utilities.millimetersToPoints(25),
                        Utilities.millimetersToPoints(35), Utilities.millimetersToPoints(50)),
                POSTER);
        foto.setBackgroundColor(Color.BLUE);
        writer.addAnnotation(foto.getField());

        // space reserved for the text
        TextField tekst = new TextField(writer,
                new Rectangle(Utilities.millimetersToPoints(0), Utilities.millimetersToPoints(7),
                        Utilities.millimetersToPoints(35), Utilities.millimetersToPoints(25)),
                TEXT);
        tekst.setOptions(TextField.MULTILINE);
        writer.addAnnotation(tekst.getTextField());

        // space reserved for the year
        TextField prijs = new TextField(writer,
                new Rectangle(Utilities.millimetersToPoints(0), Utilities.millimetersToPoints(0),
                        Utilities.millimetersToPoints(35), Utilities.millimetersToPoints(7)),
                YEAR);
        prijs.setAlignment(Element.ALIGN_CENTER);
        prijs.setBackgroundColor(Color.BLUE);
        prijs.setTextColor(Color.WHITE);
        writer.addAnnotation(prijs.getTextField());
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    // step 5
    document.close();
}

From source file:net.sf.jasperreports.forms.textinput.TextInputElementPdfHandler.java

License:Open Source License

public void exportElement(JRPdfExporterContext exporterContext, JRGenericPrintElement element) {
    PdfWriter writer = exporterContext.getPdfWriter();
    JasperPrint jasperPrint = exporterContext.getExportedReport();

    JRPrintText printText = (JRPrintText) element
            .getParameterValue(TextInputElement.PARAMETER_PRINT_TEXT_ELEMENT);
    if (printText == null) //FIXMEINPUT deal with xml serialization
    {/*from ww  w .j av  a 2  s .  c o m*/
        return;
    }

    Rectangle rectangle = new Rectangle(element.getX() + exporterContext.getOffsetX(),
            jasperPrint.getPageHeight() - element.getY() - exporterContext.getOffsetY(),
            element.getX() + exporterContext.getOffsetX() + element.getWidth(),
            jasperPrint.getPageHeight() - element.getY() - exporterContext.getOffsetY() - element.getHeight());
    TextField text = new TextField(writer, rectangle, getFieldName(element));
    text.setBackgroundColor(printText.getBackcolor());
    text.setTextColor(printText.getForecolor());
    text.setText(printText.getFullText());
    text.setDefaultText("default:" + printText.getFullText());
    //      text.setBackgroundColor(element.getBackcolor());
    //      text.setTextColor(element.getForecolor());
    //      text.setText(getText(element));
    //      text.setDefaultText(getDefaultText(element));

    //FIXME: dynamic settings below:

    //      text.setAlignment(Element.ALIGN_LEFT);
    //      text.setBorderColor(Color.BLACK);
    //      text.setBorderWidth(TextField.BORDER_WIDTH_THIN);
    //      text.setBorderStyle(PdfBorderDictionary.STYLE_INSET);

    //      text.setChoiceExports(null);
    //      text.setChoices(null);
    //      text.setChoiceSelection(0);
    //      text.setExtensionFont(null);
    //      text.setExtraMargin(0, 0);
    //      try{
    //         text.setFont(BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1250, true));
    //      }catch(Exception e){
    //         throw new JRRuntimeException(e);
    //      }
    text.setFontSize(printText.getFontsize());
    if (Boolean.TRUE.equals(element.getParameterValue(TextInputElement.PARAMETER_MULTI_LINE))) {
        text.setOptions(TextField.MULTILINE);
    }
    //      text.setRotation(90);
    //      text.setVisibility(TextField.VISIBLE);

    try {
        PdfFormField field = text.getTextField();
        writer.addAnnotation(field);
    } catch (Exception e) {
        throw new JRRuntimeException(e);
    }

}