diff --git a/camelot/cli.py b/camelot/cli.py index cc349176..8aad5eb4 100644 --- a/camelot/cli.py +++ b/camelot/cli.py @@ -290,6 +290,13 @@ def stream(c, *args, **kwargs): columns = list(kwargs["columns"]) kwargs["columns"] = None if not columns else columns + margins = conf.pop('margins') + + if margins is None: + layout_kwargs = {} + else: + layout_kwargs = {"char_margin": margins[0], "line_margin": margins[1], "word_margin": margins[2]} + if plot_type is not None: if not _HAS_MPL: raise ImportError("matplotlib is required for plotting.") @@ -300,7 +307,7 @@ def stream(c, *args, **kwargs): raise click.UsageError("Please specify output file format using --format") tables = read_pdf( - filepath, pages=pages, flavor="stream", suppress_stdout=quiet, **kwargs + filepath, pages=pages, flavor="stream", suppress_stdout=quiet, layout_kwargs=layout_kwargs, **kwargs ) click.echo(f"Found {tables.n} tables") if plot_type is not None: diff --git a/tests/test_cli.py b/tests/test_cli.py index 0903dfa3..86f7c0aa 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -61,6 +61,18 @@ def test_cli_stream(testdir): format_error = "Please specify output file format using --format" assert format_error in result.output + result = runner.invoke( + cli, [ "--margins", "1.5", "0.5", "0.8", "--format", "csv", "--output", outfile, "stream", infile] + ) + assert result.exit_code == 0 + assert result.output == "Found 1 tables\n" + + result = runner.invoke( + cli, ["--margins", "1.5", "0.5", "--format", "csv", "--output", outfile, "stream", infile] + ) + output_error = "Error: Invalid value for '-M' / '--margins': '--format' is not a valid float." + assert output_error in result.output + @skip_on_windows def test_cli_parallel(testdir):