PDFUtils
in package
PDF utility class.
Table of Contents
Methods
- addTextElement() : void
- Adds a text element to the output PDF.
- downgradePdfVersion() : string
- Downgrades PDF files unsupported by FPDI to a compatible version.
- extractFilePath() : string
- extractPagesTextElements() : array<string|int, mixed>
- Extracts text elements with their properties from all pages in a PDF.
- extractTextElements() : array<string|int, mixed>
- Extracts text elements with their properties from a PDF page.
- hasSourceText() : bool
- Checks whether the file has source text. Returns false if the file isn't a PDF.
- toCURLFile() : CURLFile
- Loads a pdf handle into a valid CURLFile handle.
- standardizeFontName() : array<string|int, mixed>
Methods
addTextElement()
Adds a text element to the output PDF.
public
static addTextElement(CustomFPDI $pdf, array<string|int, mixed> $element) : void
Parameters
- $pdf : CustomFPDI
-
The output PDF object.
- $element : array<string|int, mixed>
-
Text element array containing text, position, font, size, and color.
downgradePdfVersion()
Downgrades PDF files unsupported by FPDI to a compatible version.
public
static downgradePdfVersion(string $inputPath) : string
Parameters
- $inputPath : string
-
Input PDF path.
Tags
Return values
string —Output path.
extractFilePath()
public
static extractFilePath(mixed $input) : string
Parameters
- $input : mixed
-
Input file. Accepts SplFileObject, Imagick, Curl, resources & paths.
Tags
Return values
string —Path of the file.
extractPagesTextElements()
Extracts text elements with their properties from all pages in a PDF.
public
static extractPagesTextElements(string $pdfPath) : array<string|int, mixed>
Parameters
- $pdfPath : string
-
Path to the PDF file.
Tags
Return values
array<string|int, mixed> —An array of arrays, each containing text elements for a page. Each text element includes text content, position, font, size, and color.
extractTextElements()
Extracts text elements with their properties from a PDF page.
public
static extractTextElements(Page $page) : array<string|int, mixed>
Parameters
- $page : Page
-
Page object.
Tags
Return values
array<string|int, mixed> —An array of text elements, each containing text content, position, font, size, and color.
hasSourceText()
Checks whether the file has source text. Returns false if the file isn't a PDF.
public
static hasSourceText(string $pdfPath) : bool
Parameters
- $pdfPath : string
-
Path to the PDF file.
Tags
Return values
bool —True if the PDF has source text, false otherwise.
toCURLFile()
Loads a pdf handle into a valid CURLFile handle.
public
static toCURLFile(string $path) : CURLFile
Parameters
- $path : string
-
Imagick image handle.
Tags
Return values
CURLFilestandardizeFontName()
private
static standardizeFontName(string $fontName) : array<string|int, mixed>
Parameters
- $fontName : string
-
Name of the font/subfont.
Return values
array<string|int, mixed> —The standard font & possible style.