Example usage for com.lowagie.text.pdf PdfArray isEmpty

List of usage examples for com.lowagie.text.pdf PdfArray isEmpty

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfArray isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if the array is empty.

Usage

From source file:org.xhtmlrenderer.pdf.ITextOutputDevice.java

License:Open Source License

private void writeNamedDestinations(RenderingContext c) {
    Map idMap = getSharedContext().getIdMap();
    if ((idMap != null) && (!idMap.isEmpty())) {
        PdfArray dests = new PdfArray();
        try {/*from  w w  w  . j  a va2  s.  c  o m*/
            Iterator it = idMap.entrySet().iterator();
            while (it.hasNext()) {
                Entry entry = (Entry) it.next();

                Box targetBox = (Box) entry.getValue();

                if (targetBox.getStyle().isIdent(CSSName.FS_NAMED_DESTINATION, IdentValue.CREATE)) {
                    String anchorName = (String) entry.getKey();
                    dests.add(new PdfString(anchorName, PdfString.TEXT_UNICODE));

                    PdfDestination dest = createDestination(c, targetBox);
                    if (dest != null) {
                        PdfIndirectReference ref = _writer.addToBody(dest).getIndirectReference();
                        dests.add(ref);
                    }
                }
            }

            if (!dests.isEmpty()) {
                PdfDictionary nametree = new PdfDictionary();
                nametree.put(PdfName.NAMES, dests);
                PdfIndirectReference nameTreeRef = _writer.addToBody(nametree).getIndirectReference();

                PdfDictionary names = new PdfDictionary();
                names.put(PdfName.DESTS, nameTreeRef);
                PdfIndirectReference destinationsRef = _writer.addToBody(names).getIndirectReference();

                _writer.getExtraCatalog().put(PdfName.NAMES, destinationsRef);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}