Example usage for com.lowagie.text.pdf PdfNumber intValue

List of usage examples for com.lowagie.text.pdf PdfNumber intValue

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfNumber intValue.

Prototype

public int intValue() 

Source Link

Document

Returns the primitive int value of this object.

Usage

From source file:it.flavianopetrocchi.jpdfbookmarks.itextbookmarksconverter.iTextBookmarksConverter.java

License:Open Source License

private Bookmark bookmarkFromDictionary(PdfDictionary outline) {
    if (outline == null) {
        return null;
    }/* w ww .  j a v a 2  s  . c o m*/
    Bookmark bookmark = new Bookmark();
    PdfString title = (PdfString) PdfReader.getPdfObjectRelease(outline.get(PdfName.TITLE));
    bookmark.setTitle(title.toUnicodeString());
    PdfArray color = (PdfArray) PdfReader.getPdfObjectRelease(outline.get(PdfName.C));
    if (color != null && color.size() == 3) {
        ByteBuffer out = new ByteBuffer();
        out.append(color.getAsNumber(0).floatValue()).append(' ');
        out.append(color.getAsNumber(1).floatValue()).append(' ');
        out.append(color.getAsNumber(2).floatValue());
        bookmark.setColor(new Color(color.getAsNumber(0).floatValue(), color.getAsNumber(1).floatValue(),
                color.getAsNumber(2).floatValue()));
    }
    PdfNumber style = (PdfNumber) PdfReader.getPdfObjectRelease(outline.get(PdfName.F));
    if (style != null) {
        int f = style.intValue();
        if ((f & 1) != 0) {
            bookmark.setItalic(true);
        }
        if ((f & 2) != 0) {
            bookmark.setBold(true);
        }
    }
    PdfNumber count = (PdfNumber) PdfReader.getPdfObjectRelease(outline.get(PdfName.COUNT));
    if (count != null && count.intValue() < 0) {
        bookmark.setOpened(false);
    } else {
        bookmark.setOpened(true);
    }
    try {
        PdfObject dest = PdfReader.getPdfObjectRelease(outline.get(PdfName.DEST));
        if (dest != null) {
            mapGotoBookmark(bookmark, dest);
        } else {
            PdfDictionary action = (PdfDictionary) PdfReader.getPdfObjectRelease(outline.get(PdfName.A));
            if (action != null) {
                setActionsRecursive(bookmark, action);
            } else {
                bookmark.setType(BookmarkType.Unknown);
            }
        }
    } catch (Exception e) {
        //empty on purpose
    }
    return bookmark;
}

From source file:org.squale.welcom.outils.pdf.advanced.WPdfFieldReader.java

License:Open Source License

/**
 * init/*from www. j  a  va 2  s  .  c o  m*/
 */
public void init() {
    for (int i = 0; i < pdfReader.getAcroForm().size(); i++) {

        final PRAcroForm.FieldInformation p = (PRAcroForm.FieldInformation) pdfReader.getAcroForm().getFields()
                .get(i);

        final WPdfField pf = new WPdfField();
        pf.setName(p.getName());

        // Si ce n'est pas un champs text alors on l'ignore
        if (!p.getInfo().contains(PdfName.FT)
                || !(((PdfName) p.getInfo().get(PdfName.FT)).toString().equals(PdfName.TX.toString()))) {
            pf.setType(WPdfFieldType.INCONNU);
        } else {
            if (p.getInfo().contains(PdfName.DV)) {
                pf.setDefaultValue(((PdfString) (p.getInfo().get(PdfName.DV))).toUnicodeString());
            }
            if (p.getInfo().contains(PdfName.V)) {
                pf.setValue(((PdfString) (p.getInfo().get(PdfName.V))).toUnicodeString());
            }
            if (p.getInfo().contains(PdfName.FF)) {
                final PdfNumber pn = (PdfNumber) p.getInfo().get(PdfName.FF);
                if ((pn.intValue() & PdfFormField.FF_MULTILINE) == PdfFormField.FF_MULTILINE) {
                    pf.setType(WPdfFieldType.MUTILINETEXT);
                } else {
                    pf.setType(WPdfFieldType.TEXT);
                }
            } else {
                pf.setType(WPdfFieldType.TEXT);
            }
        }
        fields.add(pf);
    }
}

From source file:org.squale.welcom.outils.pdf.advanced.WPdfFieldWriter.java

License:Open Source License

/**
 * Tranforme les champs en nom modifiable
 * // w  w  w.j  a  v  a2  s  . c o m
 * @param form le field
 * @param name le nom
 */
private static void lockField(final AcroFields form, final String name) {
    final AcroFields.Item item = form.getFieldItem(name);
    if (item != null) {
        for (int k = 0; k < item.merged.size(); ++k) {
            PdfNumber num = (PdfNumber) PdfReader
                    .getPdfObject(((PdfDictionary) item.values.get(k)).get(PdfName.FF));
            int val = 0;

            if (num != null) {
                val = num.intValue();
            }

            num = new PdfNumber(val | PdfFormField.FF_READ_ONLY);

            ((PdfDictionary) item.merged.get(k)).put(PdfName.FF, num);
            ((PdfDictionary) item.values.get(k)).put(PdfName.FF, num);
        }
    }
}