Skip to content

Convert PDF file error [RuntimeError: Invalid code point] #1111

Open

Description

@HanseulJO-engineer

Bug

After debugging the issue, I determined that the problem originates within the line:

parsed_page = parser.parse_pdf_from_key_on_page(document_hash, page_no)

located in docling>backend>docling_parse_v2_backend.py.

  • Error Message
python3.12/site-packages/docling/backend/docling_parse_v2_backend.py", line 28, in __init__
    parsed_page = parser.parse_pdf_from_key_on_page(document_hash, page_no)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Invalid code point
  • My source code
import logging
import time

from pathlib import Path
from docling_core.types.doc import ImageRefMode, PictureItem, TableItem
from docling.datamodel.base_models import FigureElement, InputFormat, Table
from docling.datamodel.pipeline_options import PdfPipelineOptions
from docling.document_converter import DocumentConverter, PdfFormatOption
_log = logging.getLogger(__name__)
IMAGE_RESOLUTION_SCALE = 2.0


def load_document(input_source, output_dir):
    logging.basicConfig(level=logging.INFO)

    input_doc_path = input_source
    output_dir = Path(output_dir)

    pipeline_options = PdfPipelineOptions()
    pipeline_options.images_scale = IMAGE_RESOLUTION_SCALE
    pipeline_options.generate_page_images = True
    pipeline_options.generate_picture_images = True

    doc_converter = DocumentConverter(
        format_options={
            InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)
        }
    )

    start_time = time.time()

    conv_res = doc_converter.convert(input_doc_path)
    
    return conv_res


output_dir = Path("test")
input_source = Path("file_path")
documents = load_document(input_source, output_dir)

Steps to reproduce

Download this file and chage the input source Path(source code above) to attached file
연말정산.pdf

Docling version

2.25.1

Python version

python 3.12

