PdfTextExtractor
final class \
- Extends
- AbstractTextExtractor
- Implements
- PartitionedTextExtractorInterface
Extracts text of PDF files with "pdfinfo" and "pdftotext", optionally divided into page ranges according to the "pdf_mode" configuration.
Internal
Attributes
Table of Contents
Interfaces
- PartitionedTextExtractorInterface
- A text extractor for documents which are indexed in several parts, such as the page ranges of a PDF. Every part becomes an index entry of its own.
Properties
Methods
- __construct() : mixed
- calculateParts() : array<int, string>
- Divides a number of pages into page ranges. A positive PDF mode is the number of pages per range, a negative one the (absolute) number of ranges, zero means one range.
- canExtractText() : bool
- Checks if the given file can be read by this extractor
- extractStructuredText() : ExtractedText
- The actual text extraction, returning the text and the metadata of the resource
- extractText() : string
- The actual text extraction, returning a string of the file's content
- getSupportedMimeTypes() : array<int, string>
- Lowercase MIME types which this extractor can currently handle. Generic detections, such as "application/zip" for a Word document, are resolved to the concrete MIME type by the file extension via $GLOBALS['TYPO3_CONF_VARS']['SYS']['FileInfo']['mimeTypeCompatibility'], so an extractor does not need to declare them.
- removeEndJunk() : string
- Removes some strange char(12) characters and line breaks that tend to occur at the end of external tool output.
- splitPdfInfo() : array<string, string>
- Analysing the output lines of "pdfinfo" into an array of the first occurrence of each key.
- withPartitionedDocument() : T
- The parts are page ranges such as "1-5", or "0" for the whole document.
- checkRequiredTools() : bool
- extractFromLocalFile() : ExtractedText
- getMimeTypes() : array<int, string>
- getMissingTools() : array<int, string>
- getRequiredTools() : array<int, "pdfinfo"|"pdftotext"|"catdoc"|"ppthtml"|"xlhtml"|"unzip"|"unrtf">
- getToolPath() : string
- joinOutput() : string
- stripXmlTags() : string
- withLocalFile() : T
- Provides a local copy of the file to the callback, and cleans up afterwards.
Properties
$commandExecutor read-only
protected
ExternalCommandExecutor
$commandExecutor
$toolConfiguration read-only
protected
ExternalToolConfiguration
$toolConfiguration
Methods
__construct()
public
__construct(ExternalToolConfiguration $toolConfiguration, ExternalCommandExecutor $commandExecutor) : mixed
Parameters
- $toolConfiguration : ExternalToolConfiguration
- $commandExecutor : ExternalCommandExecutor
calculateParts()
Divides a number of pages into page ranges. A positive PDF mode is the number of pages per range, a negative one the (absolute) number of ranges, zero means one range.
public
static calculateParts(int $pages, int $pdfMode) : array<int, string>
Parameters
- $pages : int
- $pdfMode : int
Return values
array<int, string>canExtractText()
Checks if the given file can be read by this extractor
public
canExtractText(FileInterface $file) : bool
Parameters
- $file : FileInterface
Return values
boolextractStructuredText()
The actual text extraction, returning the text and the metadata of the resource
public
extractStructuredText(SystemResourceInterface $file) : ExtractedText
Parameters
- $file : SystemResourceInterface
Return values
ExtractedTextextractText()
The actual text extraction, returning a string of the file's content
public
extractText(FileInterface $file) : string
Parameters
- $file : FileInterface
Return values
stringgetSupportedMimeTypes()
Lowercase MIME types which this extractor can currently handle. Generic detections, such as "application/zip" for a Word document, are resolved to the concrete MIME type by the file extension via $GLOBALS['TYPO3_CONF_VARS']['SYS']['FileInfo']['mimeTypeCompatibility'], so an extractor does not need to declare them.
public
getSupportedMimeTypes() : array<int, string>
Return values
array<int, string>removeEndJunk()
Removes some strange char(12) characters and line breaks that tend to occur at the end of external tool output.
public
static removeEndJunk(string $string) : string
Parameters
- $string : string
Return values
stringsplitPdfInfo()
Analysing the output lines of "pdfinfo" into an array of the first occurrence of each key.
public
splitPdfInfo(array<int, string> $pdfInfoArray) : array<string, string>
Parameters
- $pdfInfoArray : array<int, string>
Return values
array<string, string>withPartitionedDocument()
The parts are page ranges such as "1-5", or "0" for the whole document.
public
withPartitionedDocument(SystemResourceInterface $file, Closure $callback) : T
Parameters
- $file : SystemResourceInterface
- $callback : Closure
Return values
TcheckRequiredTools()
protected
checkRequiredTools(SystemResourceInterface $file) : bool
Parameters
- $file : SystemResourceInterface
Return values
boolextractFromLocalFile()
protected
extractFromLocalFile(SystemResourceInterface $file, string $localFilePath) : ExtractedText
Parameters
- $file : SystemResourceInterface
- $localFilePath : string
Return values
ExtractedTextgetMimeTypes()
protected
getMimeTypes() : array<int, string>
Return values
array<int, string>getMissingTools()
protected
getMissingTools() : array<int, string>
Return values
array<int, string>getRequiredTools()
protected
getRequiredTools() : array<int, "pdfinfo"|"pdftotext"|"catdoc"|"ppthtml"|"xlhtml"|"unzip"|"unrtf">
Return values
array<int, "pdfinfo"|"pdftotext"|"catdoc"|"ppthtml"|"xlhtml"|"unzip"|"unrtf">getToolPath()
protected
getToolPath(string $tool) : string
Parameters
- $tool : string
Return values
stringjoinOutput()
protected
joinOutput(array<int, string> $output) : string
Parameters
- $output : array<int, string>
Return values
stringstripXmlTags()
protected
stripXmlTags(string $xml) : string
Parameters
- $xml : string
Return values
stringwithLocalFile()
Provides a local copy of the file to the callback, and cleans up afterwards.
protected
withLocalFile(SystemResourceInterface $file, callable(string): T $callback) : T
Parameters
- $file : SystemResourceInterface
- $callback : callable(string): T