MMOframework
Pourquoi l'IA Playground Bibliothèques Développeurs Agence
FR EN
Créer un projet en direct
Index

PdfReader

MMO\pdf · 1 symbole · générée le 30 Nov 2026

class

PdfReader

PdfReader.php:19

Reads what a PDF says, as Markdown (toMarkdown): each page's text from poppler's pdftotext -layout, a page without text (a scan) read by tesseract from its image (pdftoppm), the document's metadata and form fields from

class MMO\pdf\PdfReader extends MMO\core\classes\aModule
Espace de noms
MMO\pdf
Étend
aModule
Voir
PDFTK above them. Text laid out in columns (a quote's lines, a form's labels and values) stays as it is laid out, in a ``text block: a Markdown table would mix up a description going on below its line. Needs the pdftotext and pdftoppm binaries (poppler-utils); tesseract for scans and pdftk` for metadata are used when they are there.
echo PdfReader::Shared()->toMarkdown('quote.pdf');

Index

COLUMN_GAPText laid out in columns: a gap of 3 spaces or more between two pieces of a line.
minPageTextA page with fewer letters than that is taken for a scan.
ocrDpiThe resolution a scanned page is read at.
ocrLanguagesThe languages Tesseract reads, its way ('fra+eng').
pdftoppmpoppler's pdftoppm: a scanned page as an image for $tesseract.
pdftotextpoppler's pdftotext.
tesseractTesseract, for the pages without text; '' to leave them unread.
withInfoWhether PDFTK's metadata and form fields go above the text.
Fence($lines) staticLines laid out in columns, as they are: their common indent removed, in a ```text block.
Join($a, $b) staticTwo lines of a paragraph, a word cut at the end of the first put back together.
LayoutToMarkdown($text) staticText laid out as on its page made Markdown: a paragraph's lines joined (a word cut at its end too), a bullet a list item, a short line in capitals alone a heading, and the lines laid out in columns…
metadata($filename)The metadata and form fields of the PDF (PDFTK::getInfo): title, author, dates, each field's value; nothing without pdftk, or when it can't read the file.
ocr($filename, $page)A page read by Tesseract from its image: through mmo.ocr's Tesseract::text() when it is loaded (and
pages($filename, $ocr)Each page's text, laid out as on the page; a scan's from Tesseract.
Prose($lines) staticLines of text: a heading, list items, or a paragraph.
run($cmd)Run a command: its output.
toMarkdown($filename, $title, $ocr, $front)The PDF as Markdown: a front matter (its pages, metadata and form fields), then each page after its <!-- page N --> (<!-- page N (ocr) --> for a scan read by Tesseract).

Constantes1

COLUMN_GAP

Text laid out in columns: a gap of 3 spaces or more between two pieces of a line.

const COLUMN_GAP = '/\\S\\s{3,}\\S/u'

Propriétés7

minPageText

A page with fewer letters than that is taken for a scan.

int $minPageText = 20
Type
int

ocrDpi

The resolution a scanned page is read at.

int $ocrDpi = 300
Type
int

ocrLanguages

The languages Tesseract reads, its way ('fra+eng').

string $ocrLanguages = 'fra+eng'
Type
string

pdftoppm

poppler's pdftoppm: a scanned page as an image for $tesseract.

string $pdftoppm = 'pdftoppm'
Type
string

pdftotext

poppler's pdftotext.

string $pdftotext = 'pdftotext'
Type
string

tesseract

Tesseract, for the pages without text; '' to leave them unread.

string $tesseract = 'tesseract'
Type
string

withInfo

Whether PDFTK's metadata and form fields go above the text.

bool $withInfo = true
Type
bool

Méthodes9

Fence($lines)

staticPdfReader.php:188

Lines laid out in columns, as they are: their common indent removed, in a ```text block.

protected static function Fence(array $lines): string
$linesarray
retournestring

Join($a, $b)

staticPdfReader.php:235

Two lines of a paragraph, a word cut at the end of the first put back together.

protected static function Join(string $a, string $b): string
$astring
$bstring
retournestring

LayoutToMarkdown($text)

staticPdfReader.php:162

Text laid out as on its page made Markdown: a paragraph's lines joined (a word cut at its end too), a bullet a list item, a short line in capitals alone a heading, and the lines laid out in columns kept as they are, in a ```text block (blank lines between such blocks don't split them).

static function LayoutToMarkdown(string $text): string
$textstring
retournestring
PdfReader::LayoutToMarkdown("TITLE\n\nA line\ngoing on.\n\n• one\n• two"); // "## TITLE\n\nA line going on.\n\n- one\n- two"

metadata($filename)

PdfReader.php:116

The metadata and form fields of the PDF (PDFTK::getInfo): title, author, dates, each field's value; nothing without pdftk, or when it can't read the file.

function metadata(string $filename): array
$filenamestring
retournearraymixed>

ocr($filename, $page)

PdfReader.php:65

A page read by Tesseract from its image: through mmo.ocr's Tesseract::text() when it is loaded (and

function ocr(string $filename, int $page): string
Voir
$tesseract is the default), else by running $tesseract here.
$filenamestring
$pageint
retournestring'' when Tesseract isn't there or reads nothing.

pages($filename, $ocr)

PdfReader.php:43

Each page's text, laid out as on the page; a scan's from Tesseract.

