Skip to main content

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:
  1. Input Handling: If the input is a URL, the file is downloaded to a temporary local location.
  2. 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.
  3. 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.
  4. Output Handling: If a --disk is 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’s PATH.
  • 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 uses soffice. On some systems, the executable is libreoffice. You may need to edit the ImageConvertCommand.php file to change soffice to libreoffice if you encounter an error.

3. Command Syntax

Options:
  • --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 --disk is 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_data path on your configured s3 disk.
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 minio disk.

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:
  1. Penanganan Input: Jika input adalah URL, file akan diunduh ke lokasi temporer lokal.
  2. Konversi ke PDF (melalui LibreOffice): Jika file input bukan PDF, LibreOffice dalam mode headless akan digunakan untuk mengubahnya menjadi PDF temporer.
  3. Render Gambar (melalui Ghostscript): Ghostscript kemudian memproses PDF dan me-render setiap halaman menjadi gambar JPG di direktori temporer lokal.
  4. Penanganan Output: Jika --disk ditentukan, 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 melalui PATH 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 menggunakan soffice. Pada beberapa sistem, nama eksekusinya adalah libreoffice. Anda mungkin perlu mengubah file ImageConvertCommand.php dan mengganti soffice menjadi libreoffice jika terjadi galat.

3. Sintaks Perintah

Opsi:
  • --in: (Wajib) Dokumen sumber yang akan dikonversi. Bisa berupa path file lokal atau URL publik.
  • --out: (Wajib) Path tujuan untuk gambar hasil konversi. Jika --disk digunakan, 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_q4 pada disk s3 yang 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.

5. Hasil yang Diharapkan

Saat mengonversi file remote ke sebuah disk, Anda akan melihat log proses yang lebih detail: