Example usage for com.itextpdf.text.pdf PdfName POPUP

List of usage examples for com.itextpdf.text.pdf PdfName POPUP

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfName POPUP.

Prototype

PdfName POPUP

To view the source code for com.itextpdf.text.pdf PdfName POPUP.

Click Source Link

Document

A name

Usage

From source file:de.gbv.marginalia.Annotation.java

License:Open Source License

/**
 * Constructs a new Annotation from a given PdfDictionary.
 * Of course the PdfDictionary should contain an annotation.
 *///from www .ja  v a 2 s. com
// public Annotation(PdfDictionary annot) { this.Annotation(annot,0); }
public Annotation(PdfDictionary annot, int pageNum) {
    this.pageNum = pageNum;
    this.subtype = annot.getAsName(PdfName.SUBTYPE);
    // text | caret | freetext | fileattachment | highlight | ink | line | link | circle | square |
    // polygon | polyline | sound | squiggly | stamp | strikeout | underline 

    this.content = annot.getAsString(PdfName.CONTENTS);
    this.popup = getAsDictionary(annot, PdfName.POPUP);

    // TODO: skipped fields:
    // getAsDictionary(annot,PdfName.AP); // alternative to coords!
    // annot.getAsName(PdfName.AS);
    // getAsDictionary(annot,PdfName.A); // action
    // getAsDictionary(annot,PdfName.A); // additional action

    // annot.getAsNumber(PdfName.STRUCTPARENT);

    // Since PDF 1.5: 
    // RC = contents-richtext

    this.dict = annot;
}

From source file:de.gbv.marginalia.Annotation.java

License:Open Source License

/**
 * Serialize the annotation in XML format.
 * The annotation is emitted as stream of SAX events to a ContentHandler.
 * The XML is XFDF with additional Marginalia elements in its own namespace.
 *//*  ww w .  j  a  va 2 s .  c  o  m*/
public void serializeXML(ContentHandler handler) throws SAXException {
    SimpleXMLCreator xml = new SimpleXMLCreator(handler, namespaces);

    Set<PdfName> allkeys = this.dict.getKeys();
    allkeys.remove(PdfName.TYPE);
    allkeys.remove(PdfName.SUBTYPE);
    allkeys.remove(PdfName.PARENT);
    allkeys.remove(PdfName.CONTENTS);
    allkeys.remove(PdfName.POPUP);

    Map<String, String> attrs = new HashMap<String, String>();
    for (String aName : this.FIELDS.keySet()) {
        Field f = this.FIELDS.get(aName);
        String value = f.getFrom(this.dict);
        if (value != null) { // TODO: encoding & exception
            attrs.put(aName, value);
            //                allkeys.remove( f.name );
        }
    }

    PdfDictionary pg = getAsDictionary(this.dict, PdfName.P);
    allkeys.remove(PdfName.P);
    //CropBox=[0, 0, 595, 842]
    //Rotate
    //MediaBox=[0, 0, 595, 842]
    // TODO: find out where page number is stored
    if (attrs.get("page") == null)
        attrs.put("page", "" + this.pageNum);

    String element = subtypes.get(this.subtype);
    if (element == null) { // TODO
        element = this.subtype.toString();
    }

    xml.startElement(element, attrs);

    if (element.equals("ink")) {
        PdfArray inklist = this.dict.getAsArray(new PdfName("InkList"));
        if (inklist != null) {
            xml.startElement("inklist");
            for (int i = 0; i < inklist.size(); i++) {
                PdfArray pathArray = inklist.getAsArray(i);
                String s = "";
                for (int j = 0; j < pathArray.size(); j += 2) {
                    if (j > 0)
                        s += ";";
                    s += "" + pathArray.getAsNumber(j).floatValue() + ",";
                    s += "" + pathArray.getAsNumber(j + 1).floatValue();
                }
                xml.contentElement("gesture", s);
            }
            xml.endElement();
        }
    }

    if (attrs.get("rect") != null) {
        Map<String, String> a = new HashMap<String, String>();
        RectField rf = (RectField) this.FIELDS.get("rect");
        PdfRectangle r = null;
        if (rf != null)
            r = (PdfRectangle) rf.getObjectFrom(this.dict);
        if (r != null) {
            a.put("left", "" + r.left());
            a.put("bottom", "" + r.bottom());
            a.put("right", "" + r.right());
            a.put("top", "" + r.top());
            xml.emptyElement("m", "rect", a);
        }
    }

    if (this.content != null && !this.content.equals("")) {
        // TODO: encode content if not UTF-8 ?
        xml.contentElement("content", content.toString());
    }
    // TODO: contents-richtext
    // TODO: popup
    /*
          if ( this.popup != null ) {
            out.println("<!--popup>");
            for ( PdfName n : this.popup.getKeys() ) {
               out.println( n + "=" + this.popup.getDirectObject(n) );
            }
            out.println("</popup-->");
          }
    */
    // remaining dictionary elements
    /*
            for ( PdfName name : allkeys ) {
    Map<String,String> a = new HashMap<String,String>();
    a.put("name",name.toString());
    a.put("value",this.dict.getDirectObject(name).toString());
    xml.emptyElement( "m","unknown", a );
            }
    */
    xml.endElement();
}