PdfProcessingService
in package
Handles PDF file operations for waiver uploads.
Provides PDF validation, page counting, merging, and thumbnail generation. Uses pure PHP libraries (smalot/pdfparser, setasign/fpdi) with no external dependencies.
Table of Contents
Constants
- MAX_PDF_SIZE : mixed = 52428800
- Maximum file size for PDF uploads (in bytes) Default: 50MB
Methods
- generateThumbnail() : ServiceResult
- Generate a placeholder thumbnail for a PDF
- getPageCount() : int
- Get page count from a PDF file
- isPdf() : bool
- Check if a file is a PDF based on extension and magic bytes
- isPdfMimeType() : bool
- Check if a MIME type indicates a PDF
- mergePdfs() : ServiceResult
- Merge multiple PDF files into one
- validatePdf() : ServiceResult
- Validate that a file is a valid PDF
- runWorker() : ServiceResult
- Isolate untrusted parsers from the request process and bound memory and wall time.
Constants
MAX_PDF_SIZE
Maximum file size for PDF uploads (in bytes) Default: 50MB
private
mixed
MAX_PDF_SIZE
= 52428800
Methods
generateThumbnail()
Generate a placeholder thumbnail for a PDF
public
generateThumbnail(string $pdfPath, string $outputPath[, int $width = 200 ][, int $height = 260 ]) : ServiceResult
Since we don't have ImageMagick/Ghostscript, we create a simple branded placeholder image showing the page count.
Parameters
- $pdfPath : string
-
Path to the PDF file
- $outputPath : string
-
Path for the thumbnail image (PNG)
- $width : int = 200
-
Thumbnail width in pixels (default: 200)
- $height : int = 260
-
Thumbnail height in pixels (default: 260)
Return values
ServiceResult —Success or failure
getPageCount()
Get page count from a PDF file
public
getPageCount(string $filePath) : int
Parameters
- $filePath : string
-
Path to the PDF file
Return values
int —Page count, or 0 on error
isPdf()
Check if a file is a PDF based on extension and magic bytes
public
isPdf(string $filePath) : bool
Parameters
- $filePath : string
-
Path to file
Return values
bool —True if file appears to be a PDF
isPdfMimeType()
Check if a MIME type indicates a PDF
public
isPdfMimeType(string $mimeType) : bool
Parameters
- $mimeType : string
-
MIME type to check
Return values
bool —True if MIME type is PDF
mergePdfs()
Merge multiple PDF files into one
public
mergePdfs(array<string|int, mixed> $pdfInfos, string $outputPath) : ServiceResult
Parameters
- $pdfInfos : array<string|int, mixed>
- $outputPath : string
-
Path for the merged output PDF
Return values
ServiceResult —Success with total page count, or failure with error
validatePdf()
Validate that a file is a valid PDF
public
validatePdf(string $filePath) : ServiceResult
Parameters
- $filePath : string
-
Path to the PDF file
Return values
ServiceResult —Success with page count in data, or failure with error message
runWorker()
Isolate untrusted parsers from the request process and bound memory and wall time.
private
runWorker(string $operation, array<string|int, mixed> $paths[, string|null $outputPath = null ]) : ServiceResult
Parameters
- $operation : string
- $paths : array<string|int, mixed>
- $outputPath : string|null = null