How to use the pdf2image.exceptions.PDFSyntaxError function in pdf2image

To help you get started, we’ve selected a few pdf2image examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Belval / pdf2image / tests.py View on Github external
def test_missingfonterror_throws(self):
        start_time = time.time()
        try:
            images_from_path = convert_from_path("./tests/test_strict.pdf", strict=True)
            raise Exception("This should not happen")
        except PDFSyntaxError as ex:
            pass

        print("test_syntaxerror_throws: {} sec".format(time.time() - start_time))
github Belval / pdf2image / pdf2image / pdf2image.py View on Github external
# Add poppler path to LD_LIBRARY_PATH
        env = os.environ.copy()
        if poppler_path is not None:
            env["LD_LIBRARY_PATH"] = poppler_path + ":" + env.get("LD_LIBRARY_PATH", "")
        # Spawn the process and save its uuid
        processes.append(
            (thread_output_file, Popen(args, env=env, stdout=PIPE, stderr=PIPE))
        )

    images = []

    for uid, proc in processes:
        data, err = proc.communicate()

        if b"Syntax Error" in err and strict:
            raise PDFSyntaxError(err.decode("utf8", "ignore"))

        if output_folder is not None:
            images += _load_from_output_folder(
                output_folder, uid, final_extension, paths_only, in_memory=auto_temp_dir
            )
        else:
            images += parse_buffer_func(data)

    if auto_temp_dir:
        shutil.rmtree(output_folder)

    return images