function pages(string $filename, bool $ocr = true): array
$filenamestring
$ocr = trueboolread a page without text with Tesseract.
retournearrayarray{text: string, ocr: bool}> by page number, from 1.
lèveif the file doesn't exist.
lèveif pdftotext can't read it (no PDF, protected...).
foreach (PdfReader::Shared()->pages('scan.pdf') as $n => $page) {echo "$n: {$page['text']}";}

Prose($lines)

staticPdfReader.php:199

Lines of text: a heading, list items, or a paragraph.

protected static function Prose(array $lines): string
$linesarray
retournestring

run($cmd)

PdfReader.php:141

Run a command: its output. @throws eRuntime when it fails.

protected function run(string $cmd): string
$cmdstring
retournestring

toMarkdown($filename, $title, $ocr, $front)

PdfReader.php:94

The PDF as Markdown: a front matter (its pages, metadata and form fields), then each page after its <!-- page N --> (<!-- page N (ocr) --> for a scan read by Tesseract).

function toMarkdown( string $filename, ?string $title = null, bool $ocr = true, array $front = [] ): string
$filenamestring
$title = nullnull | stringa # {title} above the text (the file's name...).
$ocr = truebool
$front = []array
retournestring
echo PdfReader::Shared()->toMarkdown('quote.pdf', 'quote.pdf');
Membres hérités (48)
ConstantesDéclaré parDescription
ALERTiLogLevelAlert: Action must be taken immediately.
ALLiLogLevelMask for all
ALL_PLUSiLogLeveldebug everything
BACKTRACEiLogLevel
CRITICALiLogLevelCritical: Critical conditions.
DEBUGiLogLevelDebug: Detailed debug information.
DEEPiLogLeveldebug everything with arguments
EMERGENCYiLogLevelEmergency: System is unusable.
ERRORiLogLevelError: Runtime errors that do not require immediate action but should typically be logged and monitored.
ERROR_PLUSiLogLevelMask for all error
FATALiLogLevelMask for all fatal error
INFOiLogLevelInfo: Interesting events.
INFO_PLUSiLogLevelMask for all errors/warning/notices/info
MEMORYiLogLevelinclude backtrace object
NOTICEiLogLevelNotice: Normal but significant events.
NOTICE_PLUSiLogLevelMask for all errors/warning/notices/info
TRACEiLogLevelinclude backtrace as origins
WARNINGiLogLevelWarning: Exceptional occurrences that are not errors.
WARNING_PLUSiLogLevelMask for all errors and warnings
PropriétésDéclaré parDescription
verbosityaModule
MéthodesDéclaré parDescription
alert($message, $context)aModuleAction must be taken immediately.
backtraces($message, $context)aModuleForce-log a message at INFO level together with a full stack trace/memory snapshot (iLogLevel::BACKTRACE), bypassing the verbosity mask entirely (any non-zero verbosity is enough to trigger it).
Configure($config)aModuleMerge $config into this module's configuration in the shared Configuration.
critical($message, $context)aModuleCritical conditions. No-op if CRITICAL is currently filtered out by the verbosity mask.
debug($message, $context)aModuleDetailed debug information.
debugName()aModuleHuman-readable identifier used as the default {origin} in this instance's log messages.
DefaultConfig()aModuleThe config a module starts from before anything loaded via Configuration is merged in.
emergency($message, $context)aModuleSystem is unusable. No-op if EMERGENCY is currently filtered out by the verbosity mask.
error($message, $context)aModuleRuntime errors that do not require immediate action but should typically be logged and monitored.
getVerbosity()aModule
info($message, $context)aModuleInteresting events. No-op if INFO is currently filtered out by the verbosity mask.
Instantiate($config)aModule(Re)create the shared instance immediately, configured with $config merged into the class's existing config.
IsShared()aModule
log($level, $message, $context)aModuleLogs with an arbitrary level.
notice($message, $context)aModuleNormal but significant events.
offsetExists($key)aModule\ArrayAccess::offsetExists -- tells whether $key is a declared property at all, regardless of whether it is currently readable/writable through array access.
offsetGet($key)aModule\ArrayAccess::offsetGet -- reads a property directly, unless it has a #[Serialize(serialize: 'methodName')] attribute, in which case that zero-argument method is called instead (e.g.
offsetSet($key, $value)aModule\ArrayAccess::offsetSet -- sets a property directly, unless it has a #[Serialize(unserialize: 'methodName')] attribute, in which case that method is called with $value instead (e.g.
offsetUnset($key)aModule\ArrayAccess::offsetUnset -- equivalent to $module[$key] = null.
serialize($path, $serializer)aModule\MMO\core\interfaces\iSerializable::serialize -- exports every property (via
setVerbosity($verb)aModuleSet the current verbosity mask, replacing whatever it was before.
Shared()aModuleGet the shared instance, creating (and configuring) it on first call.
testVerbosity($level)aModuleTest whether a given level (or set of levels) is currently enabled by this instance's verbosity mask.
traitUnshare($serialize)aModuleRemove the shared instance, so the next Shared() call creates a fresh one.
unserialize($data, $path, $instances)aModule\MMO\core\interfaces\iSerializable::unserialize -- merges $data onto DefaultConfig, runs it through the (possibly overridden) constructor, then applies each resulting value to its property (via
Unshare($serialize)aModuleLike tSingleton::Unshare, but also disconnects this module's instance from every event it was listening to (via Event::DisconnectListeners) before dropping it.
warning($message, $context)aModuleExceptional occurrences that are not errors.
__construct($config)aModuleprotected constructor, so it is not possible to do new Module(...) called by the serialization process just before being injected with data.