Java Code Examples for org.apache.pdfbox.text.TextPosition#getX()

The following examples show how to use org.apache.pdfbox.text.TextPosition#getX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PDFLayoutTextStripper.java    From quarkus-pdf-extract with Apache License 2.0 5 votes vote down vote up
public Character createCharacterFromTextPosition(final TextPosition textPosition, final TextPosition previousTextPosition) {
    this.setPreviousTextPosition(previousTextPosition);
    this.isCharacterPartOfPreviousWord = this.isCharacterPartOfPreviousWord(textPosition);
    this.isFirstCharacterOfAWord = this.isFirstCharacterOfAWord(textPosition);
    this.isCharacterAtTheBeginningOfNewLine = this.isCharacterAtTheBeginningOfNewLine(textPosition);
    this.isCharacterCloseToPreviousWord = this.isCharacterCloseToPreviousWord(textPosition);
    char character = this.getCharacterFromTextPosition(textPosition);
    int index = (int)textPosition.getX() / PDFLayoutTextStripper.OUTPUT_SPACE_CHARACTER_WIDTH_IN_PT;
    return new Character(character,
                         index,
                         isCharacterPartOfPreviousWord,
                         isFirstCharacterOfAWord,
                         isCharacterAtTheBeginningOfNewLine,
                         isCharacterCloseToPreviousWord);
}
 
Example 2
Source File: PDFLayoutTextStripper.java    From quarkus-pdf-extract with Apache License 2.0 5 votes vote down vote up
private double numberOfSpacesBetweenTwoCharacters(final TextPosition textPosition1, final TextPosition textPosition2) {
    double previousTextXPosition = textPosition1.getX();
    double previousTextWidth = textPosition1.getWidth();
    double previousTextEndXPosition = (previousTextXPosition + previousTextWidth);
    double numberOfSpaces = Math.abs(Math.round(textPosition2.getX() - previousTextEndXPosition));
    return numberOfSpaces;
}
 
Example 3
Source File: TextParser.java    From tephra with MIT License 5 votes vote down vote up
@Override
protected void processTextPosition(TextPosition textPosition) {
    super.processTextPosition(textPosition);

    if (prevTextPosition == null || prevTextPosition.getEndY() != textPosition.getEndY()
            || prevTextPosition.getFontSizeInPt() != textPosition.getFontSizeInPt()
            || prevTextPosition.getEndX() + prevTextPosition.getWidth() < textPosition.getX())
        addLine();
    addWord(textPosition);
    prevTextPosition = textPosition;
}
 
Example 4
Source File: PDFLayoutTextStripper.java    From PDFLayoutTextStripper with Apache License 2.0 5 votes vote down vote up
public Character createCharacterFromTextPosition(final TextPosition textPosition, final TextPosition previousTextPosition) {
    this.setPreviousTextPosition(previousTextPosition);
    this.isCharacterPartOfPreviousWord = this.isCharacterPartOfPreviousWord(textPosition);
    this.isFirstCharacterOfAWord = this.isFirstCharacterOfAWord(textPosition);
    this.isCharacterAtTheBeginningOfNewLine = this.isCharacterAtTheBeginningOfNewLine(textPosition);
    this.isCharacterCloseToPreviousWord = this.isCharacterCloseToPreviousWord(textPosition);
    char character = this.getCharacterFromTextPosition(textPosition);
    int index = (int)textPosition.getX() / PDFLayoutTextStripper.OUTPUT_SPACE_CHARACTER_WIDTH_IN_PT;
    return new Character(character,
                         index,
                         isCharacterPartOfPreviousWord,
                         isFirstCharacterOfAWord,
                         isCharacterAtTheBeginningOfNewLine,
                         isCharacterCloseToPreviousWord);
}
 
Example 5
Source File: PDFLayoutTextStripper.java    From PDFLayoutTextStripper with Apache License 2.0 5 votes vote down vote up
private double numberOfSpacesBetweenTwoCharacters(final TextPosition textPosition1, final TextPosition textPosition2) {
    double previousTextXPosition = textPosition1.getX();
    double previousTextWidth = textPosition1.getWidth();
    double previousTextEndXPosition = (previousTextXPosition + previousTextWidth);
    double numberOfSpaces = Math.abs(Math.round(textPosition2.getX() - previousTextEndXPosition));
    return numberOfSpaces;
}
 
Example 6
Source File: TextMetrics.java    From Pdf2Dom with GNU Lesser General Public License v3.0 5 votes vote down vote up
public TextMetrics(TextPosition tp)
{
    x = tp.getX();
    baseline = tp.getY();
    font = tp.getFont();
    width = tp.getWidth();
    height = tp.getHeight();
    pointSize = tp.getFontSizeInPt();
    fontSize = tp.getYScale();
    ascent = getAscent();
    descent = getDescent();
}
 
Example 7
Source File: TextMetrics.java    From Pdf2Dom with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void append(TextPosition tp)
{
    width += tp.getX() - (x + width) + tp.getWidth();
    height = Math.max(height, tp.getHeight());
    ascent = Math.max(ascent, getAscent(tp.getFont(), tp.getYScale()));
    descent = Math.min(descent, getDescent(tp.getFont(), tp.getYScale()));
}
 
Example 8
Source File: PDFBoxTree.java    From Pdf2Dom with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void processTextPosition(TextPosition text)
{
    if (text.isDiacritic())
    {
        lastDia = text;
    }
    else if (!text.getUnicode().trim().isEmpty())
    {
        if (lastDia != null)
        {
            if (text.contains(lastDia))
                text.mergeDiacritic(lastDia);
            lastDia = null;
        }
        
        /*float[] c = transformPosition(text.getX(), text.getY());
        cur_x = c[0];
        cur_y = c[1];*/
        cur_x = text.getX();
        cur_y = text.getY();

        /*System.out.println("Text: " + text.getCharacter());
        System.out.println(" Font size: " + text.getFontSize() + " " + text.getFontSizeInPt() + "pt");
        System.out.println(" Width: " + text.getWidth());
        System.out.println(" Width adj: " + text.getWidthDirAdj());
        System.out.println(" Height: " + text.getHeight());
        System.out.println(" Height dir: " + text.getHeightDir());
        System.out.println(" XScale: " + text.getXScale());
        System.out.println(" YScale: " + text.getYScale());*/

        float distx = 0;
        float disty = 0;
        if (lastText != null)
        {
            distx = text.getX() - (lastText.getX() + lastText.getWidth());
            disty = text.getY() - lastText.getY();
        }

        //should we split the boxes?
        boolean split = lastText == null || distx > 1.0f || distx < -6.0f || Math.abs(disty) > 1.0f
                            || isReversed(getTextDirectionality(text)) != isReversed(getTextDirectionality(lastText));
        //if the style changed, we should split the boxes
        updateStyle(style, text);
        if (!style.equals(curstyle))
        	split = true;

        if (split) //start of a new box
        {
        	//finish current box (if any)
        	if (lastText != null)
        	{
        		finishBox();
        	}
            //start a new box
         curstyle = new BoxStyle(style);
        }
        textLine.append(text.getUnicode());
        if (textMetrics == null)
            textMetrics = new TextMetrics(text);
        else
            textMetrics.append(text);
        lastText = text;
    }
}