// Path: src/main/java/at/tugraz/kti/pdftable/extract/CharInfo.java
// public class CharInfo implements Comparable<CharInfo> {
// 	public String c;
// 	public float x;
// 	public float y;
// 	public float xscale;
// 	public float yscale;
// 	public float w;
// 	public float h;
// 
// 	public CharInfo(String c, float x, float y) {
// 		this.x = x;
// 		this.y = y;
// 		this.c = c;
// 	}
// 
// 	public int compareTo(CharInfo o) {
// 		if (y < o.y)
// 			return -1;
// 		if (y == o.y)
// 			return 0;
// 		return 1;
// 	}
// 
// 	public String toString() {
// 		return c + " at " + "(" + x + "," + y + ")" + ",(" + w + "," + h + ")"
// 				+ xscale;
// 	}
// }
// 
// Path: src/main/java/at/tugraz/kti/pdftable/extract/ParsePdf.java
// public class ParsePdf extends PDFTextStripper {
// 
// 	PDDocument document = null;
// 
// 	protected ArrayList<CharInfo> collect_chars_info;
// 	
// 	/**
// 	 * store size / dimensions for every page
// 	 */
// 	protected ArrayList<PDRectangle> pagesizes;
// 	
// 	/**
// 	 * store character info per page
// 	 */
// 	protected ArrayList<ArrayList<CharInfo>> allchars = new ArrayList<ArrayList<CharInfo>>();
// 
// 	/**
// 	 * Default constructor.
// 	 * @throws IOException
// 	 *             If there is an error loading text stripper properties.
// 	 */
// 	public ParsePdf(String filename) throws IOException {
// 		super.setSortByPosition(true);
// 		document = PDDocument.load(filename);
// 	}
// 
// 	/**
// 	 * read character information , pagesizes
// 	 * of all annotationsOnPage of the document
// 	 * 
// 	 * @throws Exception
// 	 */
// 	public void parse() throws Exception {
// 		
// 		allchars = new ArrayList<ArrayList<CharInfo>>();
// 		pagesizes = new ArrayList<PDRectangle>();
// 
// 		try {
// 			List allPages = document.getDocumentCatalog().getAllPages();
// 			for (int i = 0; i < allPages.size(); i++) {
// 				allchars.add(new ArrayList<CharInfo>());
// 				collect_chars_info = allchars.get(i);
// 				PDPage page = (PDPage) allPages.get(i);
// 				pagesizes.add(page.findMediaBox());
// 				PDStream contents = page.getContents();
// 				if (contents != null) {
// 					processStream(page, page.findResources(), page
// 							.getContents().getStream());
// 				}
// 			}
// 		} catch (IOException e1) {
// 			e1.printStackTrace();
// 		} finally {
// 			if (document != null) {
// 				document.close();
// 			}
// 		}		
// 	}
// 
// 	public ArrayList<ArrayList<CharInfo>> getCharacterInfo() {
// 		return allchars;
// 	}
// 	
// 	public ArrayList<PDRectangle> getPageDimensions() {
// 		return pagesizes;
// 	}
// 
// 	/**
// 	 * A method provided as an event interface to allow a subclass to perform
// 	 * some specific functionality when text needs to be processed.
// 	 * 
// 	 * @param text
// 	 *            The text to be processed
// 	 */
// 	protected void processTextPosition(TextPosition text) {
// 		CharInfo c = new CharInfo(text.getCharacter(), text.getXDirAdj(),
// 				text.getYDirAdj());
// 		c.xscale = text.getXScale();
// 		c.yscale = text.getYScale();
// 		c.w = text.getWidthDirAdj();
// 		c.h = text.getHeightDir();
// 
// 		// text.getFontSize()
// 		// text.getWidthOfSpace()
// 
// 		collect_chars_info.add(c);
// 	}
// 
// }


import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import at.tugraz.kti.pdftable.extract.CharInfo;
import at.tugraz.kti.pdftable.extract.ParsePdf;
package at.tugraz.kti.pdftable.document;




/**
 * Represents a PDF-document
 * Represents a PDF-document or the parts useful for and created through 
 * parsing, extracting manual annotation, and similar. 
 * 
 * Stores:
 * 	- single character info (per page with position and size)
 *  - table annotations
 * 
 * @author "matthias frey"
 *
 */
public class RichDocument {

	protected String sourcePath;
	protected String title = "";
	public ArrayList<ArrayList<CharInfo>> charactersOnPage;
	public ArrayList<PDRectangle> pages_dimensions;
	protected int active_page;
	
	protected DocumentTables tableAnnotations;
	
	public RichDocument(String path) {
		this.sourcePath = path;
		charactersOnPage = new ArrayList<ArrayList<CharInfo>>();
		active_page = 0;
	}
	
	public String getFilename() {
		File f = new File(sourcePath);
		return f.getName();
	}
	
	public File getSourcePath() {
		return new File(sourcePath);
	}
	
	public int getNumberOfPages() {
		return charactersOnPage.size();
	}
	
	public RichDocument setActivePage(int p) throws Exception {
		if (p >= getNumberOfPages()) throw new Exception("page exceeds document length");
		active_page = p;
		return this;
	}
	
