Documentation

FileInput extends LocalInputSource
in package

Binary file input.

Table of Contents

Properties

$fileMimetype  : string
$fileName  : string
$fileObject  : CURLFile
$filePath  : string|null
$throwsOnClose  : bool
$file  : mixed

Methods

__construct()  : mixed
Base constructor, mostly used for Mime type checking.
close()  : void
Closes the file.
compress()  : void
countDocPages()  : int
Counts the amount of pages in a PDF.
enableStrictMode()  : void
Enables strict mode.
getFilePtr()  : mixed
Returns the reference to the file object. Only used for testing purposes.
hasSourceText()  : bool
Checks the source file for source text.
isPDF()  : bool
Checks whether the file type is a PDF.
isPDFEmpty()  : bool
Checks whether the contents of a PDF are empty.
mergePDFPages()  : void
Create a new PDF from pages and set it as the main file object.
processPDF()  : void
Processes a PDF file.
readContents()  : array<string|int, mixed>
Reads the contents of the file.
checkMimeType()  : void
Checks the mimetype integrity of a file.
fixPDF()  : void
Attempts to fix a PDF file.
saveBytesAsFile()  : void

Properties

$fileName

public string $fileName

Name of the file, mandatory for proper Mime type handling server-side.

$fileObject

public CURLFile $fileObject

File object, as a CURLFile for simplicity.

$filePath

public string|null $filePath

Path of the file for files retrieved from a path.

$throwsOnClose

protected bool $throwsOnClose

Sets the input mode to debug. Only used in unit tests.

$file

private mixed $file

A file-like object compatible with CURLFile.

Methods

__construct()

Base constructor, mostly used for Mime type checking.

public __construct(mixed &$file[, bool $fixPDF = false ]) : mixed
Parameters
$file : mixed

File reference.

$fixPDF : bool = false

Whether the PDF should be fixed or not.

compress()

public compress([int $quality = 85 ][, int|null $maxWidth = null ][, int|null $maxHeight = null ][, bool $forceSourceTextCompression = false ][, bool $disableSourceText = true ]) : void
Parameters
$quality : int = 85

Quality of the output file.

$maxWidth : int|null = null

Maximum width (Ignored for PDFs).

$maxHeight : int|null = null

Maximum height (Ignored for PDFs).

$forceSourceTextCompression : bool = false

Whether to force the operation on PDFs with source text. This will attempt to re-render PDF text over the rasterized original. The script will attempt to re-write text, but might not support all fonts & encoding. If disabled, ignored the operation. WARNING: this operation is strongly discouraged.

$disableSourceText : bool = true

If the PDF has source text, whether to re-apply it to the original or not. Needs force_source_text to work.

enableStrictMode()

Enables strict mode.

public enableStrictMode() : void

Currently only used to throw on misuse of close().

getFilePtr()

Returns the reference to the file object. Only used for testing purposes.

public getFilePtr() : mixed

hasSourceText()

Checks the source file for source text.

public hasSourceText() : bool
Tags
throws
Exception

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

Return values
bool

Returns false if none is found, or if the file isn't a PDF.

isPDF()

Checks whether the file type is a PDF.

public isPDF() : bool
Return values
bool

isPDFEmpty()

Checks whether the contents of a PDF are empty.

public isPDFEmpty([int $threshold = 1024 ]) : bool
Parameters
$threshold : int = 1024

Semi-arbitrary threshold of minimum bytes on the page for it to be considered empty.

Tags
throws
MindeePDFException

Throws if the pdf file can't be processed.

Return values
bool

mergePDFPages()

Create a new PDF from pages and set it as the main file object.

public mergePDFPages(array<string|int, mixed> $pageNumbers) : void
Parameters
$pageNumbers : array<string|int, mixed>

Array of page numbers to add to the newly created PDF.

Tags
throws
MindeePDFException

Throws if the pdf file can't be processed.

processPDF()

Processes a PDF file.

public processPDF(string $behavior, int $onMinPages, array<string|int, mixed> $pageIndexes) : void

To be implemented.

Parameters
$behavior : string

Behaviors available: KEEP_ONLY, REMOVE.

$onMinPages : int

Minimum of pages to apply the operation.

$pageIndexes : array<string|int, mixed>

Indexes of the pages to apply the operation to.

Tags
throws
MindeePDFException

Throws if the operation is unknown, or if the resulting PDF can't be processed.

readContents()

Reads the contents of the file.

public readContents() : array<string|int, mixed>
Return values
array<string|int, mixed>

saveBytesAsFile()

private saveBytesAsFile(string $fileBytes) : void
Parameters
$fileBytes : string

Raw data as bytes.


        
On this page

Search results