Example usage for com.lowagie.text.pdf PushbuttonField setImage

List of usage examples for com.lowagie.text.pdf PushbuttonField setImage

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PushbuttonField setImage.

Prototype

public void setImage(Image image) 

Source Link

Document

Sets the icon as an image.

Usage

From source file:classroom.filmfestival_c.Movies23.java

public static void fillForm(String filename, AccreditationData data, OutputStream out)
        throws IOException, DocumentException {

    PdfReader reader = new PdfReader(filename);
    PdfStamper stamper = new PdfStamper(reader, out);

    AcroFields form = stamper.getAcroFields();
    form.setField("name", data.getName());
    form.setFieldProperty("type", "textcolor", data.getTypeColor(), null);
    form.setField("type", data.getTypeName());
    form.setField("number", data.getNumber(false));
    form.setFieldProperty("filmfestival", "bgcolor", data.getTypeColor(), null);
    form.regenerateField("filmfestival");

    if (data.getPhoto() != null) {
        PushbuttonField bt = form.getNewPushbuttonFromField("photo");
        bt.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
        bt.setProportionalIcon(true);/*w w w  .  j  a v  a 2  s.co m*/
        bt.setImage(data.getPhoto());
        form.replacePushbuttonField("photo", bt.getField());
    }

    try {
        BarcodeInter25 code = new BarcodeInter25();
        code.setGenerateChecksum(true);
        code.setBarHeight(mm2pt(3));
        code.setCode(data.getNumber(true));
        code.setFont(null);
        PdfContentByte cb = new PdfContentByte(stamper.getWriter());
        PdfTemplate template = code.createTemplateWithBarcode(cb, null, null);
        PushbuttonField bt = form.getNewPushbuttonFromField("barcode");
        bt.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
        bt.setProportionalIcon(false);
        bt.setTemplate(template);
        form.replacePushbuttonField("barcode", bt.getField());
    } catch (Exception e) {
        // not a valid code, do nothing
    }

    stamper.setFormFlattening(data.isFlatten());
    stamper.close();
}

From source file:classroom.filmfestival_c.Movies25.java

public static byte[] createPdf(FilmTitle movie) throws IOException, DocumentException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfReader reader = new PdfReader(TEMPLATE);
    PdfStamper stamper = new PdfStamper(reader, baos);
    AcroFields form = stamper.getAcroFields();

    File file = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg");
    if (file.exists()) {
        PushbuttonField bt = form.getNewPushbuttonFromField(POSTER);
        bt.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
        bt.setProportionalIcon(true);/*  ww w  .ja  v a  2 s . co  m*/
        bt.setImage(Image.getInstance(file.getPath()));
        form.replacePushbuttonField(POSTER, bt.getField());
    }

    String s = createHtml(movie);
    PdfContentByte canvas = stamper.getOverContent(1);
    float size = 12;
    float[] f = form.getFieldPositions(TEXT);
    while (addText(s, canvas, f, size, true) && size > 6) {
        size -= 0.2;
    }
    addText(s, canvas, f, size, false);

    form.setField(YEAR, String.valueOf(movie.getYear()));

    stamper.setFormFlattening(true);
    stamper.close();
    return baos.toByteArray();
}

From source file:classroom.newspaper_b.Newspaper10.java

public static void main(String[] args) {
    try {//from w w  w  .  j a va2 s .  c  o  m
        PdfReader reader = new PdfReader(NEWSPAPER);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        PushbuttonField button;
        Rectangle rect;

        rect = new Rectangle(100, 980, 700, 1000);
        button = new PushbuttonField(stamper.getWriter(), rect, "click");
        button.setBackgroundColor(Color.ORANGE);
        button.setText("Click here to close window");
        button.setLayout(PushbuttonField.LAYOUT_LABEL_ONLY);
        button.setAlignment(Element.ALIGN_RIGHT);
        PdfFormField menubar = button.getField();
        String js = "var f1 = getField('click'); f1.display = display.hidden;"
                + "var f2 = getField('advertisement'); f2.display = display.hidden;";
        menubar.setAction(PdfAction.javaScript(js, stamper.getWriter()));
        stamper.addAnnotation(menubar, 1);

        rect = new Rectangle(100, 500, 700, 980);
        button = new PushbuttonField(stamper.getWriter(), rect, "advertisement");
        button.setBackgroundColor(Color.WHITE);
        button.setBorderColor(Color.ORANGE);
        button.setImage(Image.getInstance(IMG));
        button.setText("Buy the book iText in Action");
        button.setLayout(PushbuttonField.LAYOUT_LABEL_TOP_ICON_BOTTOM);
        PdfFormField advertisement = button.getField();
        advertisement.setAction(new PdfAction("http://www.1t3xt.com/docs/book.php"));
        stamper.addAnnotation(advertisement, 1);
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:classroom.newspaper_b.Newspaper13.java

public static void addButton(PdfStamper stamper, Rectangle rect, String path, String name, int pagenumber)
        throws IOException, DocumentException {
    PushbuttonField field = new PushbuttonField(stamper.getWriter(), rect, name);
    if (path.endsWith(".pdf")) {
        PdfReader reader = new PdfReader(path);
        field.setTemplate(stamper.getImportedPage(reader, 1));
    } else {//w  ww .  j av a2s .c  o m
        field.setImage(Image.getInstance(path));
    }
    field.setBackgroundColor(new Color(0xFF, 0xFF, 0xFF));
    field.setBorderColor(new Color(0xC0, 0xC0, 0xC0));
    field.setBorderWidth(0.5f);
    field.setScaleIcon(PushbuttonField.SCALE_ICON_ALWAYS);
    field.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
    stamper.addAnnotation(field.getField(), pagenumber);
}