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

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

Introduction

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

Prototype

public void setFontSize(float fontSize) 

Source Link

Document

Sets the font size.

Usage

From source file:at.reppeitsolutions.formbuilder.components.pdf.itext.ITextInputText.java

License:Open Source License

@Override
public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) {
    PdfWriter writer = canvases[0].getPdfWriter();
    TextField text = new TextField(writer, rectangle, String.format("text_" + UUID.randomUUID().toString()));
    text.setBorderStyle(PdfBorderDictionary.STYLE_INSET);
    text.setText(value);//from w w w. ja v  a  2  s .com
    text.setFontSize(FONTSIZE);
    text.setAlignment(Element.ALIGN_LEFT);
    try {
        PdfFormField field = text.getTextField();
        if (locked) {
            field.setFieldFlags(BaseField.READ_ONLY);
        }
        writer.addAnnotation(field);
    } catch (IOException ioe) {
        throw new ExceptionConverter(ioe);
    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    }
}

From source file:at.reppeitsolutions.formbuilder.components.pdf.itext.ITextListbox.java

License:Open Source License

@Override
public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) {
    PdfWriter writer = canvases[0].getPdfWriter();
    TextField text = new TextField(writer, rectangle, String.format("choice_" + UUID.randomUUID().toString()));
    text.setBorderStyle(PdfBorderDictionary.STYLE_INSET);
    text.setFontSize(ITextInputText.FONTSIZE);
    text.setOptions(TextField.MULTISELECT);
    text.setChoices(values);//  w  w  w .  j av  a2s .c  o m
    ArrayList<Integer> choiceSelections = new ArrayList<>();
    if (selectedValues != null) {
        for (int i = 0; i < values.length; i++) {
            for (int i2 = 0; i2 < selectedValues.length; i2++) {
                if (values[i].equals(selectedValues[i2])) {
                    choiceSelections.add(i);
                    break;
                }
            }
        }
    }
    text.setChoiceSelections(choiceSelections);
    try {
        PdfFormField listField = text.getListField();
        if (locked) {
            listField.setFieldFlags(BaseField.READ_ONLY);
        }
        writer.addAnnotation(listField);
    } catch (IOException ex) {
        Logger.getLogger(ITextListbox.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(ITextListbox.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:at.reppeitsolutions.formbuilder.components.pdf.itext.ITextSelect.java

License:Open Source License

@Override
public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) {
    PdfWriter writer = canvases[0].getPdfWriter();
    TextField text = new TextField(writer, rectangle, String.format("choice_" + UUID.randomUUID().toString()));
    text.setBorderStyle(PdfBorderDictionary.STYLE_INSET);
    text.setChoices(values);/* www . j  a va2 s. c  om*/
    text.setFontSize(ITextInputText.FONTSIZE);
    text.setChoiceExports(text.getChoices());
    for (int i = 0; value != null && i < values.length; i++) {
        if (values[i].equals(value)) {
            text.setChoiceSelection(i);
            break;
        }
    }
    try {
        PdfFormField comboField = text.getComboField();
        if (locked) {
            comboField.setFieldFlags(BaseField.READ_ONLY);
        }
        writer.addAnnotation(comboField);
    } catch (IOException ex) {
        Logger.getLogger(ITextSelect.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(ITextSelect.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:classroom.filmfestival_c.Movies22.java

public static void main(String[] args) {
    // step 1//from w  w  w.j ava  2  s .c om
    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:com.geek.tutorial.itext.acroform.ListFieldForm.java

License:Open Source License

public ListFieldForm() throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ListFieldForm.pdf"));
    document.open();// w  w w. ja  v  a 2s .co m

    // Code 1
    String options[] = { "PS3", "XBOX 360", "Wii", "PSP", "NDS", "GBA" };

    // Code 2 create drop-down list
    PdfFormField dropDown = PdfFormField.createCombo(writer, true, options, 0);
    dropDown.setWidget(new Rectangle(50, 785, 120, 800), PdfAnnotation.HIGHLIGHT_INVERT);
    dropDown.setFieldName("dropDownList");
    dropDown.setValueAsString("PS3");
    dropDown.setMKBorderColor(Color.BLACK);
    writer.addAnnotation(dropDown);

    // Code 3 create scrollable list
    TextField scrollableList = new TextField(writer, new Rectangle(150, 740, 250, 800), "scrollableList");
    scrollableList.setBackgroundColor(Color.WHITE);
    scrollableList.setBorderColor(Color.BLUE);
    scrollableList.setBorderWidth(2);
    scrollableList.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
    scrollableList.setFontSize(10);
    scrollableList.setChoices(options);
    scrollableList.setChoiceSelection(0);
    writer.addAnnotation(scrollableList.getListField());

    // Code 4 add function and button for showing state 
    writer.addJavaScript(
            "function showState(){" + "app.alert('DropDown:'+ this.getField('dropDownList').value +'\\n'+"
                    + "'Scrollable List:'+this.getField('scrollableList').value);" + "}");
    PushbuttonField push = new PushbuttonField(writer, new Rectangle(70, 710, 140, 730), "pushAction");
    push.setBackgroundColor(Color.LIGHT_GRAY);
    push.setBorderColor(Color.GRAY);
    push.setText("Show State");
    push.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
    push.setTextColor(Color.BLACK);
    PdfFormField pushbutton = push.getField();
    pushbutton.setAction(PdfAction.javaScript("showState()", writer));
    writer.addAnnotation(pushbutton);

    document.close();
}

From source file:corner.orm.tapestry.pdf.components.PdfText.java

License:Apache License

/**
 * @see corner.orm.tapestry.pdf.components.AbstractPdfComponent#renderPdf(corner.orm.tapestry.pdf.PdfWriterDelegate, com.lowagie.text.Document)
 *//*from ww w.  j  av a2 s.  co m*/
@Override
public void renderPdf(PdfWriterDelegate writer, Document doc) {
    Defense.notNull(getRectangle(), "TextField?");
    String[] p = getRectangle().split(",");
    Rectangle r = new Rectangle(Float.valueOf(p[0]), Float.valueOf(p[1]), Float.valueOf(p[2]),
            Float.valueOf(p[3]));

    TextField tf = getFieldCreator().createTextField(writer.getPdfWriter(), r, this.getId());

    tf.setOptions(TextField.READ_ONLY);

    if (isMultiline()) {
        tf.setOptions(TextField.MULTILINE);
    }

    if (isAlignCenter()) {
        tf.setAlignment(Element.ALIGN_CENTER);
    }
    if (getValue() != null) {// 
        tf.setFont(PdfUtils.createSongLightBaseFont());
        if (getFontSize() > 0)
            tf.setFontSize(getFontSize());
        tf.setText(getValue());
    }
    try {
        writer.getPdfWriter().addAnnotation(tf.getTextField());
    } catch (IOException e) {
        throw new PdfSystemException(e);
    } catch (DocumentException e) {
        throw new PdfSystemException(e);
    }
}

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  w ww  . j  a  v  a  2 s  . co 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);
    }

}

From source file:questions.forms.FormWithTooltips.java

private static PdfPTable createTable(PdfWriter writer, PdfFormField parent)
        throws IOException, DocumentException {
    PdfPTable table = new PdfPTable(2);
    PdfPCell cell;/*from www  .java2  s  .com*/
    TextField field;
    table.getDefaultCell().setPadding(5f);

    table.addCell("Your name:");
    cell = new PdfPCell();
    field = new TextField(writer, new Rectangle(0, 0), "name");
    field.setFontSize(12);
    cell.setCellEvent(new FormWithTooltips(parent, field.getTextField(), 1, "Your name"));
    table.addCell(cell);

    table.addCell("Your home address:");
    cell = new PdfPCell();
    field = new TextField(writer, new Rectangle(0, 0), "address");
    field.setFontSize(12);
    cell.setCellEvent(new FormWithTooltips(parent, field.getTextField(), 1, "Street and number"));
    table.addCell(cell);

    table.addCell("Postal code:");
    cell = new PdfPCell();
    field = new TextField(writer, new Rectangle(0, 0), "postal_code");
    field.setFontSize(12);
    cell.setCellEvent(new FormWithTooltips(parent, field.getTextField(), 1, "Postal code"));
    table.addCell(cell);

    table.addCell("City:");
    cell = new PdfPCell();
    field = new TextField(writer, new Rectangle(0, 0), "city");
    field.setFontSize(12);
    cell.setCellEvent(new FormWithTooltips(parent, field.getTextField(), 1, "City"));
    table.addCell(cell);

    table.addCell("Country:");
    cell = new PdfPCell();
    field = new TextField(writer, new Rectangle(0, 0), "country");
    field.setFontSize(12);
    cell.setCellEvent(new FormWithTooltips(parent, field.getTextField(), 1, "Country"));
    table.addCell(cell);

    table.addCell("Your email address:");
    cell = new PdfPCell();
    field = new TextField(writer, new Rectangle(0, 0), "email");
    field.setFontSize(12);
    cell.setCellEvent(new FormWithTooltips(parent, field.getTextField(), 1, "mail address"));
    table.addCell(cell);
    return table;
}

From source file:questions.forms.MultipleChoice.java

public static void createPdf() throws IOException, DocumentException {
    // step 1//from   ww  w.j  a v a 2s  . c  om
    Document document = new Document();
    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
    // step 3
    document.open();
    // step 4
    TextField field = new TextField(writer, new Rectangle(36, 750, 144, 806), "iText");
    field.setFontSize(9);
    String[] list_options = { "JAVA", "C", "CS", "VB", "PHP" };
    field.setChoiceExports(list_options);
    String[] list_values = { "Java", "C/C++", "C#", "VB", "PHP" };
    field.setChoices(list_values);
    PdfFormField f = field.getListField();
    f.setFieldFlags(PdfFormField.FF_MULTISELECT);
    f.put(PdfName.I, new PdfArray(new int[] { 0, 2 }));
    writer.addAnnotation(f);
    // step 5
    document.close();
}