Files
pdfplumber/tests/test_laparams.py
T
Jeremy Singer-Vine 237742039d Add --laparams to CLI (and make related tweaks)
This commit adds an `--laparams` flag to the pdfplumber CLI, giving it
more feature parity with the core library. To do so, it makes some
internal changes to `convert.py`, including changing the list of objects
to convert from *a predefined default list* to *all types extracted*.
2021-04-08 09:43:33 -04:00

48 lines
1.6 KiB
Python

#!/usr/bin/env python
import unittest
import pdfplumber
import os
import logging
logging.disable(logging.ERROR)
HERE = os.path.abspath(os.path.dirname(__file__))
class Test(unittest.TestCase):
@classmethod
def setup_class(self):
self.path = os.path.join(HERE, "pdfs/issue-13-151201DSP-Fond-581-90D.pdf")
def test_without_laparams(self):
with pdfplumber.open(self.path, laparams=None) as pdf:
objs = pdf.pages[0].objects
assert "textboxhorizontal" not in objs.keys()
assert len(objs["char"]) == 4408
def test_with_laparams(self):
with pdfplumber.open(self.path, laparams={}) as pdf:
page = pdf.pages[0]
assert len(page.textboxhorizontals) == 21
assert len(page.textlinehorizontals) == 79
assert len(page.chars) == 4408
assert "anno" not in page.objects.keys()
def test_vertical_texts(self):
path = os.path.join(HERE, "pdfs/issue-192-example.pdf")
laparams = {"detect_vertical": True}
with pdfplumber.open(path, laparams=laparams) as pdf:
page = pdf.pages[0]
assert len(page.textlinehorizontals) == 142
assert len(page.textboxhorizontals) == 74
assert len(page.textlineverticals) == 11
assert len(page.textboxverticals) == 6
def test_issue_383(self):
with pdfplumber.open(self.path, laparams={}) as pdf:
p0 = pdf.pages[0]
assert "anno" not in p0.objects.keys()
cropped = p0.crop((0, 0, 100, 100))
assert len(cropped.objects)