API reference
This page lists the public API available to your Laravel application. Linked guides explain input, conversion, delivery, and error behavior.
Create an OfficeDocument
Office::fromPath(string $path): OfficeDocument
Office::fromContent(string $content, InputFormat $format): OfficeDocument
Office::fromUploadedFile(UploadedFile $file): OfficeDocumentfromPath()snapshots an absolute, readable, non-symbolic-link local file.fromContent()snapshots complete bytes using the required explicitInputFormat.fromUploadedFile()snapshots a valid Laravel upload and uses its original extension as the format candidate.
See Choosing an input. InputFormat cases are:
ODT DOC DOCX DOCM RTF TXT HTML
ODS XLS XLSX XLSM CSV
ODP PPT PPTX PPTM
ODG PDF DXF SVG PNG JPEG WEBPConvert an OfficeDocument
$document->convertTo(Format $format): ConvertedOfficeConverts once to a format supported by the input family. Unsupported combinations throw UnsupportedConversion before LibreOffice starts. See the complete conversion matrix.
Format cases are:
PDF ODT DOCX RTF TXT HTML ODS XLSX CSV ODP PPTX ODG PNG JPEG SVG WEBPConsume a ConvertedOffice
$converted->output(): string
$converted->storeAs(
string $path,
?string $filename = null,
?string $disk = null,
): string|falseoutput()returns all artifact bytes.storeAs()streams to a Laravel Storage disk and returns the driver's path orfalse.
Call either output() or storeAs() once. Both methods consume the result on success or failure and clean its temporary conversion files. See Retrieving and storing output.
Exceptions
The package exception marker is:
Mattmy\OfficeConverter\Contracts\OfficeConverterExceptionImplementations are EnvironmentUnavailable, InvalidOfficeInput, UnsupportedConversion, ConversionFailed, and AlreadyConsumed. Storage destination validation uses PHP's InvalidArgumentException; Storage/Flysystem failures are not converted. See Errors and troubleshooting.
Laravel integration
Publish tag:
office-converter-configEnvironment variable:
LIBREOFFICE_BINARYSee Configuration for config keys and defaults.