Documentation

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
throws
MindeePDFException

Throws if the file can't be handled through Imagick.

throws
Exception

Will be thrown as MindeePDFException, this is just for PHPCS linting purposes.

Return values
string

Output path.

extractFilePath()

public static extractFilePath(mixed $input) : string
Parameters
$input : mixed

Input file. Accepts SplFileObject, Imagick, Curl, resources & paths.

Tags
throws
MindeePDFException

Throws if a path can't be extracted from the input.

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
throws
MindeePDFException

Throws if the PDF can't be parsed or text elements can't be extracted.

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
throws
MindeePDFException

Throws if the text elements can't be extracted.

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
throws
Exception

Throws if an instance of pdf-parser can't be created.

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
throws
MindeeImageException

Throws if the image can't be converted back into a CURLFile.

Return values
CURLFile

standardizeFontName()

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.


        
On this page

Search results