English Documentation
Documentation for image:convert-from Artisan Command
1. Overview
This Artisan command provides a powerful utility to convert office documents and PDFs into a series of JPG images. It can process a source file from a local path or a remote URL and save the resulting images to a local directory or any configured Laravel filesystem disk (e.g., Amazon S3, Minio). Each page of the source document is rendered as a separate, sequentially numbered image. The command operates using an automated, multi-stage process:- Input Handling: If the input is a URL, the file is downloaded to a temporary local location.
- PDF Conversion (via LibreOffice): If the input file is not a PDF, it uses LibreOffice in headless mode to convert the document into a temporary PDF.
- Image Rendering (via Ghostscript): It then uses Ghostscript to process the PDF and render each page as an individual JPG image in a temporary local directory.
- Output Handling: If a
--diskis specified, the generated images are uploaded from the temporary directory to the specified disk. Otherwise, they are moved to the designated local output path.
2. System Requirements (Prerequisites)
Before using this command, you must install two essential command-line tools on your server and ensure they are accessible from the systemโsPATH.
- LibreOffice (or OpenOffice): Required for converting office documents to PDF.
- Installation on Debian/Ubuntu:
- Ghostscript: Required for converting PDF pages into images.
- Installation on Debian/Ubuntu:
Note: The command script usessoffice. On some systems, the executable islibreoffice. You may need to edit theImageConvertCommand.phpfile to changesofficetolibreofficeif you encounter an error.
3. Command Syntax
--in: (Required) The source document to convert. Can be a local file path or a public URL.--out: (Required) The destination path for the output images. If a--diskis used, this is a path within that disk. Otherwise, itโs a local directory.--filetype: (Required) The file extension of the input file (e.g.,docx,pdf,xlsx).--disk: (Optional) The Laravel filesystem disk to save the output to (e.g.,s3,minio). If omitted, output is saved to the local filesystem.
4. Example Usage
Example 1: Converting a Local DOCX file to a Local Directory
Example 2: Converting a Remote PDF to a Local Directory
Example 3: Converting a Local Excel File to an S3 Bucket
- Process: The command converts the local Excel file to images and uploads them to the
converted-images/financials/q4_datapath on your configureds3disk.
Example 4: Converting a Remote PPTX File to a Minio Bucket
- Process: The command downloads the PPTX, converts it to images, and uploads them to the specified path on your
miniodisk.
5. Expected Output
When converting a remote file to a disk, you will see a more detailed progress log:Bahasa Indonesia Documentation
Dokumentasi Perintah Artisan image:convert-from
1. Gambaran Umum
Perintah Artisan ini menyediakan utilitas untuk mengonversi dokumen office dan PDF menjadi serangkaian gambar JPG. Perintah ini dapat memproses file sumber dari path lokal atau URL remote dan menyimpan hasilnya ke direktori lokal atau disk filesystem Laravel yang terkonfigurasi (misalnya, Amazon S3, Minio). Setiap halaman dari dokumen sumber akan di-render sebagai gambar terpisah dengan nomor urut. Perintah ini bekerja menggunakan proses otomatis multi-tahap:- Penanganan Input: Jika input adalah URL, file akan diunduh ke lokasi temporer lokal.
- Konversi ke PDF (melalui LibreOffice): Jika file input bukan PDF, LibreOffice dalam mode headless akan digunakan untuk mengubahnya menjadi PDF temporer.
- Render Gambar (melalui Ghostscript): Ghostscript kemudian memproses PDF dan me-render setiap halaman menjadi gambar JPG di direktori temporer lokal.
- Penanganan Output: Jika
--diskditentukan, gambar yang dihasilkan akan diunggah ke disk tersebut. Jika tidak, gambar akan dipindahkan ke path output lokal yang ditentukan.
2. Persyaratan Sistem (Prasyarat)
Sebelum menggunakan perintah ini, Anda harus menginstal dua perangkat lunak command-line pada server Anda dan memastikan keduanya dapat diakses melaluiPATH sistem.
- LibreOffice (atau OpenOffice): Dibutuhkan untuk mengonversi dokumen office ke PDF.
- Instalasi pada Debian/Ubuntu:
- Ghostscript: Dibutuhkan untuk mengonversi halaman PDF menjadi gambar.
- Instalasi pada Debian/Ubuntu:
Catatan: Skrip perintah ini menggunakansoffice. Pada beberapa sistem, nama eksekusinya adalahlibreoffice. Anda mungkin perlu mengubah fileImageConvertCommand.phpdan menggantisofficemenjadilibreofficejika terjadi galat.
3. Sintaks Perintah
--in: (Wajib) Dokumen sumber yang akan dikonversi. Bisa berupa path file lokal atau URL publik.--out: (Wajib) Path tujuan untuk gambar hasil konversi. Jika--diskdigunakan, ini adalah path di dalam disk tersebut. Jika tidak, ini adalah direktori lokal.--filetype: (Wajib) Ekstensi file dari file input (contoh:docx,pdf,xlsx).--disk: (Opsional) Disk filesystem Laravel untuk menyimpan output (contoh:s3,minio). Jika dihilangkan, output disimpan di filesystem lokal.
4. Contoh Penggunaan
Contoh 1: Mengonversi file DOCX lokal ke Direktori Lokal
Contoh 2: Mengonversi PDF Remote ke Direktori Lokal
Contoh 3: Mengonversi file Excel Lokal ke Bucket S3
- Proses: Perintah akan mengonversi file Excel lokal menjadi gambar dan mengunggahnya ke path
converted-images/financials/data_q4pada disks3yang telah Anda konfigurasikan.
Contoh 4: Mengonversi file PPTX Remote ke Bucket Minio
- Proses: Perintah akan mengunduh file PPTX, mengonversinya menjadi gambar, dan mengunggah hasilnya ke path yang ditentukan pada disk
minio.
