Parsers API Reference¶
Complete API documentation for all Doctra parsers.
StructuredPDFParser¶
The base parser for comprehensive PDF document processing.
doctra.parsers.structured_pdf_parser.StructuredPDFParser
¶
Comprehensive PDF parser for extracting all types of content.
Processes PDF documents to extract text, tables, charts, and figures.
Supports OCR for text extraction and optional VLM processing for
converting visual elements into structured data.
Features automatic detection and merging of tables split across pages
using proximity detection and LSD-based structure analysis.
:param vlm: VLM engine instance (VLMStructuredExtractor). If None, VLM processing is disabled.
:param layout_model_name: Layout detection model name (default: "PP-DocLayout_plus-L")
:param dpi: DPI for PDF rendering (default: 200)
:param min_score: Minimum confidence score for layout detection (default: 0.0)
:param ocr_engine: OCR engine instance (PytesseractOCREngine or PaddleOCREngine).
If None, creates a default PytesseractOCREngine with lang="eng", psm=4, oem=3.
:param box_separator: Separator between text boxes in output (default: "
") :param merge_split_tables: Whether to detect and merge split tables (default: False) :param bottom_threshold_ratio: Ratio for "too close to bottom" detection (default: 0.20) :param top_threshold_ratio: Ratio for "too close to top" detection (default: 0.10) :param max_gap_ratio: Maximum allowed gap between tables (default: 0.05) :param column_alignment_tolerance: Pixel tolerance for column alignment (default: 10.0) :param min_merge_confidence: Minimum confidence score for merging (default: 0.7)
Source code in doctra/parsers/structured_pdf_parser.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
__init__(*, vlm=None, layout_model_name='PP-DocLayout_plus-L', dpi=200, min_score=0.0, ocr_engine=None, box_separator='\n', merge_split_tables=False, bottom_threshold_ratio=0.2, top_threshold_ratio=0.15, max_gap_ratio=0.25, column_alignment_tolerance=10.0, min_merge_confidence=0.65)
¶
Initialize the StructuredPDFParser with processing configuration.
Also suppresses noisy DEBUG logs from external libraries.
:param vlm: VLM engine instance (VLMStructuredExtractor). If None, VLM processing is disabled.
:param layout_model_name: Layout detection model name (default: "PP-DocLayout_plus-L")
:param dpi: DPI for PDF rendering (default: 200)
:param min_score: Minimum confidence score for layout detection (default: 0.0)
:param ocr_engine: OCR engine instance (PytesseractOCREngine or PaddleOCREngine).
If None, creates a default PytesseractOCREngine with lang="eng", psm=4, oem=3.
:param box_separator: Separator between text boxes in output (default: "
") :param merge_split_tables: Whether to detect and merge split tables (default: False) :param bottom_threshold_ratio: Ratio for "too close to bottom" detection (default: 0.20) :param top_threshold_ratio: Ratio for "too close to top" detection (default: 0.15) :param max_gap_ratio: Maximum allowed gap between tables (default: 0.25, accounts for headers/footers) :param column_alignment_tolerance: Pixel tolerance for column alignment (default: 10.0) :param min_merge_confidence: Minimum confidence score for merging (default: 0.65)
Source code in doctra/parsers/structured_pdf_parser.py
display_pages_with_boxes(pdf_path, num_pages=3, cols=2, page_width=800, spacing=40, save_path=None)
¶
Display the first N pages of a PDF with bounding boxes and labels overlaid in a modern grid layout.
Creates a visualization showing layout detection results with bounding boxes, labels, and confidence scores overlaid on the PDF pages in a grid format.
:param pdf_path: Path to the input PDF file :param num_pages: Number of pages to display (default: 3) :param cols: Number of columns in the grid layout (default: 2) :param page_width: Width to resize each page to in pixels (default: 800) :param spacing: Spacing between pages in pixels (default: 40) :param save_path: Optional path to save the visualization (if None, displays only) :return: None
Source code in doctra/parsers/structured_pdf_parser.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
parse(pdf_path)
¶
Parse a PDF document and extract all content types.
:param pdf_path: Path to the input PDF file :return: None
Source code in doctra/parsers/structured_pdf_parser.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
EnhancedPDFParser¶
Enhanced parser with image restoration capabilities.
doctra.parsers.enhanced_pdf_parser.EnhancedPDFParser
¶
Bases: StructuredPDFParser
Enhanced PDF Parser with Image Restoration capabilities.
Extends the StructuredPDFParser with DocRes image restoration to improve
document quality before processing. This is particularly useful for:
- Scanned documents with shadows or distortion
- Low-quality PDFs that need enhancement
- Documents with perspective issues
:param use_image_restoration: Whether to apply DocRes image restoration (default: True)
:param restoration_task: DocRes task to use ("dewarping", "deshadowing", "appearance", "deblurring", "binarization", "end2end", default: "appearance")
:param restoration_device: Device for DocRes processing ("cuda", "cpu", or None for auto-detect, default: None)
:param restoration_dpi: DPI for restoration processing (default: 200)
:param vlm: VLM engine instance (VLMStructuredExtractor). If None, VLM processing is disabled.
:param layout_model_name: Layout detection model name (default: "PP-DocLayout_plus-L")
:param dpi: DPI for PDF rendering (default: 200)
:param min_score: Minimum confidence score for layout detection (default: 0.0)
:param ocr_engine: OCR engine instance (PytesseractOCREngine or PaddleOCREngine).
If None, creates a default PytesseractOCREngine with lang="eng", psm=4, oem=3.
:param box_separator: Separator between text boxes in output (default: "
") :param merge_split_tables: Whether to detect and merge split tables (default: False) :param bottom_threshold_ratio: Ratio for "too close to bottom" detection (default: 0.20) :param top_threshold_ratio: Ratio for "too close to top" detection (default: 0.15) :param max_gap_ratio: Maximum allowed gap between tables (default: 0.25) :param column_alignment_tolerance: Pixel tolerance for column alignment (default: 10.0) :param min_merge_confidence: Minimum confidence score for merging (default: 0.65)
Source code in doctra/parsers/enhanced_pdf_parser.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 | |
__init__(*, use_image_restoration=True, restoration_task='appearance', restoration_device=None, restoration_dpi=200, vlm=None, layout_model_name='PP-DocLayout_plus-L', dpi=200, min_score=0.0, ocr_engine=None, box_separator='\n', merge_split_tables=False, bottom_threshold_ratio=0.2, top_threshold_ratio=0.15, max_gap_ratio=0.25, column_alignment_tolerance=10.0, min_merge_confidence=0.65)
¶
Initialize the Enhanced PDF Parser with image restoration capabilities.
Source code in doctra/parsers/enhanced_pdf_parser.py
get_restoration_info()
¶
Get information about the current restoration configuration.
:return: Dictionary with restoration settings and status
Source code in doctra/parsers/enhanced_pdf_parser.py
parse(pdf_path, enhanced_output_dir=None)
¶
Parse a PDF document with optional image restoration.
:param pdf_path: Path to the input PDF file :param enhanced_output_dir: Directory for enhanced images (if None, uses default) :return: None
Source code in doctra/parsers/enhanced_pdf_parser.py
restore_pdf_only(pdf_path, output_path=None, task=None)
¶
Apply DocRes restoration to a PDF without parsing.
:param pdf_path: Path to the input PDF file :param output_path: Path for the enhanced PDF (if None, auto-generates) :param task: DocRes restoration task (if None, uses instance default) :return: Path to the enhanced PDF or None if failed
Source code in doctra/parsers/enhanced_pdf_parser.py
ChartTablePDFParser¶
Specialized parser for extracting charts and tables.
doctra.parsers.table_chart_extractor.ChartTablePDFParser
¶
Specialized PDF parser for extracting charts and tables.
Focuses specifically on chart and table extraction from PDF documents, with optional VLM (Vision Language Model) processing to convert visual elements into structured data.
:param extract_charts: Whether to extract charts from the document (default: True) :param extract_tables: Whether to extract tables from the document (default: True) :param vlm: VLM engine instance (VLMStructuredExtractor). If None, VLM processing is disabled. :param layout_model_name: Layout detection model name (default: "PP-DocLayout_plus-L") :param dpi: DPI for PDF rendering (default: 200) :param min_score: Minimum confidence score for layout detection (default: 0.0) :param merge_split_tables: Whether to detect and merge split tables (default: False) :param bottom_threshold_ratio: Ratio for "too close to bottom" detection (default: 0.20) :param top_threshold_ratio: Ratio for "too close to top" detection (default: 0.15) :param max_gap_ratio: Maximum allowed gap between tables (default: 0.25, accounts for headers/footers) :param column_alignment_tolerance: Pixel tolerance for column alignment (default: 10.0) :param min_merge_confidence: Minimum confidence score for merging (default: 0.65)
Source code in doctra/parsers/table_chart_extractor.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
__init__(*, extract_charts=True, extract_tables=True, vlm=None, layout_model_name='PP-DocLayout_plus-L', dpi=200, min_score=0.0, merge_split_tables=False, bottom_threshold_ratio=0.2, top_threshold_ratio=0.15, max_gap_ratio=0.25, column_alignment_tolerance=10.0, min_merge_confidence=0.65)
¶
Initialize the ChartTablePDFParser with extraction configuration.
:param extract_charts: Whether to extract charts from the document (default: True) :param extract_tables: Whether to extract tables from the document (default: True) :param vlm: VLM engine instance (VLMStructuredExtractor). If None, VLM processing is disabled. :param layout_model_name: Layout detection model name (default: "PP-DocLayout_plus-L") :param dpi: DPI for PDF rendering (default: 200) :param min_score: Minimum confidence score for layout detection (default: 0.0) :param merge_split_tables: Whether to detect and merge split tables (default: False) :param bottom_threshold_ratio: Ratio for "too close to bottom" detection (default: 0.20) :param top_threshold_ratio: Ratio for "too close to top" detection (default: 0.15) :param max_gap_ratio: Maximum allowed gap between tables (default: 0.25, accounts for headers/footers) :param column_alignment_tolerance: Pixel tolerance for column alignment (default: 10.0) :param min_merge_confidence: Minimum confidence score for merging (default: 0.65)
Source code in doctra/parsers/table_chart_extractor.py
parse(pdf_path, output_base_dir='outputs')
¶
Parse a PDF document and extract charts and/or tables.
:param pdf_path: Path to the input PDF file :param output_base_dir: Base directory for output files (default: "outputs") :return: None
Source code in doctra/parsers/table_chart_extractor.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
PaddleOCRVLPDFParser¶
End-to-end document parser using PaddleOCRVL Vision-Language Model.
doctra.parsers.paddleocr_vl_parser.PaddleOCRVLPDFParser
¶
PDF Parser using PaddleOCRVL for end-to-end document parsing.
Combines PaddleOCRVL's vision-language model capabilities with: - DocRes image restoration for enhanced document quality - Split table detection and merging across pages
:param use_image_restoration: Whether to apply DocRes image restoration (default: True) :param restoration_task: DocRes task to use (default: "appearance") :param restoration_device: Device for DocRes processing (default: None for auto-detect) :param restoration_dpi: DPI for restoration processing (default: 200) :param use_chart_recognition: Enable chart recognition in PaddleOCRVL (default: True) :param use_doc_orientation_classify: Enable document orientation classification (default: False) :param use_doc_unwarping: Enable document unwarping (default: False) :param use_layout_detection: Enable layout detection (default: True) :param device: Device for PaddleOCRVL processing ("gpu" or "cpu", default: "gpu") :param merge_split_tables: Whether to detect and merge split tables (default: True) :param bottom_threshold_ratio: Ratio for "too close to bottom" detection (default: 0.20) :param top_threshold_ratio: Ratio for "too close to top" detection (default: 0.15) :param max_gap_ratio: Maximum allowed gap between tables (default: 0.25) :param column_alignment_tolerance: Pixel tolerance for column alignment (default: 10.0) :param min_merge_confidence: Minimum confidence score for merging (default: 0.65)
Source code in doctra/parsers/paddleocr_vl_parser.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 | |
__init__(*, use_image_restoration=True, restoration_task='appearance', restoration_device=None, restoration_dpi=200, use_chart_recognition=True, use_doc_orientation_classify=False, use_doc_unwarping=False, use_layout_detection=True, device='gpu', merge_split_tables=True, bottom_threshold_ratio=0.2, top_threshold_ratio=0.15, max_gap_ratio=0.25, column_alignment_tolerance=10.0, min_merge_confidence=0.65)
¶
Initialize the PaddleOCRVL PDF Parser.
Source code in doctra/parsers/paddleocr_vl_parser.py
parse(pdf_path, output_dir=None)
¶
Parse a PDF document using PaddleOCRVL.
:param pdf_path: Path to the input PDF file :param output_dir: Output directory (if None, uses default) :return: None
Source code in doctra/parsers/paddleocr_vl_parser.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
StructuredDOCXParser¶
Comprehensive parser for Microsoft Word documents (.docx files).
doctra.parsers.structured_docx_parser.StructuredDOCXParser
¶
Comprehensive DOCX parser for extracting all types of content.
Processes DOCX documents to extract text, tables, images, and figures. Supports structured data extraction and optional VLM processing for enhanced content analysis.
:param vlm: VLM engine instance (VLMStructuredExtractor). If None, VLM processing is disabled. :param extract_images: Whether to extract embedded images (default: True) :param preserve_formatting: Whether to preserve text formatting in output (default: True) :param table_detection: Whether to detect and extract tables (default: True)
Source code in doctra/parsers/structured_docx_parser.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 | |
__init__(*, vlm=None, extract_images=True, preserve_formatting=True, table_detection=True, export_excel=True)
¶
Initialize the StructuredDOCXParser with processing configuration.
:param vlm: VLM engine instance (VLMStructuredExtractor). If None, VLM processing is disabled. :param extract_images: Whether to extract embedded images (default: True) :param preserve_formatting: Whether to preserve text formatting in output (default: True) :param table_detection: Whether to detect and extract tables (default: True) :param export_excel: Whether to export tables to Excel file (default: True)
Source code in doctra/parsers/structured_docx_parser.py
parse(docx_path)
¶
Parse a DOCX document and extract all content.
:param docx_path: Path to the DOCX file to parse
Source code in doctra/parsers/structured_docx_parser.py
Quick Reference¶
StructuredPDFParser¶
from doctra import StructuredPDFParser
from doctra.engines.ocr import PytesseractOCREngine, PaddleOCREngine
from doctra.engines.vlm.service import VLMStructuredExtractor
# Initialize OCR engine (optional - defaults to PyTesseract if None)
ocr_engine = PytesseractOCREngine(lang="eng", psm=4, oem=3)
# Initialize VLM engine (optional - None to disable VLM)
vlm_engine = VLMStructuredExtractor(
vlm_provider="openai",
vlm_model="gpt-4o", # Optional
api_key="your-api-key"
)
parser = StructuredPDFParser(
# Layout Detection
layout_model_name: str = "PP-DocLayout_plus-L",
dpi: int = 200,
min_score: float = 0.0,
# OCR Engine (pass initialized engine instance)
ocr_engine: Optional[Union[PytesseractOCREngine, PaddleOCREngine]] = None,
# VLM Engine (pass initialized engine instance)
vlm: Optional[VLMStructuredExtractor] = None,
# Split Table Merging
merge_split_tables: bool = False,
bottom_threshold_ratio: float = 0.20,
top_threshold_ratio: float = 0.15,
max_gap_ratio: float = 0.25,
column_alignment_tolerance: float = 10.0,
min_merge_confidence: float = 0.65,
# Output Settings
box_separator: str = "\n"
)
# Parse document
parser.parse(
pdf_path: str,
output_base_dir: str = "outputs"
)
# Visualize layout
parser.display_pages_with_boxes(
pdf_path: str,
num_pages: int = 3,
cols: int = 2,
page_width: int = 800,
spacing: int = 40,
save_path: str = None
)
EnhancedPDFParser¶
from doctra import EnhancedPDFParser
from doctra.engines.vlm.service import VLMStructuredExtractor
# Initialize VLM engine (optional)
vlm_engine = VLMStructuredExtractor(
vlm_provider="openai",
api_key="your-api-key"
)
parser = EnhancedPDFParser(
# Image Restoration
use_image_restoration: bool = True,
restoration_task: str = "appearance",
restoration_device: str = None,
restoration_dpi: int = 200,
# VLM Engine (pass initialized engine instance)
vlm: Optional[VLMStructuredExtractor] = None,
# Layout Detection
layout_model_name: str = "PP-DocLayout_plus-L",
dpi: int = 200,
min_score: float = 0.0,
# OCR Engine (optional)
ocr_engine: Optional[Union[PytesseractOCREngine, PaddleOCREngine]] = None,
# Split Table Merging
merge_split_tables: bool = False,
bottom_threshold_ratio: float = 0.20,
top_threshold_ratio: float = 0.15,
max_gap_ratio: float = 0.25,
column_alignment_tolerance: float = 10.0,
min_merge_confidence: float = 0.65,
# Output Settings
box_separator: str = "\n"
)
# Parse with enhancement
parser.parse(
pdf_path: str,
output_base_dir: str = "outputs"
)
ChartTablePDFParser¶
from doctra import ChartTablePDFParser
from doctra.engines.vlm.service import VLMStructuredExtractor
# Initialize VLM engine (optional)
vlm_engine = VLMStructuredExtractor(
vlm_provider="openai",
api_key="your-api-key"
)
parser = ChartTablePDFParser(
# Extraction Settings
extract_charts: bool = True,
extract_tables: bool = True,
# VLM Engine (pass initialized engine instance)
vlm: Optional[VLMStructuredExtractor] = None,
# Layout Detection
layout_model_name: str = "PP-DocLayout_plus-L",
dpi: int = 200,
min_score: float = 0.0,
# Split Table Merging
merge_split_tables: bool = False,
bottom_threshold_ratio: float = 0.20,
top_threshold_ratio: float = 0.15,
max_gap_ratio: float = 0.25,
column_alignment_tolerance: float = 10.0,
min_merge_confidence: float = 0.65,
)
# Extract charts/tables
parser.parse(
pdf_path: str,
output_base_dir: str = "outputs"
)
StructuredDOCXParser¶
from doctra import StructuredDOCXParser
from doctra.engines.vlm.service import VLMStructuredExtractor
# Initialize VLM engine (optional)
vlm_engine = VLMStructuredExtractor(
vlm_provider="openai",
api_key="your-api-key"
)
parser = StructuredDOCXParser(
# VLM Engine (pass initialized engine instance)
vlm: Optional[VLMStructuredExtractor] = None,
# Processing Options
extract_images: bool = True,
preserve_formatting: bool = True,
table_detection: bool = True,
export_excel: bool = True
)
# Parse DOCX document
parser.parse(
docx_path: str
)
Parameter Reference¶
Layout Detection Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
layout_model_name |
str | "PP-DocLayout_plus-L" | PaddleOCR layout detection model |
dpi |
int | 200 | Image resolution for rendering PDF pages |
min_score |
float | 0.0 | Minimum confidence score for detected elements |
OCR Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
ocr_engine |
Optional[Union[PytesseractOCREngine, PaddleOCREngine]] |
None |
OCR engine instance. If None, creates a default PytesseractOCREngine with lang="eng", psm=4, oem=3 |
OCR Engine Configuration:
OCR engines must be initialized externally and passed to the parser. This uses a dependency injection pattern for clearer API design.
PytesseractOCREngine Parameters:
- lang (str, default: "eng"): Tesseract language code (e.g., "eng", "fra", "spa", "deu", or multiple: "eng+fra")
- psm (int, default: 4): Page segmentation mode (3=Automatic, 4=Single column, 6=Uniform block, 11=Sparse text, 12=Sparse with OSD)
- oem (int, default: 3): OCR engine mode (0=Legacy, 1=Neural nets LSTM, 3=Default both)
- extra_config (str, default: ""): Additional Tesseract configuration string
PaddleOCREngine Parameters:
- device (str, default: "gpu"): Device for OCR processing ("cpu" or "gpu")
- use_doc_orientation_classify (bool, default: False): Enable document orientation classification
- use_doc_unwarping (bool, default: False): Enable text image rectification
- use_textline_orientation (bool, default: False): Enable text line orientation classification
Example:
from doctra.engines.ocr import PytesseractOCREngine, PaddleOCREngine
# PyTesseract
tesseract_ocr = PytesseractOCREngine(lang="eng", psm=4, oem=3)
parser = StructuredPDFParser(ocr_engine=tesseract_ocr)
# PaddleOCR
paddle_ocr = PaddleOCREngine(device="gpu")
parser = StructuredPDFParser(ocr_engine=paddle_ocr)
Note: When using PaddleOCR, PaddleOCR 3.0's PP-OCRv5_server model is used by default. Models are automatically downloaded on first use.
VLM Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
vlm |
Optional[VLMStructuredExtractor] |
None |
VLM engine instance. If None, VLM processing is disabled. |
VLM Engine Configuration:
VLM engines must be initialized externally and passed to the parser. This uses a dependency injection pattern for clearer API design.
VLMStructuredExtractor Parameters:
- vlm_provider (str, required): VLM provider to use ("openai", "gemini", "anthropic", "openrouter", "qianfan", "ollama")
- vlm_model (str, optional): Model name to use (defaults to provider-specific defaults)
- api_key (str, optional): API key for the VLM provider (required for all providers except Ollama)
Example:
from doctra.engines.vlm.service import VLMStructuredExtractor
# Initialize VLM engine
vlm_engine = VLMStructuredExtractor(
vlm_provider="openai",
vlm_model="gpt-4o", # Optional
api_key="your-api-key"
)
# Pass to parser
parser = StructuredPDFParser(vlm=vlm_engine)
Image Restoration Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
use_image_restoration |
bool | True | Enable image restoration |
restoration_task |
str | "appearance" | Restoration task type |
restoration_device |
str | None | Device: "cuda", "cpu", or None (auto-detect) |
restoration_dpi |
int | 200 | DPI for restoration processing |
Split Table Merging Parameters¶
Available for both StructuredPDFParser and EnhancedPDFParser.
| Parameter | Type | Default | Description |
|---|---|---|---|
merge_split_tables |
bool | False | Enable automatic detection and merging of tables split across pages |
bottom_threshold_ratio |
float | 0.20 | Ratio (0-1) for detecting tables near bottom of page. Tables within this ratio from the bottom are considered candidates. |
top_threshold_ratio |
float | 0.15 | Ratio (0-1) for detecting tables near top of page. Tables within this ratio from the top are considered candidates. |
max_gap_ratio |
float | 0.25 | Maximum allowed gap between table segments as ratio of page height. Accounts for headers, footers, and page margins. |
column_alignment_tolerance |
float | 10.0 | Pixel tolerance for column alignment validation when comparing table structures. |
min_merge_confidence |
float | 0.65 | Minimum confidence score (0-1) required to merge two table segments. Higher values are more conservative. |
Extraction Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
extract_charts |
bool | True | Extract chart elements |
extract_tables |
bool | True | Extract table elements |
DOCX Processing Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
extract_images |
bool | True | Extract embedded images from DOCX |
preserve_formatting |
bool | True | Preserve text formatting in output |
table_detection |
bool | True | Detect and extract tables |
export_excel |
bool | True | Export tables to Excel file |
Output Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
box_separator |
str | "\n" | Separator between detected elements |
Return Values¶
parse() Method¶
Returns: None
Generates output files in the specified output_base_dir:
outputs/
βββ <document_name>/
βββ full_parse/ # or 'enhanced_parse/', 'structured_parsing/'
β βββ result.md
β βββ result.html
β βββ tables.xlsx # If VLM enabled
β βββ tables.html # If VLM enabled
β βββ vlm_items.json # If VLM enabled
β βββ images/
β βββ figures/
β βββ charts/
β βββ tables/
For DOCX parsing, generates:
outputs/
βββ <document_name>/
βββ document.md
βββ document.html
βββ tables.xlsx # With Table of Contents
βββ images/
βββ image1.png
βββ image2.jpg
βββ ...
display_pages_with_boxes() Method¶
Returns: None
Displays or saves visualization of layout detection.
Error Handling¶
All parsers may raise:
FileNotFoundError: PDF file not foundValueError: Invalid parameter valuesRuntimeError: Processing errors (e.g., Poppler not found)APIError: VLM API errors (when VLM enabled)
Example error handling:
from doctra import StructuredPDFParser
parser = StructuredPDFParser()
try:
parser.parse("document.pdf")
except FileNotFoundError:
print("PDF file not found!")
except ValueError as e:
print(f"Invalid parameter: {e}")
except RuntimeError as e:
print(f"Processing error: {e}")
Examples¶
See the Examples section for detailed usage examples.