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
fix(pdf): force UTF-8 output encoding for pdftotext on Windows (#117, #192)
Carlos Garcia-Arisco Vilchezffc56e73de78
diff --git a/book_to_skill/parsers/pdf.py b/book_to_skill/parsers/pdf.pyindex 4c1c5b7..8708bc5 100644--- a/book_to_skill/parsers/pdf.py+++ b/book_to_skill/parsers/pdf.py@@ -79,7 +79,7 @@ def extract_with_pdftotext(pdf_path: str) -> str | None:try:pdf_path = os.path.abspath(pdf_path)result = subprocess.run(- ["pdftotext", "-layout", pdf_path, "-"],+ ["pdftotext", "-layout", "-enc", "UTF-8", pdf_path, "-"],capture_output=True, text=True, timeout=120,encoding="utf-8", errors="replace",)@@ -100,7 +100,7 @@ def looks_image_only(pdf_path: str, pages: int = 5) -> bool:return Falsetry:result = subprocess.run(- ["pdftotext", "-f", "1", "-l", str(pages), os.path.abspath(pdf_path), "-"],+ ["pdftotext", "-f", "1", "-l", str(pages), "-enc", "UTF-8", os.path.abspath(pdf_path), "-"],capture_output=True, text=True, timeout=30,encoding="utf-8", errors="replace",)diff --git a/tests/test_book_to_skill.py b/tests/test_book_to_skill.pyindex 75bbd13..86add88 100644--- a/tests/test_book_to_skill.py+++ b/tests/test_book_to_skill.py@@ -1891,7 +1891,7 @@ class TestTextEncodingDetection:class TestPdftotextEncoding:"""pdftotext output (UTF-8) is decoded as UTF-8, not the locale encoding."""- def test_pdftotext_decodes_as_utf8(self, monkeypatch):+ def test_pdftotext_requests_utf8_output(self, monkeypatch):captured = {}class _Result:@@ -1901,6 +1901,7 @@ class TestPdftotextEncoding:monkeypatch.setattr(pdf_parser.shutil, "which", lambda name: "/usr/bin/pdftotext")def fake_run(cmd, **kwargs):+ captured["cmd"] = cmdcaptured.update(kwargs)return _Result()@@ -1909,6 +1910,8 @@ class TestPdftotextEncoding:assert pdf_parser.extract_with_pdftotext("x.pdf") == "Café — naïve"assert captured.get("encoding") == "utf-8"assert captured.get("errors") == "replace"+ cmd = captured.get("cmd") or []+ assert "-enc" in cmd and cmd[cmd.index("-enc") + 1] == "UTF-8"class TestPdfPageCount: