{"record":{"id":"9c620f2fbc0f64a3","repo":"VectifyAI/PageIndex","slug":"unsupported-pdf-parser-pdf-parser","errorCode":null,"errorMessage":"Unsupported PDF parser: {pdf_parser}","messagePattern":"Unsupported PDF parser: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pageindex/utils.py","lineNumber":540,"sourceCode":"            page_text = page.extract_text()\n            token_length = litellm.token_counter(model=model, text=page_text)\n            page_list.append((page_text, token_length))\n        return page_list\n    elif pdf_parser == \"PyMuPDF\":\n        import pymupdf\n        if isinstance(pdf_path, BytesIO):\n            pdf_stream = pdf_path\n            doc = pymupdf.open(stream=pdf_stream, filetype=\"pdf\")\n        elif isinstance(pdf_path, str) and os.path.isfile(pdf_path) and pdf_path.lower().endswith(\".pdf\"):\n            doc = pymupdf.open(pdf_path)\n        page_list = []\n        for page in doc:\n            page_text = page.get_text()\n            token_length = litellm.token_counter(model=model, text=page_text)\n            page_list.append((page_text, token_length))\n        return page_list\n    else:\n        raise ValueError(f\"Unsupported PDF parser: {pdf_parser}\")\n\n        \n\ndef get_text_of_pdf_pages(pdf_pages, start_page, end_page):\n    if start_page is None or end_page is None:\n        return \"\"\n    text = \"\"\n    for page_num in range(start_page-1, end_page):\n        text += pdf_pages[page_num][0]\n    return text\n\ndef get_text_of_pdf_pages_with_labels(pdf_pages, start_page, end_page):\n    if start_page is None or end_page is None:\n        return \"\"\n    text = \"\"\n    for page_num in range(start_page-1, end_page):\n        text += f\"<physical_index_{page_num+1}>\\n{pdf_pages[page_num][0]}\\n<physical_index_{page_num+1}>\\n\"\n    return text","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/VectifyAI/PageIndex/blob/afb5e119766630af6014b04fe8b53357527bc05e/pageindex/utils.py#L522-L558","documentation":"get_page_tokens supports only specific PDF parser backends (e.g. pymupdf vs others selected by the pdf_parser option). Passing any other string raises ValueError because there is no code path to extract per-page text for that parser name.","triggerScenarios":"Calling page_index_main (or configuring the pipeline) with pdf_parser set to an unsupported value, e.g. 'pdfplumber', 'pypdf', or a typo like 'pymupdf ' with trailing space.","commonSituations":"Copy-pasted config from another tool that uses a different parser name, typo in YAML config, or assuming a parser that a newer/older library version supports.","solutions":["Check the function's if/elif branches just above the raise to see the accepted parser names (e.g. 'pymupdf')","Set pdf_parser to a supported value or omit it to use the default","Trim whitespace/casing mistakes in the config value"],"exampleFix":"# before\npage_index_main(pdf, pdf_parser='pdfplumber')\n# after\npage_index_main(pdf, pdf_parser='pymupdf')","handlingStrategy":"validation","validationCode":"SUPPORTED_PARSERS = {'pymupdf'}  # keep in sync with get_page_tokens\nif cfg.get('pdf_parser') not in SUPPORTED_PARSERS | {None}:\n    raise ValueError(f\"bad pdf_parser: {cfg.get('pdf_parser')!r}\")","typeGuard":"def is_supported_parser(p):\n    return p is None or p in {'pymupdf'}","tryCatchPattern":"try:\n    page_index_main(pdf, pdf_parser=parser)\nexcept ValueError as e:\n    if 'Unsupported PDF parser' in str(e):\n        page_index_main(pdf)  # fall back to default parser\n    else:\n        raise","preventionTips":["Centralize parser choice in one validated config constant","Validate config keys before starting a long indexing job"],"tags":["config","pdf","invalid-argument","validation"],"backgroundTag":"unsupported-option-value","analyzedSha":"afb5e119766630af6014b04fe8b53357527bc05e","analyzedAt":"2026-08-27T11:20:48.519Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}