Skip to main content

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:
Options: 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:
Options: 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 the StampedFileUrl 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:
Options: 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:
Key Features:
  • Pass-Through Options: To use the detailed options from pdf:stamp (like --stamp-position or --watermark-color), you must use the -O flag.
  • Placeholders: The --stamp-qr-string and --watermark-text options 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_logs collection in MongoDB.
  • Debugging: Run the command with the -v flag to see the real-time, detailed output from the pdf:stamp worker command.
Options: 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:
Opsi: 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:
Opsi: 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 field StampedFileUrl 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:
Opsi: 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:
Fitur Utama:
  • Opsi Terusan: Untuk menggunakan opsi-opsi detail dari pdf:stamp (seperti --stamp-position atau --watermark-color), Anda harus menggunakan flag -O.
  • Placeholder: Opsi --stamp-qr-string dan --watermark-text mendukung 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_logs di MongoDB.
  • Debugging: Jalankan perintah dengan flag -v untuk melihat output detail secara real-time dari perintah pdf:stamp.
Opsi: Contoh: