- more verbose xml text output

This commit is contained in:
ari committed 2018-10-27 19:52:12 -04:00
1 parent 39280476e2
commit b4999d2010
11 files changed
+63 -27

No files matched your search

+8 -6
View File
@@ -113,16 +113,18 @@ class XMLConverter(PDFConverter):
})
def place_text(self, char: LTChar):
with self.place_elm_with_child('char', {
'font-size': char.size,
'font-family': char.fontname,
attr = {
'size': char.size,
"color": get_color(char.graphicstate.ncolor),
"x0": char.x0,
"x1": char.x1,
"y0": char.y0,
"y1": char.y1,
"stroke-color": get_color(char.graphicstate.scolor),
"fill-color": get_color(char.graphicstate.ncolor),
}, no_additional_char=True):
}
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('char', attr, no_additional_char=True):
self.write(char.get_text(), lineend='', deep_space="")
def render_curve(self, item: LTCurve):
+1
View File
@@ -23,6 +23,7 @@ from .PDFStream import list_value
from .PDFStream import dict_value
from .PDFStream import PDFStream
from ..utils import settings, FONT_METRICS, apply_matrix_norm, nunpack, choplist, isnumber
from .constants import COMMON_FONT_ATTRIBUTES
def get_widths(seq):
widths = {}
+1 -1
View File
@@ -72,7 +72,7 @@ class PDFPage(object):
INHERITABLE_ATTRS = set(['Resources', 'MediaBox', 'CropBox', 'Rotate'])
@classmethod
def create_pages(cls, document):
def create_pages(cls, document: PDFDocument):
def search(obj, parent):
if isinstance(obj, int):
objid = obj
+30 -5
View File
@@ -3,8 +3,33 @@ from .PSStackParser import LIT
## Constants
##
LITERAL_PDF = LIT('PDF')
LITERAL_TEXT = LIT('Text')
LITERAL_FONT = LIT('Font')
LITERAL_FORM = LIT('Form')
LITERAL_IMAGE = LIT('Image')
LITERAL_PDF = LIT("PDF")
LITERAL_TEXT = LIT("Text")
LITERAL_FONT = LIT("Font")
LITERAL_FORM = LIT("Form")
LITERAL_IMAGE = LIT("Image")
COMMON_FONT_ATTRIBUTES = [
"Type",
"FontName",
"FontFamily",
"FontStretch",
"FontWeight",
"Flags",
"FontBBox",
"ItalicAngle",
"Ascent",
"Descent",
"Leading",
"CapHeight",
"XHeight",
"StemV",
"StemH",
"AvgWidth",
"MaxWidth",
"MissingWidth",
# "FontFile",
# "FontFile2",
# "FontFile3",
"Charset",
]
+16 -10
View File
@@ -1,6 +1,8 @@
from ._base import LTComponent
from ..utils import apply_matrix_norm, apply_matrix_pt, matrix2str, Bbox
from ..interpreter.PDFGraphicState import PDFGraphicState
from ..interpreter.PDFFont import PDFFont
from ..interpreter.PDFColorSpace import PDFColorSpace
## LTChar
##
@@ -8,19 +10,19 @@ class LTChar(LTComponent):
def __init__(self,
matrix,
font,
fontsize,
scaling,
rise,
text,
textwidth,
textdisp,
ncs,
font: PDFFont,
fontsize: float,
scaling: float,
rise: float,
text: str,
textwidth: float,
textdisp: tuple,
ncs: PDFColorSpace,
graphicstate: PDFGraphicState
):
self._text = text
self.matrix = matrix
self.fontname = font.fontname
self.font = font
self.ncs = ncs
self.graphicstate = graphicstate
self.adv = textwidth * fontsize * scaling
@@ -71,4 +73,8 @@ class LTChar(LTComponent):
def is_compatible(self, obj):
"""Returns True if two characters can coexist in the same line."""
return True
return True
@property
def fontname(self) -> str:
return self.font.fontname
+5 -3
View File
@@ -7,16 +7,18 @@ from pdfmajor.converters import convert_file
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}")
if not os.path.exists(OUTPUT_FOLDER):
os.makedirs(OUTPUT_FOLDER)
files = os.listdir(INPUT_FOLDER)
# files = ['colors.pdf']
# files = os.listdir(INPUT_FOLDER)
# files = ['fonts.pdf']
# files = ['bar-charts.pdf']
# files = ['font-color.pdf']
files = ['tables.pdf']
TOTAL = len(files)
for idx, file_name in enumerate(files):
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2 -2
View File
@@ -1,7 +1,7 @@
# ==============
# Dependencies
# ==============
from setuptools import setup, find_namespace_packages
from setuptools import setup, find_packages
import sys
# ==============
@@ -11,7 +11,7 @@ with open('README.md') as readme_file:
SETUP = {
"name": "pdfmajor",
"version": "1.0.7",
"packages": find_namespace_packages(include=['pdfmajor*']),
"packages": find_packages(include=['pdfmajor*']),
"install_requires": [
'pycryptodome',
'chardet'