2 Commits
Author SHA1 Message Date
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
5 changed files with 34 additions and 21 deletions

No files matched your search

+1 -1
View File
@@ -1 +1 @@
v1.1.3 v1.1.4
+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. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
""" """
__version__ = (1, 1, 3) __version__ = (1, 1, 4)
if __name__ == '__main__': if __name__ == '__main__':
print( print(
+30 -17
View File
@@ -1,4 +1,5 @@
import logging import logging
import re
from typing import Dict from typing import Dict
@@ -30,6 +31,12 @@ def get_color(col: PDFGraphicStateColor):
return f'gray({color_val})' return f'gray({color_val})'
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_camelcase(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,
@@ -113,23 +120,29 @@ 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): 'width': char.width,
tag_name = 'char-block' 'height': char.height,
attr = { }, no_additional_char=True):
'size': char.size,
"color": get_color(char.graphicstate.ncolor),
"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,
"is_bold": char_block.font.is_bold,
}
for key, value in char_block.font.descriptor.items():
if key != "Type" and "FontFile" not in key:
attr[convert_capcase_to_camelcase(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 +177,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):
+1 -1
View File
@@ -7,7 +7,7 @@ from pdfmajor.converters import convert_file
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}")
+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.4",
"packages": find_packages(include=['pdfmajor*']), "packages": find_packages(include=['pdfmajor*']),
"install_requires": [ "install_requires": [
'pycryptodome', 'pycryptodome',