PDF Processing Artisan Commands Documentation
This document outlines the usage of custom Artisan commands for generating PDF thumbnails and applying stamps or watermarks to PDF documents.System Prerequisites
Before using any of these commands, ensure the following command-line utilities are installed on your server or local development machine.1. PDF Thumbnail Generation
This feature is used to create an image preview from a specific page of a PDF file.Core Command: pdf:thumbnail
This is the low-level worker command that performs the conversion of a single PDF to a thumbnail.
Usage:
Example:
Batch Command: documents:generate-thumbnails
This is the high-level orchestrator command that finds documents in the database that are missing a thumbnail and
generates one for each.
Usage:
Examples:
2. PDF Stamping & Watermarking
This feature is used to apply QR code stamps and/or text watermarks to PDF documents. The final result is saved as a new file, and its URL is stored in theStampedFileUrl field of the document model, leaving the original file untouched.
Core Command: pdf:stamp
This is the low-level worker command that performs the stamping/watermarking operation on a single PDF.
Usage:
Important Note: This command requires a font file located at
public/fonts/Calibri/Calibri.ttf for rendering
watermarks.
Batch Command: documents:generate-stamp
This is the high-level orchestrator command that processes documents from the database, applies the specified
stamps/watermarks, and logs the operation.
Usage:
- Pass-Through Options: To use the detailed options from
pdf:stamp(like--stamp-positionor--watermark-color), you must use the-Oflag. - Placeholders: The
--stamp-qr-stringand--watermark-textoptions support dynamic placeholders that are replaced with data from the document being processed. Supported placeholders:{id}(or_id) and{FCallCode}. - Logging: Every stamping operation (success or failure) is recorded in the
stamp_logscollection in MongoDB. - Debugging: Run the command with the
-vflag to see the real-time, detailed output from thepdf:stampworker command.
Examples:
Dokumentasi Perintah Artisan untuk Pemrosesan PDF
Dokumen ini menjelaskan penggunaan perintah Artisan kustom untuk menghasilkan thumbnail PDF dan menerapkan stempel atau tanda air (watermark) pada dokumen PDF.Prasyarat Sistem
Sebelum menggunakan perintah-perintah ini, pastikan utilitas baris perintah berikut telah terinstal di server atau mesin pengembangan lokal Anda.1. Pembuatan Thumbnail PDF
Fitur ini digunakan untuk membuat pratinjau gambar dari halaman tertentu sebuah file PDF.Perintah Inti: pdf:thumbnail
Ini adalah perintah level rendah yang melakukan konversi satu PDF menjadi sebuah thumbnail.
Penggunaan:
Contoh:
Perintah Massal: documents:generate-thumbnails
Ini adalah perintah level tinggi yang mencari dokumen di database yang belum memiliki thumbnail dan membuatnya untuk setiap dokumen.
Penggunaan:
Contoh:
2. Stempel & Tanda Air (Watermark) PDF
Fitur ini digunakan untuk menerapkan stempel kode QR dan/atau tanda air teks pada dokumen PDF. Hasil akhirnya disimpan sebagai file baru, dan URL-nya disimpan di fieldStampedFileUrl pada model dokumen, tanpa mengubah file asli.
Perintah Inti: pdf:stamp
Ini adalah perintah level rendah yang melakukan operasi stempel/watermark pada satu PDF.
Penggunaan:
Catatan Penting: Perintah ini memerlukan file font di
public/fonts/Calibri/Calibri.ttf untuk me-render watermark.
Perintah Massal: documents:generate-stamp
Ini adalah perintah level tinggi yang memproses dokumen dari database, menerapkan stempel/watermark yang ditentukan, dan mencatat setiap operasi.
Penggunaan:
- Opsi Terusan: Untuk menggunakan opsi-opsi detail dari
pdf:stamp(seperti--stamp-positionatau--watermark-color), Anda harus menggunakan flag-O. - Placeholder: Opsi
--stamp-qr-stringdan--watermark-textmendukung placeholder dinamis yang akan diganti dengan data dari dokumen yang sedang diproses. Placeholder yang didukung:{id}(atau_id) dan{FCallCode}. - Pencatatan (Logging): Setiap operasi (baik sukses maupun gagal) dicatat dalam koleksi
stamp_logsdi MongoDB. - Debugging: Jalankan perintah dengan flag
-vuntuk melihat output detail secara real-time dari perintahpdf:stamp.
Contoh:
