Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7722b99f70 | ||
|
|
66b5fea65c |
No files matched your search
@@ -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(
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
@@ -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}")
|
||||||
|
|
||||||
|
|||||||
@@ -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',
|
||||||
|
|||||||
Reference in new issue
Block a user