Example usage for org.apache.pdfbox.text TextPosition toString

List of usage examples for org.apache.pdfbox.text TextPosition toString

Introduction

In this page you can find the example usage for org.apache.pdfbox.text TextPosition toString.

Prototype

@Override
public String toString() 

Source Link

Document

Show the string data for this text position.

Usage

From source file:at.knowcenter.wag.egov.egiz.pdfbox2.pdf.PDFPage.java

License:EUPL

/**
 * A method provided as an event interface to allow a subclass to perform
 * some specific functionality when a character needs to be displayed. This
 * method is used to calculate the latest position of a text in the page.
 * Sorry for this missinterpretation of the method, but it is the only way
 * to do this (provided by PDFBox)!!!/*  ww w .j  a  va2  s  .  c  o  m*/
 * 
 * @param text
 *            the character to be displayed -> calculate there y position.
 */
protected void showCharacter(TextPosition text) {
    float current_y = text.getY();
    final String character = text.toString();

    if (at.gv.egiz.pdfas.common.utils.StringUtils.whiteSpaceTrim(character).isEmpty()) {
        return;
    }

    int pageRotation = this.getCurrentPage().getRotation();
    // logger_.debug("PageRotation = " + pageRotation);
    /*if (pageRotation == 0) {
       current_y = text.getY();
    }
    if (pageRotation == 90) {
       current_y = text.getY();
    }
    if (pageRotation == 180) {
       current_y = text.getY();
    }
    if (pageRotation == 270) {
       current_y = text.getY();
    }
            
    if (current_y > this.effectivePageHeight) {
       this.max_character_ypos = this.effectivePageHeight;
       return;
    }
            
    // store ypos of the char if it is not empty
    if (current_y > this.max_character_ypos) {
       this.max_character_ypos = current_y;
    }*/

    if (pageRotation == 0) {
        current_y = text.getY();
    }
    if (pageRotation == 90) {
        current_y = text.getX();
    }
    if (pageRotation == 180) {
        float page_height = this.getCurrentPage().getMediaBox().getHeight();
        current_y = page_height - text.getY();
    }
    if (pageRotation == 270) {
        float page_height = this.getCurrentPage().getMediaBox().getHeight();
        current_y = page_height - text.getX();
    }

    if (current_y > this.effectivePageHeight) {
        // logger_.debug("character is below footer_line. footer_line = " +
        // this.footer_line + ", text.character=" + character + ", y=" +
        // current_y);
        return;
    }

    // store ypos of the char if it is not empty
    if (current_y > this.max_character_ypos) {
        this.max_character_ypos = current_y;
    }
}

From source file:org.apache.tika.parser.pdf.EnhancedPDF2XHTML.java

License:Apache License

@Override
protected void writeCharacters(TextPosition text) throws IOException {
    try {/* www  .jav a  2  s .  c o m*/
        handler.characters(text.toString());
    } catch (SAXException e) {
        throw new IOExceptionWithCause("Unable to write a character: " + text.toString(), e);
    }
}