Author SHA1 Message Date
ari 290de97cb5 - fixed invisible color bug 2019-01-26 23:08:57 -05:00
ari b32aef7fda - fixed the curve ignoring of the color error 2019-01-24 21:38:47 -05:00
7 changed files with 133 additions and 3 deletions

No files matched your search

+1 -1
View File
@@ -1 +1 @@
v1.3.6 v1.3.7
+1 -1
View File
@@ -97,7 +97,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, 3, 6) __version__ = (1, 3, 7)
if __name__ == '__main__': if __name__ == '__main__':
print( print(
+11
View File
@@ -23,10 +23,16 @@ def process_command_stream(streams: List[PDFStream], font_cache: dict = None, st
if font_cache is None: if font_cache is None:
font_cache = {} font_cache = {}
parser = PDFContentParser(streams) parser = PDFContentParser(streams)
# from .cmd_record import CmdRecord
# history = CmdRecord()
for obj in parser: for obj in parser:
if isinstance(obj, PSKeyword): if isinstance(obj, PSKeyword):
name = keyword_name(obj) name = keyword_name(obj)
method = name.replace('*', '_a').replace('"', '_w').replace("'", '_q') method = name.replace('*', '_a').replace('"', '_w').replace("'", '_q')
func = None
args = []
if method == "Do":
pass
if method in PDFCommands.commands.keys(): if method in PDFCommands.commands.keys():
func = PDFCommands.commands.get(method) func = PDFCommands.commands.get(method)
nargs = func.__code__.co_argcount-1 nargs = func.__code__.co_argcount-1
@@ -40,8 +46,12 @@ def process_command_stream(streams: List[PDFStream], font_cache: dict = None, st
func(state) func(state)
else: else:
log.debug('Unknown operator: %r (i.e. %r)' % (name, method)) log.debug('Unknown operator: %r (i.e. %r)' % (name, method))
# history.write(name,
# None if func is None else func.__name__
# , args)
else: else:
state.argstack.append(obj) state.argstack.append(obj)
# history.write('arg', None, obj)
for complete_item in state.complete_layout_items: for complete_item in state.complete_layout_items:
if isinstance(complete_item, LTXObject): if isinstance(complete_item, LTXObject):
@@ -51,6 +61,7 @@ def process_command_stream(streams: List[PDFStream], font_cache: dict = None, st
resources=complete_item.resources, resources=complete_item.resources,
font_cache=font_cache font_cache=font_cache
) )
xobj_state.graphics = state.graphics.copy()
for item in process_command_stream( for item in process_command_stream(
[complete_item.stream], [complete_item.stream],
font_cache=font_cache, font_cache=font_cache,
@@ -0,0 +1,9 @@
class CmdRecord:
def __init__(self, file_name: str = "./cmd_record"):
self.file = open(file_name, 'w')
self.file.write("c_name,func_name,args\n")
def write(self, c_name, func_name, args):
self.file.write(f"{c_name},{func_name},{args}\n")
def close(self):
self.file.close()
+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.3.6", "version": "1.3.7",
"packages": find_packages(include=['pdfmajor*']), "packages": find_packages(include=['pdfmajor*']),
"install_requires": [ "install_requires": [
'pycryptodome', 'pycryptodome',
Binary file not shown.
+110
View File
@@ -0,0 +1,110 @@
import os
from typing import List
from tqdm import tqdm
# from pdfmajor.extractor import extract_items_from_pdf
from pdfmajor.interpreter import LTCharBlock, PDFInterpreter, logging
from pdfmajor.interpreter import PageInterpreter
from pdfmajor.interpreter.commands import LTCurve, PDFColor, LTXObject
from pdfmajor.interpreter.commands import PREDEFINED_COLORSPACE
CUR_PATH = os.path.dirname(os.path.dirname(__file__))
INPUT_FOLDER = os.path.join(
CUR_PATH, "tests/samples/pdf"
)
FILES = os.listdir(INPUT_FOLDER)
NUM_LOOPS = 10
file_path = os.path.join(INPUT_FOLDER, "lorem-v4.pdf")
def run_test(file_path: str, curve_defs: List[List[PDFColor]]):
def run_once(item):
if isinstance(item, LTCurve):
t_stroke, t_fill = curve_defs.pop(0)
# print([item.stroke, item.fill])
# print('...>', [t_stroke, t_fill])
assert item.stroke.values == t_stroke.values
assert item.stroke.color_space == t_stroke.color_space
assert item.fill.values == t_fill.values
assert item.fill.color_space == t_fill.color_space
elif isinstance(item, LTXObject):
for c in item:
run_once(c)
for page in PDFInterpreter(file_path):
for item in page:
run_once(item)
run_test(
os.path.join(INPUT_FOLDER, "lorem-v3.pdf"),
[
[
PDFColor(None),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 255, 255, 255),
],
[
PDFColor(None),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 114, 159, 207),
],
[
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 255, 255, 0),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 114, 159, 207),
],
[
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 255, 255, 0),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 114, 159, 207),
],
[
PDFColor(None),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 255, 255, 255),
],
[
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 0, 0, 128),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 255, 0, 0),
]
] +
([[
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 0, 0, 128),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 255, 255, 255),
]]*24)+
([[
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 0, 0, 128),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 0, 0, 0),
]]*11)+
([[
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 128, 128, 128),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 0, 0, 0),
]]*5)+
[[
PDFColor(None),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 255, 255, 255),
]]
)
run_test(
os.path.join(INPUT_FOLDER, "lorem-v4.pdf"),
[
[
PDFColor(None),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 255, 255, 255),
],
[
PDFColor(None),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 64, 64, 64),
]
]
)
run_test(
os.path.join(INPUT_FOLDER, "lorem-v5.pdf"),
[
[
PDFColor(None),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 255, 255, 255),
],
[
PDFColor(None),
PDFColor(PREDEFINED_COLORSPACE['DeviceRGB'], 128, 128, 128),
]
]
)