Example usage for com.lowagie.text.pdf PdfObject isNumber

List of usage examples for com.lowagie.text.pdf PdfObject isNumber

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfObject isNumber.

Prototype

public boolean isNumber() 

Source Link

Document

Checks if this PdfObject is of the type PdfNumber.

Usage

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

License:Open Source License

private String makeBookmarkParam(PdfReader reader, Bookmark bookmark, PdfArray dest, IntHashtable pages) {
    StringBuilder s = new StringBuilder();
    PdfObject obj = dest.getPdfObject(0);
    if (obj.isNumber()) {
        s.append(((PdfNumber) obj).intValue() + 1);
        bookmark.setPageNumber(((PdfNumber) obj).intValue() + 1);
    } else {/* www .  j  ava 2  s  .c  o m*/
        if (pages == null) {
            initPages();
        }
        if (pages != null) {
            s.append(pages.get(getNumber((PdfIndirectReference) obj))); //changed by ujihara 2004-06-13
            bookmark.setPageNumber(pages.get(getNumber((PdfIndirectReference) obj)));
        }
    }

    Rectangle pageSize = null;
    //if (bookmark.getType().equals(BookmarkType.GoToFile) == false) {
    //if (!bookmark.isRemoteDestination()) {
    pageSize = reader.getPageSize(bookmark.getPageNumber());
    //}

    if (pageSize != null) {
        bookmark.setPageWidth(pageSize.getWidth());
        bookmark.setPageHeight(pageSize.getHeight());
    }

    String destType = dest.getPdfObject(1).toString();
    PdfObject[] params = new PdfObject[dest.size()];
    for (int k = 2; k < dest.size(); ++k) {
        params[k - 2] = dest.getPdfObject(k);
    }
    if (destType.equals("/XYZ")) {
        bookmark.setType(BookmarkType.TopLeftZoom);
        if (!params[0].isNull()) {
            bookmark.setLeft(((PdfNumber) params[0]).intValue());
        }
        if (!params[1].isNull()) {
            bookmark.setTop(((PdfNumber) params[1]).intValue());
        }
        if (pageSize != null) {
            bookmark.setThousandthsLeft(thousandthsHorizontal(bookmark.getLeft(), pageSize));
            bookmark.setThousandthsTop(thousandthsVertical(bookmark.getTop(), pageSize));
        }
        if (!params[2].isNull()) {
            bookmark.setZoom(((PdfNumber) params[2]).floatValue());
        }
    } else if (destType.equals("/FitH")) {
        bookmark.setType(BookmarkType.FitWidth);
        if (!params[0].isNull()) {
            bookmark.setTop(((PdfNumber) params[0]).intValue());
        }
        if (pageSize != null) {
            bookmark.setThousandthsTop(thousandthsVertical(bookmark.getTop(), pageSize));
        }
    } else if (destType.equals("/FitV")) {
        bookmark.setType(BookmarkType.FitHeight);
        if (!params[0].isNull()) {
            bookmark.setLeft(((PdfNumber) params[0]).intValue());
        }
        if (pageSize != null) {
            bookmark.setThousandthsLeft(thousandthsHorizontal(bookmark.getLeft(), pageSize));
        }
    } else if (destType.equals("/FitBH")) {
        bookmark.setType(BookmarkType.FitContentWidth);
        if (!params[0].isNull()) {
            bookmark.setTop(((PdfNumber) params[0]).intValue());
        }
        if (pageSize != null) {
            bookmark.setThousandthsTop(thousandthsVertical(bookmark.getTop(), pageSize));
        }
    } else if (destType.equals("/FitBV")) {
        bookmark.setType(BookmarkType.FitContentHeight);
        if (!params[0].isNull()) {
            bookmark.setLeft(((PdfNumber) params[0]).intValue());
        }
        if (pageSize != null) {
            bookmark.setThousandthsLeft(thousandthsHorizontal(bookmark.getLeft(), pageSize));
        }
    } else if (destType.equals("/Fit")) {
        bookmark.setType(BookmarkType.FitPage);
    } else if (destType.equals("/FitB")) {
        bookmark.setType(BookmarkType.FitContent);
    } else if (destType.equals("/FitR")) {
        bookmark.setType(BookmarkType.FitRect);
        if (!params[0].isNull()) {
            bookmark.setLeft(((PdfNumber) params[0]).intValue());
        }
        if (!params[1].isNull()) {
            bookmark.setBottom(((PdfNumber) params[1]).intValue());
        }
        if (!params[2].isNull()) {
            bookmark.setRight(((PdfNumber) params[2]).intValue());
        }
        if (!params[3].isNull()) {
            bookmark.setTop(((PdfNumber) params[3]).intValue());
        }
        if (pageSize != null) {
            bookmark.setThousandthsLeft(thousandthsHorizontal(bookmark.getLeft(), pageSize));
            bookmark.setThousandthsTop(thousandthsVertical(bookmark.getTop(), pageSize));
            bookmark.setThousandthsRight(thousandthsHorizontal(bookmark.getRight(), pageSize));
            bookmark.setThousandthsBottom(thousandthsVertical(bookmark.getBottom(), pageSize));
        }
    }

    s.append(' ').append(dest.getPdfObject(1).toString().substring(1));
    for (int k = 2; k < dest.size(); ++k) {
        s.append(' ').append(dest.getPdfObject(k).toString());
    }
    return s.toString();
}