cleaner xml output

This commit is contained in:
ari committed 2018-10-19 08:19:33 -04:00
1 parent 1e89e2abba
commit 6655c3aec7
8 files changed
+32 -6078

No files matched your search

+1 -1
View File
@@ -75,7 +75,7 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
__version__ = (1, 0, 4)
__version__ = (1, 0, 6)
if __name__ == '__main__':
print(
+6 -1
View File
@@ -28,13 +28,17 @@ class PDFConverter(PDFLayoutAnalyzer):
caching: bool = True,
check_extractable: bool = True,
pagenos: List[int] = None,
dont_export_images: bool = False,
debug: bool = False,
) -> TextIOWrapper:
if debug:
log.setLevel(logging.DEBUG)
if image_folder_path is None:
if dont_export_images:
image_folder_path = None
if not dont_export_images and image_folder_path is None and output_file.name is not None:
image_folder_path = os.path.dirname(output_file.name)
log.debug("Creating resources....")
@@ -50,6 +54,7 @@ class PDFConverter(PDFLayoutAnalyzer):
log.debug("Reading pages....")
pages = PDFPage.get_pages(input_file, pagenos=pagenos, maxpages=maxpages, password=password, caching=caching, check_extractable=check_extractable)
for idx, page in enumerate(pages):
log.debug(f"Reading page #{idx}")
interpreter.process_page(page)
device.close()
return output_file
+12 -7
View File
@@ -42,8 +42,8 @@ class XMLConverter(PDFConverter):
self.__levels_deep = 0
self.write_header()
def write(self, text: str):
text = " "*self.__levels_deep + text + '\n'
def write(self, text: str, lineend: str = '\n', deep_space: str = ' '):
text = deep_space*self.__levels_deep + text + lineend
self.write_raw(text)
def write_raw(self, text):
@@ -64,16 +64,21 @@ class XMLConverter(PDFConverter):
self.write('</pages>')
@contextmanager
def place_elm_with_child(self, tag_name: str, attr_dict: Dict[str, str] = {}):
def place_elm_with_child(self, tag_name: str, attr_dict: Dict[str, str] = {}, no_additional_char = False):
lineend = '\n'
deep_space = ' '
if no_additional_char:
lineend = ''
deep_space = ''
attrs = " ".join([
f'{name}="{value}"'
for name, value in attr_dict.items()
])
self.write(f"<{tag_name} {attrs}>")
self.write(f"<{tag_name} {attrs}>", lineend=lineend)
self.__levels_deep += 1
yield
self.__levels_deep -= 1
self.write(f"</{tag_name}>")
self.write(f"</{tag_name}>", deep_space=deep_space)
def place_elm_close(self, tag_name: str, attr_dict: Dict[str, str] = {}, as_childless = True):
attrs = " ".join([
@@ -117,8 +122,8 @@ class XMLConverter(PDFConverter):
"y1": char.y1,
"stroke-color": get_color(char.graphicstate.scolor),
"fill-color": get_color(char.graphicstate.ncolor),
}):
self.write(char.get_text())
}, no_additional_char=True):
self.write(char.get_text(), lineend='', deep_space="")
def render_curve(self, item: LTCurve):
attr = {
+12 -6
View File
@@ -60,13 +60,19 @@ class BMPWriter(object):
##
class ImageWriter(object):
def __init__(self, outdir: str):
self.outdir = outdir
if not os.path.exists(self.outdir):
os.makedirs(self.outdir)
return
def __init__(self, outdir: str = None):
if outdir is None:
self.inactive = True
else:
self.inactive = False
self.outdir = outdir
if not os.path.exists(self.outdir):
os.makedirs(self.outdir)
def export_image(self, image: LTImage):
def export_image(self, image: LTImage) -> str:
if self.inactive:
return "N/A"
stream = image.stream
filters = stream.get_filters()
(width, height) = image.srcsize
File diff suppressed because it is too large. Load diff
-76
View File
@@ -1,76 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
<style >
.page { position: relative; overflow: hidden;border: 1px black solid;}
</style>
</head>
<body>
<div class="page" style="width: 612px;height: 792px">
<div class="curve rect" style="position: absolute;left: 56.7px;bottom: 722.65px;width: 34.14999999999999px;height: 12.649999999999977px;border-color: none;background-color: rgb(255,241.99755000000002,0)"></div>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 56.8;bottom: 722.6080000000001">
Y
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 64.3;bottom: 722.6080000000001">
e
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 69.604;bottom: 722.6080000000001">
l
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 72.904;bottom: 722.6080000000001">
l
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 76.204;bottom: 722.6080000000001">
o
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 82.204;bottom: 722.6080000000001">
w
</span>
<div class="curve rect" style="position: absolute;left: 90.9px;bottom: 722.65px;width: 19.25px;height: 12.649999999999977px;border-color: none;background-color: rgb(255,63.9999,0)"></div>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 91.0;bottom: 722.6080000000001">
R
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 98.992;bottom: 722.6080000000001">
e
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 104.29599999999999;bottom: 722.6080000000001">
d
</span>
<div class="curve rect" style="position: absolute;left: 110.2px;bottom: 722.65px;width: 29.249999999999986px;height: 12.649999999999977px;border-color: none;background-color: rgb(128.9994,211.99935000000002,25.9998)"></div>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 110.3;bottom: 722.6080000000001">
G
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 118.988;bottom: 722.6080000000001">
r
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 122.984;bottom: 722.6080000000001">
e
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 128.288;bottom: 722.6080000000001">
e
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 133.59199999999998;bottom: 722.6080000000001">
n
</span>
<div class="curve rect" style="position: absolute;left: 139.5px;bottom: 722.65px;width: 40.650000000000006px;height: 12.649999999999977px;border-color: none;background-color: rgb(255,181.9986,107.9976)"></div>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 139.6;bottom: 722.6080000000001">
R
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 147.59199999999998;bottom: 722.6080000000001">
a
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 152.896;bottom: 722.6080000000001">
n
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 158.896;bottom: 722.6080000000001">
d
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 164.896;bottom: 722.6080000000001">
o
</span>
<span class="char" style="font-size: 15.408000000000015px;font-family: BAAAAA+LiberationSerif;color: rgb(0,0,0);position: absolute;left: 170.896;bottom: 722.6080000000001">
m
</span>
</div>
</body>
</html>
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -10,7 +10,7 @@ import sys
with open('README.md') as readme_file:
SETUP = {
"name": "pdfmajor",
"version": "1.0.4",
"version": "1.0.6",
"packages": find_namespace_packages(include=['pdfmajor*']),
"install_requires": [
'pycryptodome',