docling-project / docling-project/docling

Can I train tesseract with my font and then use it in docling?

Open
#1,944 2 comments 0 reactions 0 assignees View on GitHub
question triage/close-stale
Dominant language
Python
Stars
66.4k
Forks
4.8k
Avg merge
2d 21h
Merged PRs (30d)
84

Description

### Question

...

Hello! I want to use OCR trained with custom data that I have, but I don't know how to do it.

I want to train tesseract with fonts that I have. But can I use my tesseract model trained like that in docling? If possible, how can I do it?

I would really appreciate it if you could explain it in detail. I will wait for your answer.
Thank you.

------------------------------------------------------------------------------

This is the code that I am currently trying.

```
@router.post("/upload")
async def upload_file(
file_info: str = Form(...),
file: UploadFile = File(...),
):
info = FileInfo.from_json(file_info)
service = DoclingService(info.file_category)
file_path = await service.save_docs(file)
task = asyncio.create_task(run_in_executor(service.process_file, file_path, info))
task.add_done_callback(error_callback)

return {"status": f"{info.file_name} processing in background..."}

```

```
class DoclingService:
def __init__(self, file_category: str):
self.doc_converter = DocumentConverter(
format_options={
InputFormat.PDF: PdfFormatOption(
pipeline_cls=StandardPdfPipeline,
backend=PyPdfiumDocumentBackend,
pipeline_options=PdfPipelineOptions(
artifacts_path=None,
accelerator_options=AcceleratorOptions(device=AcceleratorDevice.CUDA, num_threads=8)
)
),
},
)
self.collection_name = COLLECTIONS[file_category]
```

```
class PdfPipelineOptions(PaginatedPipelineOptions):
"""Options for the PDF pipeline."""

do_table_structure: bool = True # True: perform table structure extraction
do_ocr: bool = True # True: perform OCR, replace programmatic PDF text
do_code_enrichment: bool = False # True: perform code OCR
do_formula_enrichment: bool = False # True: perform formula OCR, return Latex code
do_picture_classification: bool = False # True: classify pictures in documents
do_picture_description: bool = False # True: run describe pictures in documents
force_backend_text: bool = (
False # (To be used with vlms, or other generative models)
)
# If True, text from backend will be used instead of generated text

table_structure_options: TableStructureOptions = TableStructureOptions()
ocr_options: OcrOptions = TesseractCliOcrOptions()
picture_description_options: PictureDescriptionBaseOptions = (
smolvlm_picture_description
)
layout_options: LayoutOptions = LayoutOptions()

images_scale: float = 1.0
generate_page_images: bool = False
generate_picture_images: bool = False
generate_table_images: bool = Field(
default=False,
deprecated=(
"Field `generate_table_images` is deprecated. "
"To obtain table images, set `PdfPipelineOptions.generate_page_images = True` "
"before conversion and then use the `TableItem.get_image` function."
),
)

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.