Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d74bf1eaa9 | ||
|
|
cf3c89bf25 | ||
|
|
b491cd2181 |
No files matched your search
@@ -86,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, 7)
|
__version__ = (1, 1, 9)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(
|
print(
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ def get_color(col: PDFGraphicStateColor):
|
|||||||
return f'gray({color_val})'
|
return f'gray({color_val})'
|
||||||
elif color_type == "custom":
|
elif color_type == "custom":
|
||||||
# Todo: convert these to more friendly color types
|
# Todo: convert these to more friendly color types
|
||||||
return f"custom({col.custom['type']})"
|
return f"{col.custom['type']}({col.custom['defintion']})"
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
FIRST_CAP_RE = re.compile('(.)([A-Z][a-z]+)')
|
FIRST_CAP_RE = re.compile('(.)([A-Z][a-z]+)')
|
||||||
|
|||||||
@@ -351,6 +351,24 @@ class PDFPageInterpreter(object):
|
|||||||
#self.do_cs(LITERAL_DEVICE_CMYK)
|
#self.do_cs(LITERAL_DEVICE_CMYK)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def __process_ICCBased(self, n: int, components: list):
|
||||||
|
if n == 1:
|
||||||
|
return {
|
||||||
|
"type": "gray",
|
||||||
|
"definition": components
|
||||||
|
}
|
||||||
|
elif n == 3:
|
||||||
|
return {
|
||||||
|
"type": "rgb",
|
||||||
|
"definition": components
|
||||||
|
}
|
||||||
|
elif n == 4:
|
||||||
|
return {
|
||||||
|
"type": "cmyk",
|
||||||
|
"definition": components
|
||||||
|
}
|
||||||
|
raise PDFInterpreterError("Unsupported ICCBased color")
|
||||||
|
|
||||||
# setcolor
|
# setcolor
|
||||||
def __process_scn(self):
|
def __process_scn(self):
|
||||||
if self.ncs:
|
if self.ncs:
|
||||||
@@ -359,8 +377,14 @@ class PDFPageInterpreter(object):
|
|||||||
raise PDFInterpreterError('No colorspace specified!')
|
raise PDFInterpreterError('No colorspace specified!')
|
||||||
components = self.pop(n)
|
components = self.pop(n)
|
||||||
obj_id = components[0]
|
obj_id = components[0]
|
||||||
|
if self.ncs.name == "ICCBased":
|
||||||
|
return self.__process_ICCBased(n, components)
|
||||||
if self.ncs.name not in self.resources.keys():
|
if self.ncs.name not in self.resources.keys():
|
||||||
raise PDFInterpreterError("Color space not in resources")
|
log.warning("Color space not in resources")
|
||||||
|
return {
|
||||||
|
"type": self.ncs.name,
|
||||||
|
"defintion": f"{n}|({','.join(map(str, components))})"
|
||||||
|
}
|
||||||
if obj_id.name not in self.resources[self.ncs.name].keys():
|
if obj_id.name not in self.resources[self.ncs.name].keys():
|
||||||
raise PDFInterpreterError("Invalid Color reference")
|
raise PDFInterpreterError("Invalid Color reference")
|
||||||
|
|
||||||
@@ -374,11 +398,27 @@ class PDFPageInterpreter(object):
|
|||||||
"defintion": color_data
|
"defintion": color_data
|
||||||
}
|
}
|
||||||
def do_SCN(self):
|
def do_SCN(self):
|
||||||
self.graphicstate.scolor.custom = self.__process_scn()
|
processed_col = self.__process_scn()
|
||||||
|
if processed_col['type'] == 'rgb':
|
||||||
|
self.graphicstate.scolor.rgb = processed_col['definition']
|
||||||
|
elif processed_col['type'] == 'gray':
|
||||||
|
self.graphicstate.scolor.gray = processed_col['definition'][0]
|
||||||
|
elif processed_col['type'] == 'cmyk':
|
||||||
|
self.graphicstate.scolor.cmyk = processed_col['definition']
|
||||||
|
else:
|
||||||
|
self.graphicstate.scolor.custom = processed_col
|
||||||
return
|
return
|
||||||
|
|
||||||
def do_scn(self):
|
def do_scn(self):
|
||||||
self.graphicstate.ncolor.custom = self.__process_scn()
|
processed_col = self.__process_scn()
|
||||||
|
if processed_col['type'] == 'rgb':
|
||||||
|
self.graphicstate.ncolor.rgb = processed_col['definition']
|
||||||
|
elif processed_col['type'] == 'gray':
|
||||||
|
self.graphicstate.ncolor.gray = processed_col['definition'][0]
|
||||||
|
elif processed_col['type'] == 'cmyk':
|
||||||
|
self.graphicstate.ncolor.cmyk = processed_col['definition']
|
||||||
|
else:
|
||||||
|
self.graphicstate.ncolor.custom = processed_col
|
||||||
return
|
return
|
||||||
|
|
||||||
def do_SC(self):
|
def do_SC(self):
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ 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 = 'xml'
|
EXT = 'html'
|
||||||
INPUT_FOLDER = rel_path("./pdf")
|
INPUT_FOLDER = rel_path("./pdf")
|
||||||
OUTPUT_FOLDER = rel_path(f"./output/{EXT}")
|
OUTPUT_FOLDER = rel_path(f"./output/{EXT}")
|
||||||
|
|
||||||
|
|||||||
@@ -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.7",
|
"version": "1.1.9",
|
||||||
"packages": find_packages(include=['pdfmajor*']),
|
"packages": find_packages(include=['pdfmajor*']),
|
||||||
"install_requires": [
|
"install_requires": [
|
||||||
'pycryptodome',
|
'pycryptodome',
|
||||||
|
|||||||
Reference in new issue
Block a user