PHP code example of hosmelq / laravel-anydoc

1. Go to this page and download the library: Download hosmelq/laravel-anydoc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hosmelq / laravel-anydoc example snippets


use HosmelQ\Anydoc\Laravel\Facades\Anydoc;

$markdown = Anydoc::file('report.docx')->markdown();

$markdown = Anydoc::file($uploadedFile)->markdown();

$bytes = file_get_contents('report.docx');

$markdown = Anydoc::bytes($bytes)->markdown();

use HosmelQ\Anydoc\Laravel\Enums\Format;
use HosmelQ\Anydoc\Laravel\Facades\Anydoc;

$bytes = file_get_contents('data.csv');

$markdown = Anydoc::bytes($bytes, Format::Csv)->markdown();

use HosmelQ\Anydoc\Laravel\Facades\Anydoc;

$markdown = Anydoc::disk('s3')
    ->file('documents/report.docx')
    ->markdown();

use HosmelQ\Anydoc\Laravel\Facades\Anydoc;

$document = Anydoc::file('presentation.pptx')->document();

$assets = $document->assets;
$blocks = $document->blocks;
$notes = $document->notes;

use HosmelQ\Anydoc\Laravel\Enums\Format;
use HosmelQ\Anydoc\Laravel\Facades\Anydoc;

$markdown = Anydoc::bytes($bytes, Format::Docx)->markdown();

use HosmelQ\Anydoc\Laravel\Facades\Anydoc;

$fromBytes = Anydoc::formatFromBytes($bytes);
$fromExtension = Anydoc::formatFromExtension('.DOCX');
$fromPath = Anydoc::formatFromPath('documents/report.docx');

use HosmelQ\Anydoc\Laravel\Contracts\Anydoc;

final class ConvertDocument
{
    public function __construct(private Anydoc $anydoc) {}

    public function handle(string $path): string
    {
        return $this->anydoc->file($path)->markdown();
    }
}

use Anydoc\Exception\ConvertException;
use Anydoc\Exception\PanicException;
use HosmelQ\Anydoc\Laravel\Facades\Anydoc;

try {
    $markdown = Anydoc::file('report.docx')->markdown();
} catch (ConvertException $exception) {
    report($exception);
} catch (PanicException $exception) {
    report($exception);
}

use HosmelQ\Anydoc\Laravel\Facades\Anydoc;
use HosmelQ\Anydoc\Laravel\RecordedConversion;

Anydoc::fake([
    'markdown' => '# Converted document',
]);

Anydoc::file('report.docx')->markdown();

Anydoc::assertConvertedToMarkdown(
    fn (RecordedConversion $conversion): bool => $conversion->input === 'report.docx',
);

Anydoc::fake([
    'markdown' => fn (RecordedConversion $conversion): string => "# {$conversion->input}",
]);

$markdown = Anydoc::file('report.docx')->markdown();

Anydoc::assertConverted();
Anydoc::assertConvertedTimes(2);
Anydoc::assertConvertedToDocument();
Anydoc::assertConvertedToMarkdown();
Anydoc::assertNotConverted($callback);
Anydoc::assertNothingConverted();

$conversions = Anydoc::conversions();