Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac49ad1bcf | ||
|
|
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.
|
||||
|
||||
"""
|
||||
__version__ = (1, 1, 7)
|
||||
__version__ = (1, 1, 10)
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(
|
||||
|
||||
@@ -33,7 +33,7 @@ def get_color(col: PDFGraphicStateColor):
|
||||
return f'gray({color_val})'
|
||||
elif color_type == "custom":
|
||||
# Todo: convert these to more friendly color types
|
||||
return f"custom({col.custom['type']})"
|
||||
return f"{col.custom['type']}({col.custom['defintion']})"
|
||||
return ""
|
||||
|
||||
FIRST_CAP_RE = re.compile('(.)([A-Z][a-z]+)')
|
||||
@@ -131,7 +131,7 @@ class XMLConverter(PDFConverter):
|
||||
'y0': char.y0,
|
||||
'y1': char.y1,
|
||||
}, no_additional_char=True):
|
||||
self.write(char.get_text(), lineend='', deep_space="")
|
||||
self.write(saxutils.escape(char.get_text()), lineend='', deep_space="")
|
||||
|
||||
def render_char_block(self, char_block: LTCharBlock):
|
||||
attr = {
|
||||
|
||||
@@ -351,6 +351,24 @@ class PDFPageInterpreter(object):
|
||||
#self.do_cs(LITERAL_DEVICE_CMYK)
|
||||
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
|
||||
def __process_scn(self):
|
||||
if self.ncs:
|
||||
@@ -359,8 +377,14 @@ class PDFPageInterpreter(object):
|
||||
raise PDFInterpreterError('No colorspace specified!')
|
||||
components = self.pop(n)
|
||||
obj_id = components[0]
|
||||
if self.ncs.name == "ICCBased":
|
||||
return self.__process_ICCBased(n, components)
|
||||
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():
|
||||
raise PDFInterpreterError("Invalid Color reference")
|
||||
|
||||
@@ -374,11 +398,27 @@ class PDFPageInterpreter(object):
|
||||
"defintion": color_data
|
||||
}
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
def do_SC(self):
|
||||
|
||||
@@ -8,7 +8,7 @@ from xml.etree import ElementTree
|
||||
def rel_path(*arg: List[str]) -> str:
|
||||
return os.path.join(os.path.dirname(__file__), *arg)
|
||||
|
||||
EXT = 'xml'
|
||||
EXT = 'html'
|
||||
INPUT_FOLDER = rel_path("./pdf")
|
||||
OUTPUT_FOLDER = rel_path(f"./output/{EXT}")
|
||||
|
||||
|
||||
Reference in new issue
Block a user