List of usage examples for org.apache.pdfbox.text TextPosition getXScale
public float getXScale()
From source file:PDFTextExtract.java
License:Apache License
/** * Override the default functionality of PDFTextStripper. *///from w w w.ja v a 2s. c om @Override protected void writeString(String _string, List<TextPosition> textPositions) throws IOException { for (TextPosition text : textPositions) { { _tmp.add(new Text(text.getXDirAdj(), text.getYDirAdj(), text.getFontSize(), text.getXScale(), text.getHeightDir(), text.getWidthOfSpace(), text.getWidthDirAdj(), text.getUnicode())); } } }
From source file:com.yiyihealth.tools.test.DrawPrintTextLocations.java
License:Apache License
/** * Override the default functionality of PDFTextStripper. *//*from w w w .jav a 2s.c om*/ @Override protected void writeString(String string, List<TextPosition> textPositions) throws IOException { for (TextPosition text : textPositions) { System.out.println("String[" + text.getXDirAdj() + "," + text.getYDirAdj() + " fs=" + text.getFontSize() + " xscale=" + text.getXScale() + " height=" + text.getHeightDir() + " space=" + text.getWidthOfSpace() + " width=" + text.getWidthDirAdj() + "]" + text.getUnicode()); // in red: // show rectangles with the "height" (not a real height, but used for text extraction // heuristics, it is 1/2 of the bounding box height and starts at y=0) Rectangle2D.Float rect = new Rectangle2D.Float(text.getXDirAdj(), (text.getYDirAdj() - text.getHeightDir()), text.getWidthDirAdj(), text.getHeightDir()); g2d.setColor(Color.red); g2d.draw(rect); // in blue: // show rectangle with the real vertical bounds, based on the font bounding box y values // usually, the height is identical to what you see when marking text in Adobe Reader PDFont font = text.getFont(); BoundingBox bbox = font.getBoundingBox(); // advance width, bbox height (glyph space) float xadvance = font.getWidth(text.getCharacterCodes()[0]); // todo: should iterate all chars rect = new Rectangle2D.Float(0, bbox.getLowerLeftY(), xadvance, bbox.getHeight()); // glyph space -> user space // note: text.getTextMatrix() is *not* the Text Matrix, it's the Text Rendering Matrix AffineTransform at = text.getTextMatrix().createAffineTransform(); if (font instanceof PDType3Font) { // bbox and font matrix are unscaled at.concatenate(font.getFontMatrix().createAffineTransform()); } else { // bbox and font matrix are already scaled to 1000 at.scale(1 / 1000f, 1 / 1000f); } Shape s = at.createTransformedShape(rect); s = flipAT.createTransformedShape(s); s = rotateAT.createTransformedShape(s); g2d.setColor(Color.blue); g2d.draw(s); } }
From source file:edu.ist.psu.sagnik.research.pdfbox2playground.javatest.DrawPrintTextLocations.java
License:Apache License
/** * Override the default functionality of PDFTextStripper. *///from www .j a v a 2 s.co m @Override protected void writeString(String string, List<TextPosition> textPositions) throws IOException { for (TextPosition text : textPositions) { System.out.println("String[" + text.getXDirAdj() + "," + text.getYDirAdj() + " fs=" + text.getFontSize() + " xscale=" + text.getXScale() + " height=" + text.getHeightDir() + " space=" + text.getWidthOfSpace() + " width=" + text.getWidthDirAdj() + "]" + text.getUnicode()); // in red: // show rectangles with the "height" (not a real height, but used for text extraction // heuristics, it is 1/2 of the bounding box height and starts at y=0) Rectangle2D.Float rect = new Rectangle2D.Float(text.getXDirAdj(), (text.getYDirAdj() - text.getHeightDir()), text.getWidthDirAdj(), text.getHeightDir()); g2d.setColor(Color.red); g2d.draw(rect); // in blue: // show rectangle with the real vertical bounds, based on the font bounding box y values // usually, the height is identical to what you see when marking text in Adobe Reader PDFont font = text.getFont(); BoundingBox bbox = font.getBoundingBox(); // advance width, bbox height (glyph space) float xadvance = font.getWidth(text.getCharacterCodes()[0]); // todo: should iterate all chars rect = new Rectangle2D.Float(0, bbox.getLowerLeftY(), xadvance, bbox.getHeight()); // glyph space -> user space // note: text.getTextMatrix() is *not* the Text Matrix, it's the Text Rendering Matrix AffineTransform at = text.getTextMatrix().createAffineTransform(); if (font instanceof PDType3Font) { // bbox and font matrix are unscaled at.concatenate(font.getFontMatrix().createAffineTransform()); } else { // bbox and font matrix are already scaled to 1000 at.scale(1 / 1000f, 1 / 1000f); } Shape s = at.createTransformedShape(rect); s = flipAT.createTransformedShape(s); s = rotateAT.createTransformedShape(s); g2d.setColor(Color.blue); g2d.draw(s); } }
From source file:uk.org.openeyes.PDFFunctions.java
/** * Override the default functionality of PDFTextStripper. * @param string//from w w w . j av a 2 s.c o m * @param textPositions * @throws java.io.IOException */ @Override protected void writeString(String string, List<TextPosition> textPositions) throws IOException { for (TextPosition text : textPositions) { System.out.println((char) 27 + "[0m String[" + text.getXDirAdj() + "," + text.getYDirAdj() + " fs=" + text.getFontSize() + " xscale=" + text.getXScale() + " height=" + text.getHeightDir() + " space=" + text.getWidthOfSpace() + " width=" + text.getWidthDirAdj() + "] " + (char) 27 + "[34;43m \t" + text.getUnicode() + " "); } }