- Menambahkan command baru `webstatement:convert-html-to-pdf` untuk melakukan konversi file HTML menjadi PDF secara otomatis: - Dapat menerima parameter `directory` untuk menentukan direktori sumber file HTML. - Menampilkan pesan sukses atau error selama proses berjalan. - Menggunakan konsep asinkron melalui job untuk meningkatkan efisiensi. - Membuat job baru `ConvertHtmlToPdfJob` untuk menangani proses konversi file: - Memproses folder yang berisi file HTML berdasarkan struktur direktori tertentu. - Mengambil semua file HTML dalam suatu folder, kemudian mengonversinya menjadi file PDF. - Menggunakan library `Barryvdh\DomPDF\Facade\Pdf` untuk konversi format HTML ke PDF. - Melakukan logging untuk setiap proses berhasil atau ketika terjadi error. - Memastikan suksesnya konversi ke direktori yang sama dengan file HTML. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\Webstatement\Console;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Modules\Webstatement\Jobs\ConvertHtmlToPdfJob;
|
|
use Exception;
|
|
|
|
class ConvertHtmlToPdf extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'webstatement:convert-html-to-pdf {directory}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Convert HTML files to PDF in the specified directory';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
try {
|
|
$directory = $this->argument('directory');
|
|
|
|
$this->info('Starting HTML to PDF conversion process...');
|
|
|
|
// Dispatch the job
|
|
ConvertHtmlToPdfJob::dispatch($directory);
|
|
|
|
$this->info('HTML to PDF conversion job has been queued.');
|
|
|
|
return 0;
|
|
} catch (Exception $e) {
|
|
$this->error('Error processing HTML to PDF conversion: ' . $e->getMessage());
|
|
return 1;
|
|
}
|
|
}
|
|
}
|