251 lines
9.5 KiB
HTML
251 lines
9.5 KiB
HTML
<!DOCTYPE html>
|
|
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
|
|
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
|
<link rel="shortcut icon" href="../img/favicon.ico">
|
|
<title>API - PDF Major</title>
|
|
<link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>
|
|
|
|
<link rel="stylesheet" href="../css/theme.css" type="text/css" />
|
|
<link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
|
|
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
|
|
|
|
<script>
|
|
// Current page data
|
|
var mkdocs_page_name = "API";
|
|
var mkdocs_page_input_path = "api.md";
|
|
var mkdocs_page_url = null;
|
|
</script>
|
|
|
|
<script src="../js/jquery-2.1.1.min.js" defer></script>
|
|
<script src="../js/modernizr-2.8.3.min.js" defer></script>
|
|
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
|
|
<script>hljs.initHighlightingOnLoad();</script>
|
|
|
|
</head>
|
|
|
|
<body class="wy-body-for-nav" role="document">
|
|
|
|
<div class="wy-grid-for-nav">
|
|
|
|
|
|
<nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
|
|
<div class="wy-side-nav-search">
|
|
<a href=".." class="icon icon-home"> PDF Major</a>
|
|
<div role="search">
|
|
<form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
|
|
<input type="text" name="q" placeholder="Search docs" title="Type search term here" />
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
|
<ul class="current">
|
|
|
|
|
|
<li class="toctree-l1">
|
|
|
|
<a class="" href="..">Home</a>
|
|
</li>
|
|
|
|
<li class="toctree-l1 current">
|
|
|
|
<a class="current" href="./">API</a>
|
|
<ul class="subnav">
|
|
|
|
<li class="toctree-l2"><a href="#api">API</a></li>
|
|
|
|
<ul>
|
|
|
|
<li><a class="toctree-l3" href="#parser">parser</a></li>
|
|
|
|
<li><a class="toctree-l3" href="#interpreter">interpreter</a></li>
|
|
|
|
<li><a class="toctree-l3" href="#converters">converters</a></li>
|
|
|
|
<li><a class="toctree-l3" href="#imagewriter">imagewriter</a></li>
|
|
|
|
</ul>
|
|
|
|
|
|
</ul>
|
|
</li>
|
|
|
|
</ul>
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
|
|
|
|
|
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
|
|
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
|
<a href="..">PDF Major</a>
|
|
</nav>
|
|
|
|
|
|
<div class="wy-nav-content">
|
|
<div class="rst-content">
|
|
<div role="navigation" aria-label="breadcrumbs navigation">
|
|
<ul class="wy-breadcrumbs">
|
|
<li><a href="..">Docs</a> »</li>
|
|
|
|
|
|
|
|
<li>API</li>
|
|
<li class="wy-breadcrumbs-aside">
|
|
|
|
</li>
|
|
</ul>
|
|
<hr/>
|
|
</div>
|
|
<div role="main">
|
|
<div class="section">
|
|
|
|
<h1 id="api">API</h1>
|
|
<p>The library is constructed from 4 base modules:</p>
|
|
<ul>
|
|
<li><strong>parser</strong>: contains low-level classes for extracting fundamental data-structures from the documents</li>
|
|
<li><strong>interpreter</strong>: a interpreter of the pdf-standard commands</li>
|
|
<li><strong>converters</strong>: contains high-level functions for conversion of the fundamental pdf structures to other formats</li>
|
|
<li><strong>imagewriter</strong>: contains a simple implementation for converting PDF Image Streams to png/bmp/img formats</li>
|
|
</ul>
|
|
<h2 id="parser">parser</h2>
|
|
<p>WIP</p>
|
|
<h2 id="interpreter">interpreter</h2>
|
|
<p>a interpreter of the pdf-standard commands</p>
|
|
<h3 id="example">Example</h3>
|
|
<pre><code class="py">from pdfmajor.interpreter import PDFInterpreter
|
|
|
|
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)
|
|
</code></pre>
|
|
|
|
<h3 id="interpreterpdfinterpreter">interpreter.PDFInterpreter</h3>
|
|
<p>This generator-function yields individual pages which contain their respected items.</p>
|
|
<h4 id="arguments">Arguments</h4>
|
|
<ul>
|
|
<li><code>input_file_path</code>: <a href="#">str</a></li>
|
|
<li><code>preload</code>: <a href="#">bool</a> defaults to False</li>
|
|
<li><code>maxpages</code>: <a href="#">int</a> defaults to 0 </li>
|
|
<li><code>password</code>: <a href="#">str</a> defaults to None </li>
|
|
<li><code>caching</code>: <a href="#">bool</a> defaults to True </li>
|
|
<li><code>check_extractable</code>: <a href="#">bool</a> defaults to True</li>
|
|
<li><code>ignore_bad_chars</code>: <a href="#">bool</a> defaults to False</li>
|
|
<li><code>pagenos</code>: <a href="#">List[int]</a> defaults to None</li>
|
|
<li><code>debug_level</code>: <a href="#https://docs.python.org/3/library/logging.html#levels">logging.levels</a> defaults logging.WARNING</li>
|
|
</ul>
|
|
<h4 id="yield-value">Yield Value</h4>
|
|
<p>This function returns a generator that yields <a href="#interpreterpageinterpreter">PDFInterpreter</a>.</p>
|
|
<h3 id="interpreterpageinterpreter">interpreter.PageInterpreter</h3>
|
|
<p>This generator-function-class yields individual <a href="#layout-items">layout items</a>.</p>
|
|
<h3 id="layout-items">Layout Items</h3>
|
|
<p>All layout items extend the <code>LTItem</code> class. There are two kinds of layout items:</p>
|
|
<ul>
|
|
<li>LTComponent: extends the base <code>LTItem</code> class, this class will have additional values such as boundary boxes, height and width</li>
|
|
<li>LTContainer: extends the <code>LTComponent</code> class, this class is used to contain elements of the pdf that would have child elements. Iterating on this element will output its child elements.</li>
|
|
</ul>
|
|
<h4 id="layout-containers">Layout Containers</h4>
|
|
<p>All of these classes extend the LTContainer class.</p>
|
|
<ul>
|
|
<li>LTXObject: a layout item containing other additional layout items</li>
|
|
<li>LTCharBlock: a layout item containing LTChars, this corresponds to whenever a <code>TJ</code> or <code>Tj</code> operators is issued within a text object.</li>
|
|
<li>LTTextBlock: a layout item containing LTCharBlocks, note that this directly corresponds to the <code>BT</code> and <code>ET</code> operators pair in the pdf standard</li>
|
|
</ul>
|
|
<h4 id="layout-components">Layout Components</h4>
|
|
<p>All of these classes extend the LTComponent class.</p>
|
|
<ul>
|
|
<li>LTChar: an individual character</li>
|
|
<li>LTCurves: represents a collection of svg-paths (available under <code>self.paths</code>)</li>
|
|
<li>LTImage: a component containing information regarding an image</li>
|
|
</ul>
|
|
<h2 id="converters">converters</h2>
|
|
<p>Contains high-level functions for conversion of the fundamental pdf structures to other formats. This library includes 4 high-level conversion cases:</p>
|
|
<ul>
|
|
<li>HTML</li>
|
|
<li>JSON</li>
|
|
<li>XML</li>
|
|
<li>Text</li>
|
|
</ul>
|
|
<p>These formats are all generated using the <a href="#PDFInterpreter">PageInterpreter</a>. To use them simply call the static method <a href="#converterspdfconverter">parse_file</a>.</p>
|
|
<h3 id="example_1">Example</h3>
|
|
<pre><code class="py">from pdfmajor.converters import convert_file
|
|
|
|
convert_file(
|
|
"path/to/input/file.pdf",
|
|
"path/to/output/file.html",
|
|
out_type="html"
|
|
)
|
|
</code></pre>
|
|
|
|
<h3 id="convertersconvert_file">converters.convert_file</h3>
|
|
<p>A high-level abstraction for the conversion classes.</p>
|
|
<ul>
|
|
<li><code>input_file</code>: <a href="https://docs.python.org/3/library/io.html#io.TextIOWrapper">TextIOWrapper</a> </li>
|
|
<li><code>output_file</code>: <a href="https://docs.python.org/3/library/io.html#io.TextIOWrapper">TextIOWrapper</a> </li>
|
|
<li><code>image_folder_path</code>: <a href="#">str</a> defaults to None</li>
|
|
<li><code>codec</code>: <a href="#">str</a> defaults to 'utf-8'</li>
|
|
<li><code>maxpages</code>: <a href="#">int</a> defaults to 0 </li>
|
|
<li><code>password</code>: <a href="#">str</a> defaults to None </li>
|
|
<li><code>caching</code>: <a href="#">bool</a> defaults to True </li>
|
|
<li><code>check_extractable</code>: <a href="#">bool</a> defaults to True</li>
|
|
<li><code>pagenos</code>: <a href="#">List[int]</a> defaults to None</li>
|
|
<li><code>out_type</code>: <a href="#">str</a> defaults to 'html'</li>
|
|
</ul>
|
|
<h2 id="imagewriter">imagewriter</h2>
|
|
<p>WIP </p>
|
|
|
|
</div>
|
|
</div>
|
|
<footer>
|
|
|
|
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
|
|
|
|
|
<a href=".." class="btn btn-neutral" title="Home"><span class="icon icon-circle-arrow-left"></span> Previous</a>
|
|
|
|
</div>
|
|
|
|
|
|
<hr/>
|
|
|
|
<div role="contentinfo">
|
|
<!-- Copyright etc -->
|
|
|
|
</div>
|
|
|
|
Built with <a href="http://www.mkdocs.org">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
|
</footer>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
<div class="rst-versions" role="note" style="cursor: pointer">
|
|
<span class="rst-current-version" data-toggle="rst-current-version">
|
|
|
|
|
|
<span><a href=".." style="color: #fcfcfc;">« Previous</a></span>
|
|
|
|
|
|
</span>
|
|
</div>
|
|
<script>var base_url = '..';</script>
|
|
<script src="../js/theme.js" defer></script>
|
|
<script src="../search/main.js" defer></script>
|
|
|
|
</body>
|
|
</html>
|