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.
"""
__version__ = (1, 1, 3)
__version__ = (1, 1, 4)
if __name__ == '__main__':
print(
+30 -17
View File
@@ -1,4 +1,5 @@
import logging
import re
from typing import Dict
@@ -30,6 +31,12 @@ def get_color(col: PDFGraphicStateColor):
return f'gray({color_val})'
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):
def __init__(self,
rsrcmgr,
@@ -113,23 +120,29 @@ class XMLConverter(PDFConverter):
})
def place_text(self, char: LTChar):
tag_name = 'char'
if isinstance(char, LTCharBlock):
tag_name = 'char-block'
attr = {
'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):
with self.place_elm_with_child('char', {
'width': char.width,
'height': char.height,
}, no_additional_char=True):
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):
attr = {
"x0": item.x0,
@@ -164,8 +177,8 @@ class XMLConverter(PDFConverter):
render(child)
elif isinstance(item, LTImage):
self.place_image(item)
elif isinstance(item, LTChar) or isinstance(item, LTCharBlock):
self.place_text(item)
elif isinstance(item, LTCharBlock):
self.render_char_block(item)
render(ltpage)
def close(self):
+1 -1
View File
@@ -7,7 +7,7 @@ from pdfmajor.converters import convert_file
def rel_path(*arg: List[str]) -> str:
return os.path.join(os.path.dirname(__file__), *arg)
EXT = 'html'
EXT = 'xml'
INPUT_FOLDER = rel_path("./pdf")
OUTPUT_FOLDER = rel_path(f"./output/{EXT}")
+1 -1
View File
@@ -10,7 +10,7 @@ import sys
with open('README.md') as readme_file:
SETUP = {
"name": "pdfmajor",
"version": "1.1.3",
"version": "1.1.4",
"packages": find_packages(include=['pdfmajor*']),
"install_requires": [
'pycryptodome',