diff --git a/pdfmajor/interpreter/commands/commands.py b/pdfmajor/interpreter/commands/commands.py index 6aec062..dcab93d 100644 --- a/pdfmajor/interpreter/commands/commands.py +++ b/pdfmajor/interpreter/commands/commands.py @@ -14,38 +14,38 @@ log = get_logger('commands') # No Support # @PDFCommands.add('W','W_a', 'sh', 'ET', 'BX', 'EX' ,'BI', 'ID', 'gs') # def do_no_support(stack: PDFStateStack) -> PDFStateStack: -# # log.warning("Unsupported command") +# # log.debug("Unsupported command") # return stack # marked content operators @PDFCommands.add('MP') def do_MP(stack: PDFStateStack, tag) -> PDFStateStack: - log.warning(f"Unsupported command - do_tag {[tag]}") + log.debug(f"Unsupported command - do_tag {[tag]}") # self.device.do_tag(tag) return stack @PDFCommands.add('DP') def do_DP(stack: PDFStateStack, tag, props=None) -> PDFStateStack: - log.warning(f"Unsupported command - do_tag {[tag.name, type(tag), props]}") + log.debug(f"Unsupported command - do_tag {[tag.name, type(tag), props]}") # self.device.do_tag(tag) return stack @PDFCommands.add('BMC') def do_BMC(stack: PDFStateStack, tag) -> PDFStateStack: - log.warning(f"Unsupported command - begin_tag {[tag.name, type(tag)]}") + log.debug(f"Unsupported command - begin_tag {[tag.name, type(tag)]}") # self.device.begin_tag(tag) return stack @PDFCommands.add('BDC') def do_BDC(stack: PDFStateStack, tag, props=None) -> PDFStateStack: - log.warning(f"Unsupported command - begin_tag {[tag.name, type(tag), props]}") + log.debug(f"Unsupported command - begin_tag {[tag.name, type(tag), props]}") # self.device.begin_tag(tag) return stack @PDFCommands.add('EMC') def do_EMC(stack: PDFStateStack) -> PDFStateStack: # self.device.end_tag(tag) - log.warning("Unsupported command - end_tag") + log.debug("Unsupported command - end_tag") return stack @PDFCommands.add('q') diff --git a/pdfmajor/interpreter/commands/state/layout/_base.py b/pdfmajor/interpreter/commands/state/layout/_base.py index 76c3c1d..7491fa8 100644 --- a/pdfmajor/interpreter/commands/state/layout/_base.py +++ b/pdfmajor/interpreter/commands/state/layout/_base.py @@ -90,9 +90,9 @@ class LTComponent(LTItem): ## class LTContainer(LTComponent): - def __init__(self, bbox: Bbox, objs: List[LTItem] = []): + def __init__(self, bbox: Bbox, objs: List[LTItem] = None): LTComponent.__init__(self, bbox) - self._objs: List[LTItem] = objs + self._objs: List[LTItem] = [] if objs is None else objs return def __iter__(self): diff --git a/tests/samples/pdf/lorem-v1.pdf b/tests/samples/pdf/lorem-v1.pdf new file mode 100644 index 0000000..a41b113 Binary files /dev/null and b/tests/samples/pdf/lorem-v1.pdf differ diff --git a/tests/samples/pdf/lorem-v2.pdf b/tests/samples/pdf/lorem-v2.pdf new file mode 100644 index 0000000..e79ce89 Binary files /dev/null and b/tests/samples/pdf/lorem-v2.pdf differ diff --git a/tests/samples/pdf/lorem-v3.pdf b/tests/samples/pdf/lorem-v3.pdf new file mode 100644 index 0000000..fc58f3b Binary files /dev/null and b/tests/samples/pdf/lorem-v3.pdf differ diff --git a/tests/samples/pdf/lorem-v4.pdf b/tests/samples/pdf/lorem-v4.pdf new file mode 100644 index 0000000..f1718c5 Binary files /dev/null and b/tests/samples/pdf/lorem-v4.pdf differ diff --git a/tests/test_caching_err.py b/tests/test_caching_err.py new file mode 100644 index 0000000..65adc53 --- /dev/null +++ b/tests/test_caching_err.py @@ -0,0 +1,35 @@ +import os +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 LTContainer + +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 + +def count_elms(file_path: str): + count = 0 + for page in PDFInterpreter(file_path): + for item in page: + if isinstance(item, LTContainer): + count += len([*item]) + else: + count += 1 + return count + +with tqdm(desc='Cache Test', total=len(FILES)*NUM_LOOPS) as waiter: + for file_name in FILES: + waiter.set_description(f"Cache Test - [{file_name}]") + file_path = os.path.join(INPUT_FOLDER, file_name) + last_count = count_elms(file_path) + for _ in range(NUM_LOOPS): + new_count = count_elms(file_path) + assert new_count == last_count + last_count = new_count + waiter.update()