List of usage examples for org.apache.pdfbox.pdmodel.common PDRectangle getUpperRightX
public float getUpperRightX()
From source file:paper2ebook.Transformer.java
License:Apache License
/** * Heuristic search of the list of interesting areas in page, returned by * natural read order.//from w ww . ja v a 2s .co m */ public List<PDRectangle> getFragments(PDPage page) { List<PDRectangle> fragments = new ArrayList<PDRectangle>(); // TODO: naive 2 columns hack: rewrite me to introspect the document // structure instead PDRectangle origBox = page.findCropBox(); float width = origBox.getWidth(); float height = origBox.getHeight(); // top left PDRectangle box = new PDRectangle(); box.setLowerLeftX(origBox.getLowerLeftX()); box.setLowerLeftY(origBox.getLowerLeftY() + height / 2); box.setUpperRightX(origBox.getUpperRightX() / 2); box.setUpperRightY(origBox.getUpperRightY()); fragments.add(box); // bottom left box = new PDRectangle(); box.setLowerLeftX(origBox.getLowerLeftX()); box.setLowerLeftY(origBox.getLowerLeftY()); box.setUpperRightX(origBox.getUpperRightX() / 2); box.setUpperRightY(origBox.getUpperRightY() / 2); fragments.add(box); // top right box = new PDRectangle(); box.setLowerLeftX(origBox.getLowerLeftX() + width / 2); box.setLowerLeftY(origBox.getLowerLeftY() + height / 2); box.setUpperRightX(origBox.getUpperRightX()); box.setUpperRightY(origBox.getUpperRightY()); fragments.add(box); // bottom right box = new PDRectangle(); box.setLowerLeftX(origBox.getLowerLeftX() + width / 2); box.setLowerLeftY(origBox.getLowerLeftY()); box.setUpperRightX(origBox.getUpperRightX()); box.setUpperRightY(origBox.getUpperRightY() / 2); fragments.add(box); return fragments; }
From source file:PDF.RotatePDF.java
private void transformPage(PDDocument document, PDPage page, AffineTransform at) throws IOException, COSVisitorException { PDRectangle cropBox = page.findCropBox(); float xOffset = (cropBox.getUpperRightX() + cropBox.getLowerLeftX()) / 2f; float yOffset = (cropBox.getUpperRightY() + cropBox.getLowerLeftY()) / 2f; AffineTransform transform = AffineTransform.getTranslateInstance(xOffset, yOffset); transform.concatenate(at);//from w ww . jav a2s. c om transform.concatenate(AffineTransform.getTranslateInstance(-xOffset, -yOffset)); PDPageContentStream stream = new PDPageContentStream(document, page, true, false); stream.concatenate2CTM(transform); stream.close(); COSBase contents = page.getCOSDictionary().getDictionaryObject(COSName.CONTENTS); if (contents instanceof COSStreamArray) { COSStreamArray contentsArray = (COSStreamArray) contents; COSArray newArray = new COSArray(); newArray.add(contentsArray.get(contentsArray.getStreamCount() - 1)); for (int i = 0; i < contentsArray.getStreamCount() - 1; i++) { newArray.add(contentsArray.get(i)); } COSStreamArray newStreamArray = new COSStreamArray(newArray); page.getCOSDictionary().setItem(COSName.CONTENTS, newStreamArray); } }
From source file:vortext.TextHighlight.java
License:Apache License
/** * Computes a float array of size eight with all the vertices of the * PDRectangle/*from w w w. j a v a 2 s .com*/ */ public float[] getQuads(final PDRectangle rect) { final float[] quads = new float[8]; // top left quads[0] = rect.getLowerLeftX(); // x1 quads[1] = rect.getUpperRightY(); // y1 // bottom left quads[2] = rect.getUpperRightX(); // x2 quads[3] = quads[1]; // y2 // top right quads[4] = quads[0]; // x3 quads[5] = rect.getLowerLeftY(); // y3 // bottom right quads[6] = quads[2]; // x4 quads[7] = quads[5]; // y5 return quads; }