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

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

Introduction

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

Prototype

int LAYOUT_ICON_ONLY

To view the source code for com.itextpdf.text.pdf PushbuttonField LAYOUT_ICON_ONLY.

Click Source Link

Document

A layout option

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 {/*w  w  w .  j  a va2  s . co  m*/

        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);
    }
}