public CharSegment(TextPosition tPos) { super(tPos.getX(), tPos.getX() + (tPos.getWidth()), tPos.getY(), tPos.getY() + (tPos.getFontSize() * tPos.getYScale()), tPos.getCharacter(), findFontName(tPos.getFont()), tPos.getFontSize() * tPos.getYScale()); // todo: trim the name of the font String fontName = tPos.getFont().getBaseFont(); }
w.setX(t.getX()); w.setY(t.getY()); if (t.getFontSize() < 0.3 && t.getYScale() <= 1.0) { w.setFontSize(t.getFontSize() * 100); w.setHeight(Math.max(t.getYScale(), t.getFontSize()) * 100); w.setXScale(t.getXScale()); w.setYScale(t.getYScale()); } else { if (t.getYScale() < 0.3 && t.getFontSize() <= 1.0) { w.setYScale(t.getYScale() * 100); w.setXScale(t.getXScale() * 100); w.setHeight(Math.max(t.getYScale() * 100, t.getFontSize())); } else { w.setFontSize(t.getFontSize()); w.setHeight(Math.max(t.getYScale(), t.getFontSize())); w.setXScale(t.getXScale()); w.setYScale(t.getYScale()); w.setWidth(Math.abs(t.getWidth())); w.setEndX(w.getX() + w.getWidth()); w.setWidthOfSpace(t.getWidthOfSpace()); w.setWordSpacing(t.getWordSpacing()); w.setText(t.getCharacter()); wordsOfThisPage.add(w);
/** * Processes text events. * * Stores characters in a buffer until a terminal symbol is found * (e.g. space), then treats the characters stored as a single word. * * @param text The text to be processed */ @Override protected void processTextPosition( TextPosition text ) { String chars = text.getCharacter(); // Some line breaks do not enter here, I ignore why if (TERMINALS.contains(chars)) { String word = charsBuffer.toString(); if (words.contains(word)) { addColor(charsBuffer.toString(), previousColor); } charsBuffer = new StringBuffer(); } else { charsBuffer.append(chars); previousText = text; try { previousColor = getGraphicsState().getNonStrokingColor().getJavaColor(); } catch (IOException e) { e.printStackTrace(); } } }
public TextFragment(TextPosition tPos) { super(tPos.getX(), tPos.getX() + (tPos.getWidth()), tPos.getY(), tPos.getY() + (tPos.getFontSize() * tPos.getYScale()), tPos.getCharacter(), findFontName(tPos.getFont()), tPos.getFontSize() * tPos.getYScale()); // todo: trim the name of the font String fontName = tPos.getFont().getBaseFont(); }
/** * This will create a TextFragment object from a TextPosition object. * As of PDFBox 0.7.2, this is the method currently in use, which * converts co-ordinates back to the original system. * * @param tPos - the TextPosition object; pageDim - page dimensions in order to * convert co-ordinates * @return The new TextFragment object */ public CharSegment(TextPosition tPos, GenericSegment pageDim) { super(tPos.getX(), tPos.getX() + tPos.getWidth(), pageDim.getY2() - tPos.getY(), pageDim.getY2() - tPos.getY() + (tPos.getFontSize() * tPos.getYScale()), tPos.getCharacter(), tPos.getFont().getBaseFont(), tPos.getFontSize() * tPos.getYScale()); // uncomment to print the contents of all text fragments to the screen // System.out.println("Created text fragment: x1: " + tPos.getX() + " x2: " + (tPos.getX() + tPos.getWidth()) + " y1: " + tPos.getY() + " y2: " + (tPos.getY() + (tPos.getFontSize() * tPos.getYScale())) + " Text: " + text + " Font size: " + tPos.getFontSize() + " X Scale: " + tPos.getYScale() + " Y Scale: " + tPos.getYScale()); // todo: trim the name of the font String fontName = tPos.getFont().getBaseFont(); /* this.xScale = tPos.getXScale(); this.yScale = tPos.getYScale(); this.widthOfSpace = tPos.getWidthOfSpace(); this.wordSpacing = tPos.getWordSpacing(); */ }
/** * This will create a TextFragment object from a TextPosition object. * As of PDFBox 0.7.2, this is the method currently in use, which * converts co-ordinates back to the original system. * * @param tPos - the TextPosition object; pageDim - page dimensions in order to * convert co-ordinates * @return The new TextFragment object */ public TextFragment(TextPosition tPos, GenericSegment pageDim) { super(tPos.getX(), tPos.getX() + tPos.getWidth(), pageDim.getY2() - tPos.getY(), pageDim.getY2() - tPos.getY() + (tPos.getFontSize() * tPos.getYScale()), tPos.getCharacter(), tPos.getFont().getBaseFont(), tPos.getFontSize() * tPos.getYScale()); // uncomment to print the contents of all text fragments to the screen // System.out.println("Created text fragment: x1: " + tPos.getX() + " x2: " + (tPos.getX() + tPos.getWidth()) + " y1: " + tPos.getY() + " y2: " + (tPos.getY() + (tPos.getFontSize() * tPos.getYScale())) + " Text: " + text + " Font size: " + tPos.getFontSize() + " X Scale: " + tPos.getYScale() + " Y Scale: " + tPos.getYScale()); // todo: trim the name of the font String fontName = tPos.getFont().getBaseFont(); /* this.xScale = tPos.getXScale(); this.yScale = tPos.getYScale(); this.widthOfSpace = tPos.getWidthOfSpace(); this.wordSpacing = tPos.getWordSpacing(); */ }