Activity

  1. LuRe97 commented on Mar 19, 2025

    @LuRe97

    We have the exact same issue with this one page file pranger-3.pdf, in case you need another file for easier debuggig.

    UPDATE: We noticed this error behavior for several other PDF-pages printed from the german Wikipedia. What they all had in common were at least one Korean character. If we had to guess from our current knowledge it seems that some PDF Writer encode these characters in a specific way incomaptible with doclings architecture.

  2. geonhak904 commented on Mar 26, 2025

    @geonhak904

    same issue in here.

  3. widium commented on Apr 7, 2025

    @widium

    same issue in here.

  4. developers-dev commented on Apr 21, 2025

    @developers-dev

    same issue...

  5. syats commented on Apr 22, 2025

    @syats
  6. luke-z commented on Jul 28, 2025

    @luke-z

    I tried forcing ocr with do_ocr = True, this also causes the invalid code point error.

    Converting the pdf to an image beforehand seems to make it work. So it must be a PDF pipeline problem

  7. geekypilot commented on Aug 23, 2025

    @geekypilot

    I'm seeing the same issue on several PDFs. It occurs both with do_ocr = True and do_ocr = False.

  8. mayurtikundi12 commented on Sep 21, 2025

    @mayurtikundi12

    did anyone find any solution?

  9. luke-z commented on Sep 21, 2025

    @luke-z

    did anyone find any solution?

    You could try this:

    https://docling-project.github.io/docling/reference/pipeline_options/#docling.datamodel.pipeline_options.EasyOcrOptions.force_full_page_ocr

    do_ocr only does ocr if there is no layer at all.
    In our workflow we're checking the pdf for a layer and whether it's useful. If not, we set the force_full_page_ocr to true. (this creates a new pipeline, which takes one or two seconds)

  10. dorianmeric commented on Oct 13, 2025

    @dorianmeric

    Still no solution for "RuntimeError: Invalid code point" ? I get it on several of my pdfs, for no apparent reason.
    There's not even any image in the source PDF (it's just digital text).

    This person seems to have at least found a potential cause: docling-project/docling-parse#145 (comment)

  11. danielelongo14 commented on Oct 21, 2025

    @danielelongo14

    I'm still getting this issue on some documents. Only workaround I found is to find the exact page where it happens, convert to image and use the ocr on that page.

  12. KnightChaser commented on Oct 28, 2025

    @KnightChaser

    Me too, I also experienced the same issue. Got the same error without useful hints. Let me drop my error log just for someone who's interested:

    2025-10-28 15:22:14,841 - INFO - detected formats: [<InputFormat.PDF: 'pdf'>]
    2025-10-28 15:22:14,863 - INFO - Going to convert document batch...
    2025-10-28 15:22:14,864 - INFO - Initializing pipeline for StandardPdfPipeline with options hash 0736d5c3d20fb1ebbc3435380ccdf6fa
    2025-10-28 15:22:14,866 - INFO - Loading plugin 'docling_defaults'
    2025-10-28 15:22:14,867 - INFO - Registered picture descriptions: ['vlm', 'api']
    2025-10-28 15:22:14,871 - INFO - Loading plugin 'docling_defaults'
    2025-10-28 15:22:14,873 - INFO - Registered ocr engines: ['auto', 'easyocr', 'ocrmac', 'rapidocr', 'tesserocr', 'tesseract']
    /home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling/models/easyocr_model.py:68: UserWarning: Deprecated field. Better to set the `accelerator_options.device` in `pipeline_options`. When `use_gpu and accelerator_options.device == AcceleratorDevice.CUDA` the GPU is used to run EasyOCR. Otherwise, EasyOCR runs in CPU.
      warnings.warn(
    2025-10-28 15:22:16,923 - INFO - Accelerator device: 'cuda:0'
    2025-10-28 15:22:17,956 - INFO - Accelerator device: 'cuda:0'
    2025-10-28 15:22:18,323 - INFO - Processing document example_report_2.pdf
    2025-10-28 15:22:18,463 - WARNING - Encountered an error during conversion of document f917ab50ae5c1e6e0b4b683fe2a2d51ff2e39dbdc2a491f4e5321f2c3c8278ab:
    Traceback (most recent call last):
    
      File "/home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling/pipeline/base_pipeline.py", line 230, in _build_document
        for p in pipeline_pages:  # Must exhaust!
    
      File "/home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling/pipeline/base_pipeline.py", line 195, in _apply_on_pages
        yield from page_batch
    
      File "/home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling/models/page_assemble_model.py", line 70, in __call__
        for page in page_batch:
    
      File "/home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling/models/table_structure_model.py", line 177, in __call__
        for page in page_batch:
    
      File "/home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling/models/layout_model.py", line 152, in __call__
        pages = list(page_batch)
                ^^^^^^^^^^^^^^^^
    
      File "/home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling/models/easyocr_model.py", line 136, in __call__
        for page in page_batch:
    
      File "/home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling/models/page_preprocessing_model.py", line 48, in __call__
        page = self._parse_page_cells(conv_res, page)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
      File "/home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling/models/page_preprocessing_model.py", line 72, in _parse_page_cells
        page.parsed_page = page._backend.get_segmented_page()
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
      File "/home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling/backend/docling_parse_v4_backend.py", line 109, in get_segmented_page
        self._ensure_parsed()
    
      File "/home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling/backend/docling_parse_v4_backend.py", line 57, in _ensure_parsed
        seg_page = self._dp_doc.get_page(
                   ^^^^^^^^^^^^^^^^^^^^^^
    
      File "/home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling_parse/pdf_parser.py", line 162, in get_page
        doc_dict = self._parser.parse_pdf_from_key_on_page(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    RuntimeError: Invalid code point
    
    /home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling/datamodel/base_models.py:456: RuntimeWarning: Mean of empty slice
      np.nanmean(
    /home/grlee/ghrepo/pdfscribe2d/.venv/lib/python3.11/site-packages/docling/datamodel/base_models.py:465: RuntimeWarning: Mean of empty slice
      np.nanmean(
    ...
    RuntimeError: Invalid code point
    

    One noteable error message was Mean of empty slice. Maybe some mistakes or incomplete exception handling within the program logic?

  13. dolfim-ibm commented on Oct 28, 2025

    @dolfim-ibm
    Member

    @KnightChaser there have been quite some fixes in the parser. Can you please provide the output of docling --version? you should look in particular for the version of the docling-parse package.

  14. KnightChaser commented on Oct 28, 2025

    @KnightChaser

    @dolfim-ibm

    My current Docling version is 2.58.0(Docling Parse version is 4.7.0) according to the result of the command docling --version. Since the latest release of Docling Parse version is 4.7.0 as well, I think I'm using the latest available version?

    (.venv) ____@___:___________________$ docling --version
    2025-10-28 16:01:07,431 - INFO - Loading plugin 'docling_defaults'
    2025-10-28 16:01:07,433 - INFO - Registered ocr engines: ['auto', 'easyocr', 'ocrmac', 'rapidocr', 'tesserocr', 'tesseract']
    Docling version: 2.58.0
    Docling Core version: 2.49.0
    Docling IBM Models version: 3.10.1
    Docling Parse version: 4.7.0
    Python: cpython-311 (3.11.2)
    Platform: Linux-6.1.0-30-amd64-x86_64-with-glibc2.36
    
  15. dolfim-ibm commented on Oct 28, 2025

    @dolfim-ibm
    Member

    The file provided in the first comment of this issue seems to be resolved. @KnightChaser If you still get it with the latest version, can you please share a file to reproduce it?

  16. KnightChaser commented on Oct 28, 2025

    @KnightChaser

    @dolfim-ibm

    Here, I attached the problematic document.

    2025_08_report_published_kr.pdf

    I also tried to parse other random PDF documents and they all worked well with Docling smoothly. I think my first PDF document, the uploaded one, was structurally malformed, even though the visual appearance looks sane enough.

  17. kylee0643 commented on Feb 10, 2026

    @kylee0643

    I have same issue with this pdf.

    Docling version: 2.72.0
    Docling Core version: 2.64.0
    Docling IBM Models version: 3.11.0
    Docling Parse version: 4.7.3
    Python: cpython-314 (3.14.3)
    Platform: Windows-11-10.0.26200-SP0

    NASA_23_p1.pdf

  18. wittjeff commented on Oct 20, 2026

    @wittjeff
    Contributor

    I tested the four files in this thread that I could download (default.pdf from the first post, pranger-3.pdf, 2025_08_report_published_kr.pdf and NASA_23_p1.pdf) on several docling-parse releases. The PMC link in this thread returns a bot-check page, so I could not test that one.

    The crash is fixed in docling-parse 7.16.0 and later.

    docling-parse result
    4.7.3, 5.3.2, 5.3.3 RuntimeError: Invalid code point on all four files
    5.4.0 – 7.15.0 some pages fail with UnicodeDecodeError instead
    7.16.0 – 7.22.x all pages parse

    If you still see this error, check docling --version and upgrade docling-parse to 7.16.0 or later.

    Some text was still wrong after 7.16.0. Large Korean and CJK fonts use character codes between 0xD800 and 0xDFFF. The parser read those /ToUnicode codes as UTF-16 text, so it lost their mappings, and it could also overwrite the mapping of another code. On NASA_23_p1.pdf, the curly quotes came out as U+FFFD and every space in the Korean font came out as ”. The root cause is docling-project/docling-parse#145, and the fix is in docling-project/docling-parse#419.

    2025_08_report_published_kr.pdf pages 1–2 are a different case. The title fonts have no /ToUnicode entry for most of the codes they use, and pdftotext also gets no text from them. For those pages, OCR (force_full_page_ocr=True) is the only way to get the text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingpdf parsingPDF issue related to docling-parse

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions