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);
}
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);
}
}
Aggregations