Search in sources :

Example 1 with PDThreadBead

use of com.tom_roush.pdfbox.pdmodel.interactive.pagenavigation.PDThreadBead in project PdfBox-Android by TomRoush.

the class PDPage method getThreadBeads.

/**
 * This will get a list of PDThreadBead objects, which are article threads in the document. This
 * will return an empty list if there are no thread beads.
 *
 * @return A list of article threads on this page, never null. The returned list is backed by
 * the beads COSArray, so any adding or deleting in this list will change the document too.
 */
public List<PDThreadBead> getThreadBeads() {
    COSArray beads = (COSArray) page.getDictionaryObject(COSName.B);
    if (beads == null) {
        beads = new COSArray();
    }
    List<PDThreadBead> pdObjects = new ArrayList<PDThreadBead>();
    for (int i = 0; i < beads.size(); i++) {
        COSBase base = beads.getObject(i);
        PDThreadBead bead = null;
        // in some cases the bead is null
        if (base instanceof COSDictionary) {
            bead = new PDThreadBead((COSDictionary) base);
        }
        pdObjects.add(bead);
    }
    return new COSArrayList<PDThreadBead>(pdObjects, beads);
}
Also used : COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) ArrayList(java.util.ArrayList) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDThreadBead(com.tom_roush.pdfbox.pdmodel.interactive.pagenavigation.PDThreadBead)

Example 2 with PDThreadBead

use of com.tom_roush.pdfbox.pdmodel.interactive.pagenavigation.PDThreadBead in project PdfBox-Android by TomRoush.

the class PDFTextStripper method fillBeadRectangles.

private void fillBeadRectangles(PDPage page) {
    beadRectangles = new ArrayList<PDRectangle>();
    for (PDThreadBead bead : page.getThreadBeads()) {
        if (bead == null) {
            // can't skip, because of null entry handling in processTextPosition()
            beadRectangles.add(null);
            continue;
        }
        PDRectangle rect = bead.getRectangle();
        // bead rectangle is in PDF coordinates (y=0 is bottom),
        // glyphs are in image coordinates (y=0 is top),
        // so we must flip
        PDRectangle mediaBox = page.getMediaBox();
        float upperRightY = mediaBox.getUpperRightY() - rect.getLowerLeftY();
        float lowerLeftY = mediaBox.getUpperRightY() - rect.getUpperRightY();
        rect.setLowerLeftY(lowerLeftY);
        rect.setUpperRightY(upperRightY);
        // adjust for cropbox
        PDRectangle cropBox = page.getCropBox();
        if (cropBox.getLowerLeftX() != 0 || cropBox.getLowerLeftY() != 0) {
            rect.setLowerLeftX(rect.getLowerLeftX() - cropBox.getLowerLeftX());
            rect.setLowerLeftY(rect.getLowerLeftY() - cropBox.getLowerLeftY());
            rect.setUpperRightX(rect.getUpperRightX() - cropBox.getLowerLeftX());
            rect.setUpperRightY(rect.getUpperRightY() - cropBox.getLowerLeftY());
        }
        beadRectangles.add(rect);
    }
}
Also used : PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle) PDThreadBead(com.tom_roush.pdfbox.pdmodel.interactive.pagenavigation.PDThreadBead)

Aggregations

PDThreadBead (com.tom_roush.pdfbox.pdmodel.interactive.pagenavigation.PDThreadBead)2 COSArray (com.tom_roush.pdfbox.cos.COSArray)1 COSBase (com.tom_roush.pdfbox.cos.COSBase)1 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)1 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)1 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)1 ArrayList (java.util.ArrayList)1