	public void open() throws IOException {
// Path: src/main/java/at/tugraz/kti/pdftable/extract/CharInfo.java
// public class CharInfo implements Comparable<CharInfo> {
// 	public String c;
// 	public float x;
// 	public float y;
// 	public float xscale;
// 	public float yscale;
// 	public float w;
// 	public float h;
// 
// 	public CharInfo(String c, float x, float y) {
// 		this.x = x;
// 		this.y = y;
// 		this.c = c;
// 	}
// 
// 	public int compareTo(CharInfo o) {
// 		if (y < o.y)
// 			return -1;
// 		if (y == o.y)
// 			return 0;
// 		return 1;
// 	}
// 
// 	public String toString() {
// 		return c + " at " + "(" + x + "," + y + ")" + ",(" + w + "," + h + ")"
// 				+ xscale;
// 	}
// }
// 
// Path: src/main/java/at/tugraz/kti/pdftable/extract/ParsePdf.java
// public class ParsePdf extends PDFTextStripper {
// 
// 	PDDocument document = null;
// 
// 	protected ArrayList<CharInfo> collect_chars_info;
// 	
// 	/**
// 	 * store size / dimensions for every page
// 	 */
// 	protected ArrayList<PDRectangle> pagesizes;
// 	
// 	/**
// 	 * store character info per page
// 	 */
// 	protected ArrayList<ArrayList<CharInfo>> allchars = new ArrayList<ArrayList<CharInfo>>();
// 
// 	/**
// 	 * Default constructor.
// 	 * @throws IOException
// 	 *             If there is an error loading text stripper properties.
// 	 */
// 	public ParsePdf(String filename) throws IOException {
// 		super.setSortByPosition(true);
// 		document = PDDocument.load(filename);
// 	}
// 
// 	/**
// 	 * read character information , pagesizes
// 	 * of all annotationsOnPage of the document
// 	 * 
// 	 * @throws Exception
// 	 */
// 	public void parse() throws Exception {
// 		
// 		allchars = new ArrayList<ArrayList<CharInfo>>();
// 		pagesizes = new ArrayList<PDRectangle>();
// 
// 		try {
// 			List allPages = document.getDocumentCatalog().getAllPages();
// 			for (int i = 0; i < allPages.size(); i++) {
// 				allchars.add(new ArrayList<CharInfo>());
// 				collect_chars_info = allchars.get(i);
// 				PDPage page = (PDPage) allPages.get(i);
// 				pagesizes.add(page.findMediaBox());
// 				PDStream contents = page.getContents();
// 				if (contents != null) {
// 					processStream(page, page.findResources(), page
// 							.getContents().getStream());
// 				}
// 			}
// 		} catch (IOException e1) {
// 			e1.printStackTrace();
// 		} finally {
// 			if (document != null) {
// 				document.close();
// 			}
// 		}		
// 	}
// 
// 	public ArrayList<ArrayList<CharInfo>> getCharacterInfo() {
// 		return allchars;
// 	}
// 	
// 	public ArrayList<PDRectangle> getPageDimensions() {
// 		return pagesizes;
// 	}
// 
// 	/**
// 	 * A method provided as an event interface to allow a subclass to perform
// 	 * some specific functionality when text needs to be processed.
// 	 * 
// 	 * @param text
// 	 *            The text to be processed
// 	 */
// 	protected void processTextPosition(TextPosition text) {
// 		CharInfo c = new CharInfo(text.getCharacter(), text.getXDirAdj(),
// 				text.getYDirAdj());
// 		c.xscale = text.getXScale();
// 		c.yscale = text.getYScale();
// 		c.w = text.getWidthDirAdj();
// 		c.h = text.getHeightDir();
// 
// 		// text.getFontSize()
// 		// text.getWidthOfSpace()
// 
// 		collect_chars_info.add(c);
// 	}
// 
// }


// Path: src/main/java/at/tugraz/kti/pdftable/document/RichDocument.java
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import at.tugraz.kti.pdftable.extract.CharInfo;
import at.tugraz.kti.pdftable.extract.ParsePdf;

package at.tugraz.kti.pdftable.document;




/**
 * Represents a PDF-document
 * Represents a PDF-document or the parts useful for and created through 
 * parsing, extracting manual annotation, and similar. 
 * 
 * Stores:
 * 	- single character info (per page with position and size)
 *  - table annotations
 * 
 * @author "matthias frey"
 *
 */
public class RichDocument {

	protected String sourcePath;
	protected String title = "";
	public ArrayList<ArrayList<CharInfo>> charactersOnPage;
	public ArrayList<PDRectangle> pages_dimensions;
	protected int active_page;
	
	protected DocumentTables tableAnnotations;
	
	public RichDocument(String path) {
		this.sourcePath = path;
		charactersOnPage = new ArrayList<ArrayList<CharInfo>>();
		active_page = 0;
	}
	
	public String getFilename() {
		File f = new File(sourcePath);
		return f.getName();
	}
	
	public File getSourcePath() {
		return new File(sourcePath);
	}
	
	public int getNumberOfPages() {
		return charactersOnPage.size();
	}
	
	public RichDocument setActivePage(int p) throws Exception {
		if (p >= getNumberOfPages()) throw new Exception("page exceeds document length");
		active_page = p;
		return this;
	}
	
	public void open() throws IOException {
		ParsePdf textstripper 	= new ParsePdf(sourcePath);