PDFCompressor
in package
PDF compression class.
Table of Contents
Methods
- compress() : CURLFile
- Compresses each page of a provided PDF stream. Skips if force_source_text isn't set and source text is detected.
- createOutputPdf() : string
- Creates the final output PDF, optionally injecting text from the original PDF.
- injectText() : void
- Extracts text from a source text PDF, and injects it into a newly-created one.
- injectTextForPage() : void
- processPdfPage() : array<string|int, mixed>
- Processes a single PDF page, rasterizing it to a JPEG image.
Methods
compress()
Compresses each page of a provided PDF stream. Skips if force_source_text isn't set and source text is detected.
public
static compress(mixed $input[, int $quality = 85 ][, bool $forceSourceTextCompression = false ][, bool $disableSourceText = true ]) : CURLFile
Parameters
- $input : mixed
-
Path to the PDF file.
- $quality : int = 85
-
Compression quality (70-100 for most JPG images in the test dataset).
- $forceSourceTextCompression : bool = false
-
If true, attempts to re-write detected text.
- $disableSourceText : bool = true
-
If true, doesn't re-apply source text to the original PDF.
Tags
Return values
CURLFilecreateOutputPdf()
Creates the final output PDF, optionally injecting text from the original PDF.
private
static createOutputPdf(CustomFPDI $processedPdf, bool $disableSourceText, Document $originalPdf) : string
Parameters
- $processedPdf : CustomFPDI
-
The FPDI object containing the processed pages.
- $disableSourceText : bool
-
Whether to disable source text injection.
- $originalPdf : Document
-
The original PDF document (used for text injection).
Tags
Return values
string —Path to the output PDF file
injectText()
Extracts text from a source text PDF, and injects it into a newly-created one.
private
static injectText(Document $inputPdf, CustomFPDI $outputPdf) : void
Parameters
- $inputPdf : Document
-
Input PDF document.
- $outputPdf : CustomFPDI
-
The output PDF object.
Tags
injectTextForPage()
private
static injectTextForPage(Page $inputPage, CustomFPDI $outputPdf) : void
Parameters
- $inputPage : Page
-
Input page.
- $outputPdf : CustomFPDI
-
Output PDF handle.
Tags
processPdfPage()
Processes a single PDF page, rasterizing it to a JPEG image.
private
static processPdfPage(string $sourcePdfPath, int $pageIndex, int $imageQuality) : array<string|int, mixed>
Parameters
- $sourcePdfPath : string
-
Path to the source PDF file.
- $pageIndex : int
-
The index of the page to process.
- $imageQuality : int
-
The quality setting for JPEG compression.
Tags
Return values
array<string|int, mixed> —Path to the temporary JPEG file and orientation of the page.