diff --git a/doc-src/api.md b/doc-src/api.md index f7a4dd4..a097fa0 100644 --- a/doc-src/api.md +++ b/doc-src/api.md @@ -58,7 +58,8 @@ All layout items extend the `LTItem` class. There are two kinds of layout items: All of these classes extend the LTContainer class. - LTXObject: a layout item containing other additional layout items -- LTCharBlock: a layout item containing LTChars +- LTCharBlock: a layout item containing LTChars, this corresponds to whenever a `TJ` or `Tj` operators is issued within a text object. +- LTTextBlock: a layout item containing LTCharBlocks, note that this directly corresponds to the `BT` and `ET` operators pair in the pdf standard #### Layout Components All of these classes extend the LTComponent class. diff --git a/docs/api/index.html b/docs/api/index.html index 8f61b37..4f328fc 100644 --- a/docs/api/index.html +++ b/docs/api/index.html @@ -62,14 +62,14 @@ @@ -111,37 +111,82 @@

API

The library is constructed from 4 base modules:

+

parser

+

WIP

interpreter

-
WIP
-
-

converters

-

Contains high-level classes for conversion of the fundamental pdf structures to other formats. This library includes 4 high-level conversion classes:

- -

These classes all extend the PDFConverter. To use them simply call the static method parse_file.

+

a interpreter of the pdf-standard commands

Example

-
from pdfmajor.converters import HTMLConverter
+
from pdfmajor.interpreter import PageInterpreter
 
-input_file = open('path/to/input/file.pdf', 'rb')
-output_file = open('path/to/output/file.html', 'wb')
-HTMLConverter.parse_file(
-    input_file,
-    output_file
-)
-input_file.close()
-output_file.close()
+for page in PDFInterpreter("/path/to/pdf.pdf"):
+    print("page start", page.page_num)
+    for item in page:
+        print(" >", item)
+    print("page end", page.page_num)
 
-

converters.convert_file(input_file, output_file, image_folder_path, codec, maxpages, password, caching, check_extractable, pagenos, out_type)

+

interpreter.PDFInterpreter

+

This generator-function yields individual pages which contain their respected items.

+

Arguments

+ +

Yield Value

+

This function returns a generator that yields PDFInterpreter.

+

interpreter.PageInterpreter

+

This generator-function-class yields individual layout items.

+

Layout Items

+

All layout items extend the LTItem class. There are two kinds of layout items:

+ +

Layout Containers

+

All of these classes extend the LTContainer class.

+ +

Layout Components

+

All of these classes extend the LTComponent class.

+ +

converters

+

Contains high-level functions for conversion of the fundamental pdf structures to other formats. This library includes 4 high-level conversion cases:

+ +

These formats are all generated using the PageInterpreter. To use them simply call the static method parse_file.

+

Example

+
from pdfmajor.converters import convert_file
+
+convert_file(
+    "path/to/input/file.pdf",
+    "path/to/output/file.html",
+    out_type="html"
+)
+
+ +

converters.convert_file

A high-level abstraction for the conversion classes.

-

Example (converters.convert_file)

-
from pdfmajor.converters import convert_file
-
-input_file = open('path/to/input/file.pdf', 'rb')
-output_file = open('path/to/output/file.html', 'wb')
-convert_file(
-    input_file,
-    output_file
-)
-input_file.close()
-output_file.close()
-
- -

converters.PDFConverter

-

Extends layouts.PDFLayoutAnalyzer.

-

converters.PDFConverter.__init__(rsrcmgr, outfp, imagewriter, codec, pageno)

- -

initialization function for the class

-

converters.PDFConverter.parse_file(input_file, output_file, image_folder_path, codec, maxpages, password, caching, check_extractable, pagenos)

-

returns the output file TextIOWrapper.

-

imagewriter

-

WIP

-

layouts

WIP

diff --git a/docs/index.html b/docs/index.html index 66def72..dcd1842 100644 --- a/docs/index.html +++ b/docs/index.html @@ -59,6 +59,8 @@
  • Documentation
  • +
  • Basic Example
  • +
  • Why Another Fork?
  • Features
  • @@ -122,23 +124,34 @@ -

    PDF-Major is a fork of PDFMiner.six. It is meant to be a more light-weight implementation that makes fewer assumptions on the data. Additionally, this version intends to be more up to date with recent versions of python and make liberal use of the typing capabilities of python for improved future maintainability.

    +

    PDF-Major is a fork of PDFMiner.six. It is meant to be a more light-weight implementation that makes fewer assumptions on the data. The ultimate goal of this project is to provide a simpler, faster and more functional library that both casual and low-level developers could build upon.

    Documentation

    See documentation here.

    +

    Basic Example

    +
    from pdfmajor.interpreter import PageInterpreter
    +
    +for page in PDFInterpreter("/path/to/pdf.pdf"):
    +    print("page start", page.page_num)
    +    for item in page:
    +        print(" >", item)
    +    print("page end", page.page_num)
    +
    +
    +

    Why Another Fork?

    -

    PDFMiner was designed to run in python 2.7>, PDFMiner.six was written to bring cross-version support for python 2 and 3. This versions intends to make use of the latest improvement in the python language while remaining fairly simple to develop with.

    +

    PDFMiner was designed to run in python 2.7>, PDFMiner.six was written to bring cross-version support for python 2 and 3. However, after attempting to build and extend upon PDFMiner.six I found it rather difficult to extend and identify additional details regarding the items encoded in the pdf. This library will attempt to expose as much information as possible to end-users, without having them solely rely on to-xml or to-json exports.

    Features

    -

    Note: We took out the layout-analysis process in this version (there is no more LTTextHorizontal or LTTextVertical). While the mathematics behind the grouping process was sound, the coupling of the layout-analysis process with the parsing and interpretation process produced unfriendly-code. This feature could be brought back by extending the pdfmajor.layouts.PDFLayoutAnalyzer class, but at the current time is not supported.

    +

    Note: We took out the layout-analysis process in this version (there is no more LTTextHorizontal or LTTextVertical). While the mathematics behind the grouping process was sound, the coupling of the layout-analysis process with the parsing and interpretation process produced unfriendly-code. This feature could be brought back by running your own implementation of it on the pdfmajor.interpreter.PageInterpreter class, but at the current time is not supported.

    How to Install

    Source