-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSplitRange.php
More file actions
67 lines (56 loc) · 2.02 KB
/
Copy pathSplitRange.php
File metadata and controls
67 lines (56 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
<?php
declare(strict_types=1);
namespace Mindee\V2\Product\Split;
use Mindee\Input\LocalInputSource;
use Mindee\Pdf\ExtractedPdf;
use Mindee\V2\FileOperations\Split;
use Mindee\V2\Product\Extraction\ExtractionResponse;
use Stringable;
/**
* A single document as identified when splitting a multi-document source file.
*/
class SplitRange implements Stringable
{
/**
* @var integer[] 0-based page indexes, where the first integer indicates the start page and the second integer
* indicates the end page.
*/
public array $pageRange;
/**
* @var string Type or classification of the detected object.
*/
public string $documentType;
/**
* @var ExtractionResponse|null $extractionResponse The extraction response associated with the split.
*/
public ?ExtractionResponse $extractionResponse;
/**
* @param array<string, int|float|string|bool|null|array<array-key, mixed>> $rawResponse Raw server response array.
*/
public function __construct(array $rawResponse)
{
$this->pageRange = $rawResponse['page_range'];
$this->documentType = $rawResponse['document_type'];
$this->extractionResponse = isset($rawResponse['extraction_response'])
? new ExtractionResponse($rawResponse['extraction_response']) : null;
}
/**
* @return string String representation.
*/
public function __toString(): string
{
$pageRangeStr = implode(",", $this->pageRange);
return "* :Page Range: $pageRangeStr\n :Document Type: $this->documentType";
}
/**
* Extracts a single page from the input source based on the specified page range.
*
* @param LocalInputSource $inputSource The input source from which to extract the page.
* @return ExtractedPdf The extracted PDF.
*/
public function extractFromInputSource(LocalInputSource $inputSource): ExtractedPdf
{
$splitter = new Split($inputSource);
return $splitter->extractSingleSplit($this->pageRange);
}
}