Line
This class is used to handle lines on a Page
.
It stores basic physical information (coordinates, text, links, styles, spacings).
It also allows some manipulation on lines (see try_merge()
and join_next()
).
On instanciation, the regex patterns are matched with the textual content of the
line (see is_potential_section()
and is_potential_other_index()
.)
Source code in pdfstruct/line.py
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 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 |
|
base_y
property
⚓︎
The PYMUPDF y coordinate of the origin.
bbox
property
⚓︎
The PYMUPDF bbox.
content = content
instance-attribute
⚓︎
The textual content of the line.
height
property
⚓︎
The difference between y1 and y0.
id = uuid.uuid4()
instance-attribute
⚓︎
The unique identifier for the line.
kind = None
instance-attribute
⚓︎
links = []
instance-attribute
⚓︎
The links provided by PyMuPdf,if any.
most_common_styles
property
⚓︎
Computes the style that is used on most portions of the text (joining the spans and summing their lenghts)
Returns:
Type | Description |
---|---|
dict
|
a dictionary containing the most common styles (font, color, size and flags.) |
next: Optional[Line] = None
instance-attribute
⚓︎
next_close_line
property
⚓︎
return next line if on same page and same column
Returns:
Type | Description |
---|---|
(Line) : the next line. |
next_spacing
property
⚓︎
Computes the distance between a line an the next line.
Returns:
Type | Description |
---|---|
int
|
the distance or spacing between a line and the next line |
normalize
property
⚓︎
Normalizes the text of a line : removes everything that is not a letter and converts to lowercase
Returns:
Type | Description |
---|---|
str
|
the normalized text of the line |
orientation
property
⚓︎
The PYMUPDF direction/orientation of the line.
origin
property
⚓︎
The PYMUPDF origin.
page = page
instance-attribute
⚓︎
prev: Optional[Line] = None
instance-attribute
⚓︎
prev_spacing
property
⚓︎
Computes the distance between a line an the previous line.
Returns:
Type | Description |
---|---|
int
|
the distance or spacing between a line and the previous line |
raw = raw
instance-attribute
⚓︎
The PyMuPdf raw dictionary value for the line.
raws = [self.raw]
instance-attribute
⚓︎
where = None
instance-attribute
⚓︎
width
property
⚓︎
The difference between x1 and x0.
x0
property
⚓︎
The PYMUPDF x0
x1
property
⚓︎
The PYMUPDF x1.
y0
property
⚓︎
The PYMUPDF y0
y1
property
⚓︎
The PYMUPDF y1.
__init__(content, raw, page=None, doc=None)
⚓︎
Source code in pdfstruct/line.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
__str__()
⚓︎
Displays the text according to a color scheme and the localization of the line (column). The colors depend on the type of marker. (ex: Section is red)
Returns:
Type | Description |
---|---|
str
|
the text content of the line |
Source code in pdfstruct/line.py
126 127 128 129 130 131 132 133 134 135 136 137 |
|
acceptable_numbering(numbering)
⚓︎
Compares the line with a set of regular expressions that are deemed to be acceptable numerations (for more details, see the page about Patterns).
Returns:
Type | Description |
---|---|
bool
|
if True, the line has an acceptable numeration at the beginning of the text. |
Source code in pdfstruct/line.py
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 |
|
check_with_other_index(index=None)
⚓︎
Checks whether a Line is a caption by comparing it to a normalized TOC entry.
If so, the Line becomes a caption (Other
).
Returns:
Type | Description |
---|---|
Match
|
a regex Match object. |
Source code in pdfstruct/line.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
|
check_with_section_index(index=None)
⚓︎
Compares a Line with another SecIndex Line found in a TOC by normalizing their contents and checking if the components are the same. If so, the Line becomes a Section.
Returns:
Type | Description |
---|---|
Match
|
a regex Match object. |
Source code in pdfstruct/line.py
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 |
|
delete()
⚓︎
Deletes the line and updates the next
and prev
attributes of surrounding lines.
Source code in pdfstruct/line.py
572 573 574 575 576 577 578 579 |
|
display()
⚓︎
Displays the text according to a color scheme. The colors depend on the type of marker. (ex: Section is red)
Returns:
Type | Description |
---|---|
str
|
the text content of the line |
Source code in pdfstruct/line.py
139 140 141 142 143 144 145 146 147 148 149 |
|
display_html()
⚓︎
Displays the text in HTML format.
Returns:
Type | Description |
---|---|
str
|
the HTML tagged text of the line. |
Source code in pdfstruct/line.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
is_potential_other_aux(content=None)
⚓︎
Filters the regexp with conditions before returning it to is_potential_other_index(), otherwise returns None.
Returns:
Type | Description |
---|---|
Match
|
a regex Match object. |
Source code in pdfstruct/line.py
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 |
|
is_potential_other_index(constraints=None)
⚓︎
checks whether a line is an OtherIndex. If so, the Line becomes an OtherIndex.
Source code in pdfstruct/line.py
558 559 560 561 562 563 564 565 566 567 568 569 570 |
|
is_potential_section(doc=None)
⚓︎
check if the line could be a section title, possibly with some constraints return the numbering if true otherwise None.
Returns:
Type | Description |
---|---|
str
|
the "num" group of the Match object |
Source code in pdfstruct/line.py
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 |
|
is_potential_section_aux(content=None, doc=None)
⚓︎
Filters the regexp with conditions before returning it to is_potential_section(), otherwise returns None.
Returns:
Type | Description |
---|---|
Match
|
an regex match object. |
Source code in pdfstruct/line.py
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 |
|
join_next()
⚓︎
Joins a line with the next line. Updates the new Line
object attributes.
Source code in pdfstruct/line.py
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
|
light_check_with_section_index(index=None)
⚓︎
Behaves like check_with_section_index()
but with less constraints.
If so, the Line becomes a Section.
Returns:
Type | Description |
---|---|
Match
|
a regex Match object. |
Source code in pdfstruct/line.py
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 |
|
potential_merge(other, doc=None, col_sep=None)
⚓︎
Checks whether two lines could be merged into one.
Returns:
Type | Description |
---|---|
bool
|
if True, the two lines can be merged safely. |
Source code in pdfstruct/line.py
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 |
|
same_style(other)
⚓︎
Compares the styles of two lines
Returns:
Type | Description |
---|---|
bool
|
if True, the two lines have the same styles |
Source code in pdfstruct/line.py
116 117 118 119 120 121 122 123 124 |
|
try_merge(other, doc=None, col_sep=None)
⚓︎
Merges two lines into one and updates the new Line
object.
Returns:
Type | Description |
---|---|
bool
|
if True, the merge has been done. |
Source code in pdfstruct/line.py
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 |
|
update(doc=None)
⚓︎
Checks if the line is a potential Section and a potential OtherIndex.
Source code in pdfstruct/line.py
85 86 87 88 |
|
vdelta(other=None)
⚓︎
Computes the vertical delta between a line and the closest next line.
Returns:
Type | Description |
---|---|
int
|
the vertical delta |
Source code in pdfstruct/line.py
618 619 620 621 622 623 624 625 626 627 628 629 |
|