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

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

Introduction

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

Prototype

public void setProportionalIcon(boolean proportionalIcon) 

Source Link

Document

Sets the way the icon is scaled.

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);
        bt.setImage(data.getPhoto());//  w w  w .j  a va 2 s .c o m
        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

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    createTemplate();/*from ww w .jav a 2s.  c o m*/
    Session session = (Session) MySessionFactory.currentSession();
    Query q = session.createQuery("from FilmTitle order by title");
    java.util.List<FilmTitle> results = q.list();
    try {
        Document document = new Document();
        PdfSmartCopy copy = new PdfSmartCopy(document, new FileOutputStream(RESULT));
        document.open();

        PdfReader reader;
        PdfStamper stamper = null;
        ByteArrayOutputStream baos = null;
        AcroFields form = null;
        int count = 0;
        for (FilmTitle movie : results) {
            if (count == 0) {
                baos = new ByteArrayOutputStream();
                reader = new PdfReader(BACKGROUND);
                stamper = new PdfStamper(reader, baos);
                stamper.setFormFlattening(true);
                form = stamper.getAcroFields();
            }
            count++;
            byte[] pdf = createPdf(movie);
            reader = new PdfReader(pdf);
            PdfImportedPage page = stamper.getImportedPage(reader, 1);
            PushbuttonField bt = form.getNewPushbuttonFromField("movie_" + count);
            bt.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
            bt.setProportionalIcon(true);
            bt.setTemplate(page);
            form.replacePushbuttonField("movie_" + count, bt.getField());
            if (count == 16) {
                stamper.close();
                reader = new PdfReader(baos.toByteArray());
                copy.addPage(copy.getImportedPage(reader, 1));
                count = 0;
            }
        }
        if (count > 0) {
            stamper.close();
            reader = new PdfReader(baos.toByteArray());
            copy.addPage(copy.getImportedPage(reader, 1));
            count = 0;
        }
        document.close();
    } catch (IOException ioe) {
        LOGGER.error("IOException: ", ioe);
    } catch (DocumentException de) {
        LOGGER.error("DocumentException: ", de);
    }
}

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);
        bt.setImage(Image.getInstance(file.getPath()));
        form.replacePushbuttonField(POSTER, bt.getField());
    }/*from w w w. j  a  va  2 s  .  co  m*/

    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.Newspaper14.java

public static void changeField(PdfStamper stamper, String button, String path)
        throws IOException, DocumentException {
    AcroFields fields = stamper.getAcroFields();
    PushbuttonField bt = fields.getNewPushbuttonFromField(button);
    bt.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
    bt.setProportionalIcon(true);
    PdfReader reader = new PdfReader(path);
    bt.setTemplate(stamper.getImportedPage(reader, 1));
    fields.replacePushbuttonField(button, bt.getField());
}