Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.
Python agent-skillsai-agentsbook-to-skillcontext-engineeringdocument-processingedtechknowledge-baseknowledge-managementllmpdf-to-markdownragself-studystudy-tools
feat(pdf): apply pdftotext cleanup to pypdf and pdfminer paths too (#101)
Shubham Srivastava2ea067a7a001
diff --git a/book_to_skill/parsers/pdf.py b/book_to_skill/parsers/pdf.pyindex 0f5373d..6e4f3de 100644--- a/book_to_skill/parsers/pdf.py+++ b/book_to_skill/parsers/pdf.py@@ -110,7 +110,9 @@ def extract_with_pypdf(pdf_path: str) -> str | None:text_parts.append(page.extract_text() or "")except Exception:text_parts.append("")- return "\n".join(text_parts)+ # Join pages with a form feed so clean_pdftotext can strip repeated+ # per-page headers/footers, not just dehyphenate.+ return clean_pdftotext("\f".join(text_parts))except ImportError:return Noneexcept Exception as e:@@ -121,7 +123,8 @@ def extract_with_pypdf(pdf_path: str) -> str | None:def extract_with_pdfminer(pdf_path: str) -> str | None:try:from pdfminer.high_level import extract_text- return extract_text(pdf_path)+ text = extract_text(pdf_path) # already form-feed delimited per page+ return clean_pdftotext(text) if text else textexcept ImportError:return Noneexcept Exception as e:diff --git a/tests/test_book_to_skill.py b/tests/test_book_to_skill.pyindex 248e72d..538a5f1 100644--- a/tests/test_book_to_skill.py+++ b/tests/test_book_to_skill.py@@ -1738,3 +1738,36 @@ class TestCjkTokenEstimate:def test_empty_is_zero(self):assert estimate_tokens("") == 0+++class TestPdfLibsCleanup:+ """extract_with_pypdf / extract_with_pdfminer also clean their output."""++ def test_pypdf_output_is_cleaned(self, monkeypatch):+ pages = [f"HEAD\nsome informa-\ntion page {n}\n{n}" for n in (1, 2, 3)]++ class _Page:+ def __init__(self, t): self._t = t+ def extract_text(self): return self._t++ class _Reader:+ def __init__(self, f): self.pages = [_Page(p) for p in pages]++ import types+ fake = types.SimpleNamespace(PdfReader=_Reader)+ monkeypatch.setitem(sys.modules, "pypdf", fake)+ monkeypatch.setattr("builtins.open", lambda *a, **k: mock.MagicMock())++ out = pdf_parser.extract_with_pypdf("x.pdf")+ assert "information" in out # dehyphenated+ assert "HEAD" not in out # repeated header stripped++ def test_pdfminer_output_is_cleaned(self, monkeypatch):+ raw = "\f".join(f"HEAD\ncon-\ntent page {n}\n{n}" for n in (1, 2, 3))+ import types+ fake = types.SimpleNamespace(extract_text=lambda path: raw)+ monkeypatch.setitem(sys.modules, "pdfminer.high_level", fake)++ out = pdf_parser.extract_with_pdfminer("x.pdf")+ assert "content" in out+ assert "HEAD" not in out