10 Commits
Author SHA1 Message Date
ari 70144c8fe1 - updated docx
- sanitizing xml attributes
2018-11-04 16:28:29 -05:00
ari 0d832bf7fa version inc 2018-10-31 14:45:37 -04:00
ari 7319b7f584 xml chars output bbx instead of width/height 2018-10-31 14:45:02 -04:00
ari 5b641d6243 comment out leading for now 2018-10-29 16:35:32 -04:00
ari 10d679d379 clean up 2018-10-29 16:26:57 -04:00
ari 5378a4f34c - better color grabbing for scn
- show custom type in converters
2018-10-29 16:25:50 -04:00
ari 42cbc8e39e - using snake case
- not outputting is_bold
2018-10-29 13:18:12 -04:00
ari 66004988f4 actually cleaning it all prior to deployment 2018-10-29 13:04:32 -04:00
ari 7722b99f70 Deployong new version - v1.1.4 2018-10-29 13:03:28 -04:00
ari 66b5fea65c - compatible xml-converter with char-blocks
- consitent attr naming convention for fonts
2018-10-29 13:03:11 -04:00
17 changed files with 148 additions and 54 deletions

No files matched your search

+1 -1
View File
@@ -1 +1 @@
v1.1.3 v1.1.7
+11
View File
@@ -1,5 +1,16 @@
# PDFMajor # PDFMajor
<table>
<tr>
<td>Latest Release</td>
<td>
<a href="https://pypi.org/project/pdfmajor/">
<img src="https://img.shields.io/pypi/v/pdfmajor.svg" alt="latest release" />
</a>
</td>
</tr>
</table>
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. 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.
## Documentation ## Documentation
+2 -2
View File
@@ -4,12 +4,12 @@ WK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $WK_DIR cd $WK_DIR
cd .. cd ..
sh bin/clean.sh ./bin/clean.sh
python setup.py sdist bdist_wheel python setup.py sdist bdist_wheel
git add . git add .
git commit -m "Deployong new version - $(cat .version)" git commit
git push git push
git tag $(cat .version) git tag $(cat .version)
+11
View File
@@ -1,5 +1,16 @@
# PDFMajor # PDFMajor
<table>
<tr>
<td>Latest Release</td>
<td>
<a href="https://pypi.org/project/pdfmajor/">
<img src="https://img.shields.io/pypi/v/pdfmajor.svg" alt="latest release" />
</a>
</td>
</tr>
</table>
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. 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.
## Documentation ## Documentation
+14 -3
View File
@@ -53,7 +53,7 @@
<a class="current" href=".">Home</a> <a class="current" href=".">Home</a>
<ul class="subnav"> <ul class="subnav">
<li class="toctree-l2"><a href="#pdf-major">PDF-Major</a></li> <li class="toctree-l2"><a href="#pdfmajor">PDFMajor</a></li>
<ul> <ul>
@@ -110,7 +110,18 @@
<div role="main"> <div role="main">
<div class="section"> <div class="section">
<h1 id="pdf-major">PDF-Major</h1> <h1 id="pdfmajor">PDFMajor</h1>
<table>
<tr>
<td>Latest Release</td>
<td>
<a href="https://pypi.org/project/pdfmajor/">
<img src="https://img.shields.io/pypi/v/pdfmajor.svg" alt="latest release" />
</a>
</td>
</tr>
</table>
<p>PDF-Major is a fork of <code>PDFMiner.six</code>. 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.</p> <p>PDF-Major is a fork of <code>PDFMiner.six</code>. 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.</p>
<h2 id="documentation">Documentation</h2> <h2 id="documentation">Documentation</h2>
<p>See documentation <a href="https://asosnovsky.github.io/pdfmajor/">here</a>.</p> <p>See documentation <a href="https://asosnovsky.github.io/pdfmajor/">here</a>.</p>
@@ -216,5 +227,5 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
<!-- <!--
MkDocs version : 1.0.4 MkDocs version : 1.0.4
Build Date UTC : 2018-10-12 22:22:34 Build Date UTC : 2018-11-04 21:27:38
--> -->
+1 -1
View File
@@ -1 +1 @@
{"config":{"lang":["en"],"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"PDF-Major 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. Documentation See documentation here . 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. Features Written entirely in Python. Parse, analyze, and convert PDF documents. PDF-1.7 specification support. (well, almost) CJK languages and vertical writing scripts support. Various font types (Type1, TrueType, Type3, and CID) support. Basic encryption (RC4) support. Font-Color extraction Shape fill and stroke color extraction 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. How to Install Source Install Python 3.6.4 or newer. clone this repo git clone https://github.com/asosnovsky/pdfmajor * install repo python setup.py install Pypi Install Python 3.6.4 or newer. install repo pip install pdfmajor Terms and Conditions (This is so-called MIT/X License) Copyright (c) 2018-2019 Ariel Sosnovsky Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","title":"Home"},{"location":"#pdf-major","text":"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.","title":"PDF-Major"},{"location":"#documentation","text":"See documentation here .","title":"Documentation"},{"location":"#why-another-fork","text":"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.","title":"Why Another Fork?"},{"location":"#features","text":"Written entirely in Python. Parse, analyze, and convert PDF documents. PDF-1.7 specification support. (well, almost) CJK languages and vertical writing scripts support. Various font types (Type1, TrueType, Type3, and CID) support. Basic encryption (RC4) support. Font-Color extraction Shape fill and stroke color extraction 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.","title":"Features"},{"location":"#how-to-install","text":"","title":"How to Install"},{"location":"#source","text":"Install Python 3.6.4 or newer. clone this repo git clone https://github.com/asosnovsky/pdfmajor * install repo python setup.py install","title":"Source"},{"location":"#pypi","text":"Install Python 3.6.4 or newer. install repo pip install pdfmajor","title":"Pypi"},{"location":"#terms-and-conditions","text":"(This is so-called MIT/X License) Copyright (c) 2018-2019 Ariel Sosnovsky Permission is hereby granted, free of charge, to any person obtaining aLine truncated {"config":{"lang":["en"],"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"PDFMajor Latest Release 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. Documentation See documentation here . 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. Features Written entirely in Python. Parse, analyze, and convert PDF documents. PDF-1.7 specification support. (well, almost) CJK languages and vertical writing scripts support. Various font types (Type1, TrueType, Type3, and CID) support. Basic encryption (RC4) support. Font-Color extraction Shape fill and stroke color extraction 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. How to Install Source Install Python 3.6.4 or newer. clone this repo git clone https://github.com/asosnovsky/pdfmajor * install repo python setup.py install Pypi Install Python 3.6.4 or newer. install repo pip install pdfmajor Terms and Conditions (This is so-called MIT/X License) Copyright (c) 2018-2019 Ariel Sosnovsky Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","title":"Home"},{"location":"#pdfmajor","text":"Latest Release 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.","title":"PDFMajor"},{"location":"#documentation","text":"See documentation here .","title":"Documentation"},{"location":"#why-another-fork","text":"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.","title":"Why Another Fork?"},{"location":"#features","text":"Written entirely in Python. Parse, analyze, and convert PDF documents. PDF-1.7 specification support. (well, almost) CJK languages and vertical writing scripts support. Various font types (Type1, TrueType, Type3, and CID) support. Basic encryption (RC4) support. Font-Color extraction Shape fill and stroke color extraction 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.","title":"Features"},{"location":"#how-to-install","text":"","title":"How to Install"},{"location":"#source","text":"Install Python 3.6.4 or newer. clone this repo git clone https://github.com/asosnovsky/pdfmajor * install repo python setup.py install","title":"Source"},{"location":"#pypi","text":"Install Python 3.6.4 or newer. install repo pip install pdfmajor","title":"Pypi"},{"location":"#terms-and-conditions","text":"(This is so-called MIT/X License) Copyright (c) 2018-2019 Ariel Sosnovsky Permission is hereby granted, free of chargeLine truncated
+2 -2
View File
@@ -2,12 +2,12 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>None</loc> <loc>None</loc>
<lastmod>2018-10-12</lastmod> <lastmod>2018-11-04</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>None</loc> <loc>None</loc>
<lastmod>2018-10-12</lastmod> <lastmod>2018-11-04</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
</urlset> </urlset>
Binary file not shown.
+12 -1
View File
@@ -5,6 +5,17 @@
""" """
# PDFMajor # PDFMajor
<table>
<tr>
<td>Latest Release</td>
<td>
<a href="https://pypi.org/project/pdfmajor/">
<img src="https://img.shields.io/pypi/v/pdfmajor.svg" alt="latest release" />
</a>
</td>
</tr>
</table>
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. 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.
## Documentation ## Documentation
@@ -75,7 +86,7 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
""" """
__version__ = (1, 1, 3) __version__ = (1, 1, 7)
if __name__ == '__main__': if __name__ == '__main__':
print( print(
+4 -1
View File
@@ -26,6 +26,9 @@ def get_color(col: PDFGraphicStateColor):
return f"cmyk({','.join(map(str, color_val))})" return f"cmyk({','.join(map(str, color_val))})"
elif color_type == 'gray': elif color_type == 'gray':
return f'rgba(0,0,0,{1-color_val})' return f'rgba(0,0,0,{1-color_val})'
elif color_type == "custom":
# Todo: convert these to more friendly color types
return f"custom({col.custom['type']})"
return "none" return "none"
class HTMLConverter(PDFConverter): class HTMLConverter(PDFConverter):
@@ -236,7 +239,7 @@ class HTMLConverter(PDFConverter):
'display': 'flex', 'display': 'flex',
'flex-flow': 'row nowrap', 'flex-flow': 'row nowrap',
'justify-content': 'space-between', 'justify-content': 'space-between',
'padding-left': item.font.leading # 'padding-left': item.font.leading
}): }):
for char in item: for char in item:
render(char) render(char)
+38 -19
View File
@@ -1,7 +1,10 @@
import logging import logging
import re
import json
from typing import Dict from typing import Dict
from xml.sax import saxutils
from contextlib import contextmanager from contextlib import contextmanager
from ..layouts import LTPage from ..layouts import LTPage
@@ -28,8 +31,17 @@ def get_color(col: PDFGraphicStateColor):
return f"cmyk({','.join(map(str, color_val))})" return f"cmyk({','.join(map(str, color_val))})"
elif color_type == 'gray': elif color_type == 'gray':
return f'gray({color_val})' return f'gray({color_val})'
elif color_type == "custom":
# Todo: convert these to more friendly color types
return f"custom({col.custom['type']})"
return "" return ""
FIRST_CAP_RE = re.compile('(.)([A-Z][a-z]+)')
ALL_CAP_RE = re.compile('([a-z0-9])([A-Z])')
def convert_capcase_to_snakecase(text: str) -> str:
s1 = FIRST_CAP_RE.sub(r'\1-\2', text)
return ALL_CAP_RE.sub(r'\1-\2', s1).lower()
class XMLConverter(PDFConverter): class XMLConverter(PDFConverter):
def __init__(self, def __init__(self,
rsrcmgr, rsrcmgr,
@@ -71,7 +83,7 @@ class XMLConverter(PDFConverter):
lineend = '' lineend = ''
deep_space = '' deep_space = ''
attrs = " ".join([ attrs = " ".join([
f'{name}="{value}"' f'{name}="{saxutils.escape(str(value))}"'
for name, value in attr_dict.items() for name, value in attr_dict.items()
]) ])
self.write(f"<{tag_name} {attrs}>", lineend=lineend) self.write(f"<{tag_name} {attrs}>", lineend=lineend)
@@ -82,7 +94,7 @@ class XMLConverter(PDFConverter):
def place_elm_close(self, tag_name: str, attr_dict: Dict[str, str] = {}, as_childless = True): def place_elm_close(self, tag_name: str, attr_dict: Dict[str, str] = {}, as_childless = True):
attrs = " ".join([ attrs = " ".join([
f'{name}="{value}"' f'{name}="{saxutils.escape(str(value))}"'
for name, value in attr_dict.items() for name, value in attr_dict.items()
]) ])
if as_childless: if as_childless:
@@ -113,23 +125,30 @@ class XMLConverter(PDFConverter):
}) })
def place_text(self, char: LTChar): def place_text(self, char: LTChar):
tag_name = 'char' with self.place_elm_with_child('char', {
if isinstance(char, LTCharBlock): 'x0': char.x0,
tag_name = 'char-block' 'x1': char.x1,
attr = { 'y0': char.y0,
'size': char.size, 'y1': char.y1,
"color": get_color(char.graphicstate.ncolor), }, no_additional_char=True):
"x0": char.x0,
"x1": char.x1,
"y0": char.y0,
"y1": char.y1,
}
for key, value in char.font.descriptor.items():
if key != "Type" and "FontFile" not in key:
attr["font-" + key] = value
with self.place_elm_with_child(tag_name, attr, no_additional_char=True):
self.write(char.get_text(), lineend='', deep_space="") self.write(char.get_text(), lineend='', deep_space="")
def render_char_block(self, char_block: LTCharBlock):
attr = {
'size': char_block.size,
"color": get_color(char_block.graphicstate.ncolor),
"x0": char_block.x0,
"x1": char_block.x1,
"y0": char_block.y0,
"y1": char_block.y1,
}
for key, value in char_block.font.descriptor.items():
if key != "Type" and "FontFile" not in key:
attr[convert_capcase_to_snakecase(key)] = value
with self.place_elm_with_child("char-block", attr):
for char in char_block:
self.place_text(char)
def render_curve(self, item: LTCurve): def render_curve(self, item: LTCurve):
attr = { attr = {
"x0": item.x0, "x0": item.x0,
@@ -164,8 +183,8 @@ class XMLConverter(PDFConverter):
render(child) render(child)
elif isinstance(item, LTImage): elif isinstance(item, LTImage):
self.place_image(item) self.place_image(item)
elif isinstance(item, LTChar) or isinstance(item, LTCharBlock): elif isinstance(item, LTCharBlock):
self.place_text(item) self.render_char_block(item)
render(ltpage) render(ltpage)
def close(self): def close(self):
@@ -5,6 +5,7 @@ class PDFGraphicStateColor:
self.__rgb = None self.__rgb = None
self.__gray = None self.__gray = None
self.__cmyk = None self.__cmyk = None
self.__custom = None
def get_color(self): def get_color(self):
if self.__rgb is not None: if self.__rgb is not None:
@@ -13,6 +14,8 @@ class PDFGraphicStateColor:
return 'cmyk', self.cmyk return 'cmyk', self.cmyk
elif self.__gray is not None: elif self.__gray is not None:
return 'gray', self.gray return 'gray', self.gray
elif self.__custom is not None:
return 'custom', self.custom
else: return None, None else: return None, None
@property @property
@@ -34,6 +37,11 @@ class PDFGraphicStateColor:
if self.__gray is not None: return float(self.__gray) if self.__gray is not None: return float(self.__gray)
else: raise self.NotSet else: raise self.NotSet
@property
def custom(self):
if self.__custom is not None: return dict(self.__custom)
else: raise self.NotSet
@rgb.setter @rgb.setter
def rgb(self, rgb): def rgb(self, rgb):
self.__rgb = rgb self.__rgb = rgb
@@ -46,11 +54,16 @@ class PDFGraphicStateColor:
def gray(self, color): def gray(self, color):
self.__gray = color self.__gray = color
@custom.setter
def custom(self, color):
self.__custom = color
def copy(self): def copy(self):
cp = self.__class__() cp = self.__class__()
cp.gray = self.__gray cp.gray = self.__gray
cp.rgb = self.__rgb cp.rgb = self.__rgb
cp.cmyk = self.__cmyk cp.cmyk = self.__cmyk
cp.custom = self.__custom
return cp return cp
def __repr__(self): def __repr__(self):
@@ -58,4 +71,5 @@ class PDFGraphicStateColor:
if self.__gray is not None: rep += f' gray={self.__gray}' if self.__gray is not None: rep += f' gray={self.__gray}'
if self.__rgb is not None: rep += f' rgb=[{",".join(map(str, self.__rgb))}]' if self.__rgb is not None: rep += f' rgb=[{",".join(map(str, self.__rgb))}]'
if self.__cmyk is not None: rep += f' cmyk=[{",".join(map(str, self.__cmyk))}]' if self.__cmyk is not None: rep += f' cmyk=[{",".join(map(str, self.__cmyk))}]'
if self.__custom is not None: rep += f' custom={self.__custom}'
return rep + '/>' return rep + '/>'
+25 -11
View File
@@ -1,6 +1,7 @@
import logging import logging
import operator import operator
from collections import OrderedDict
from typing import List from typing import List
@@ -54,7 +55,7 @@ class PDFPageInterpreter(object):
self.resources = resources self.resources = resources
self.fontmap = {} self.fontmap = {}
self.xobjmap = {} self.xobjmap = {}
self.csmap = PREDEFINED_COLORSPACE.copy() self.csmap:OrderedDict = PREDEFINED_COLORSPACE.copy()
if not resources: if not resources:
return return
@@ -351,20 +352,33 @@ class PDFPageInterpreter(object):
return return
# setcolor # setcolor
def do_SCN(self): def __process_scn(self):
if self.scs:
n = self.scs.ncomponents
else:
raise PDFInterpreterError('No colorspace specified!')
self.pop(n)
return
def do_scn(self):
if self.ncs: if self.ncs:
n = self.ncs.ncomponents n = self.ncs.ncomponents
else: else:
raise PDFInterpreterError('No colorspace specified!') raise PDFInterpreterError('No colorspace specified!')
self.pop(n) components = self.pop(n)
obj_id = components[0]
if self.ncs.name not in self.resources.keys():
raise PDFInterpreterError("Color space not in resources")
if obj_id.name not in self.resources[self.ncs.name].keys():
raise PDFInterpreterError("Invalid Color reference")
color_data = self.resources[self.ncs.name][obj_id.name].resolve()
if isinstance(color_data, PDFStream):
color_data = color_data.attrs
return {
"type": self.ncs.name,
"defintion": color_data
}
def do_SCN(self):
self.graphicstate.scolor.custom = self.__process_scn()
return
def do_scn(self):
self.graphicstate.ncolor.custom = self.__process_scn()
return return
def do_SC(self): def do_SC(self):
+1 -1
View File
@@ -12,7 +12,7 @@ from .exceptions import * # pylint: disable=W0614
## ##
class PDFObjRef(PDFObject): class PDFObjRef(PDFObject):
def __init__(self, doc, objid, _): def __init__(self, doc, objid, a):
if objid == 0: if objid == 0:
if settings.STRICT: if settings.STRICT:
raise PDFValueError('PDF object id cannot be 0.') raise PDFValueError('PDF object id cannot be 0.')
@@ -100,7 +100,6 @@ class PSBaseParser(object):
linebuf += self.buf[self.charpos:] linebuf += self.buf[self.charpos:]
self.charpos = len(self.buf) self.charpos = len(self.buf)
log.debug('nextline: %r, %r', linepos, linebuf) log.debug('nextline: %r, %r', linepos, linebuf)
return (linepos, linebuf) return (linepos, linebuf)
def revreadlines(self): def revreadlines(self):
+11 -10
View File
@@ -3,35 +3,36 @@ import os
from typing import List from typing import List
from pdfmajor.converters import convert_file from pdfmajor.converters import convert_file
from xml.etree import ElementTree
def rel_path(*arg: List[str]) -> str: def rel_path(*arg: List[str]) -> str:
return os.path.join(os.path.dirname(__file__), *arg) return os.path.join(os.path.dirname(__file__), *arg)
EXT = 'html' EXT = 'xml'
INPUT_FOLDER = rel_path("./pdf") INPUT_FOLDER = rel_path("./pdf")
OUTPUT_FOLDER = rel_path(f"./output/{EXT}") OUTPUT_FOLDER = rel_path(f"./output/{EXT}")
if not os.path.exists(OUTPUT_FOLDER): if not os.path.exists(OUTPUT_FOLDER):
os.makedirs(OUTPUT_FOLDER) os.makedirs(OUTPUT_FOLDER)
# files = os.listdir(INPUT_FOLDER) files = os.listdir(INPUT_FOLDER)
# files = ['fonts.pdf']
# files = ['bar-charts.pdf']
# files = ['font-color.pdf']
files = ['tables.pdf']
TOTAL = len(files) TOTAL = len(files)
for idx, file_name in enumerate(files): for idx, file_name in enumerate(files):
file_name_no_ext = re.sub(r'\.pdf$',"", file_name) file_name_no_ext = re.sub(r'\.pdf$',"", file_name)
input_file_path = os.path.join(INPUT_FOLDER, file_name)
output_file_path = os.path.join(OUTPUT_FOLDER, file_name_no_ext + "." + EXT)
print(f"processing {file_name} {idx}/{TOTAL}")
if len(file_name) > len(file_name_no_ext): if len(file_name) > len(file_name_no_ext):
with open(os.path.join(INPUT_FOLDER, file_name), 'rb') as input_file: print(f"processing {file_name} {idx}/{TOTAL}")
with open(os.path.join(OUTPUT_FOLDER, file_name_no_ext + "." + EXT), 'wb') as output_file: with open(input_file_path, 'rb') as input_file:
with open(output_file_path, 'wb') as output_file:
convert_file( convert_file(
input_file=input_file, input_file=input_file,
output_file=output_file, output_file=output_file,
out_type=EXT, out_type=EXT,
debug=True, debug=True,
) )
print(f"processing {idx+1}/{TOTAL}") print(f" > testing format {file_name} {idx}/{TOTAL}")
ElementTree.parse(output_file_path)
print(f"processing {idx+1}/{TOTAL}")
+1 -1
View File
@@ -10,7 +10,7 @@ import sys
with open('README.md') as readme_file: with open('README.md') as readme_file:
SETUP = { SETUP = {
"name": "pdfmajor", "name": "pdfmajor",
"version": "1.1.3", "version": "1.1.7",
"packages": find_packages(include=['pdfmajor*']), "packages": find_packages(include=['pdfmajor*']),
"install_requires": [ "install_requires": [
'pycryptodome', 'pycryptodome',