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

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

Introduction

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

Prototype

public void setImage(Image image) 

Source Link

Document

Sets the icon as an image.

Usage

From source file:org.smap.sdal.managers.PDFSurveyManager.java

License:Open Source License

private static void fillTemplateUserDetails(AcroFields pdfForm, User user, String basePath)
        throws IOException, DocumentException {
    try {/*from w ww.  j a v a2  s .  c om*/

        pdfForm.setField("user_name", user.name);
        pdfForm.setField("user_company", user.company_name);

        /*
         * User configurable data TODO This should be an array of key value pairs
         * As interim use a hard coded class to hold the data
         */
        String settings = user.settings;
        Type type = new TypeToken<UserSettings>() {
        }.getType();
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
        UserSettings us = gson.fromJson(settings, type);

        if (us != null) {
            pdfForm.setField("user_title", us.title);
            pdfForm.setField("user_license", us.license);

            PushbuttonField ad = pdfForm.getNewPushbuttonFromField("user_signature");
            if (ad != null) {
                ad.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
                ad.setProportionalIcon(true);
                String filename = null;
                try {
                    filename = basePath + "/media/users/" + user.id + "/sig/" + user.signature;
                    ad.setImage(Image.getInstance(filename));
                } catch (Exception e) {
                    log.info("Error: Failed to add signature " + filename + " to pdf");
                }
                pdfForm.replacePushbuttonField("user_signature", ad.getField());
            } else {
                //log.info("Picture field: user_signature not found");
            }
        }

    } catch (Exception e) {
        log.log(Level.SEVERE, "Error filling template", e);
    }
}