phpdftk API Documentation

TextRedactor
in package

FinalYes

Redact text or areas from PDF pages by drawing filled rectangles.

Note: This is visual redaction (Phase 1). The underlying text bytes remain in the PDF. For full content removal, a future Phase 2 will rewrite content streams to strip text operators.

Usage: TextRedactor::open('contract.pdf') ->redactArea(1, 72, 700, 200, 20) ->apply() ->save('redacted.pdf');

Table of Contents

Methods

apply()  : self
Apply all marked redactions. Must be called before save/toBytes.
getPageCount()  : int
getReader()  : PdfReader
getRedactionCount()  : int
getVersionWarnings()  : array<int, string>
open()  : self
openString()  : self
redactArea()  : self
Mark a specific area for redaction.
redactPattern()  : self
redactText()  : self
Mark a text string for redaction across pages.
save()  : void
setRedactionColor()  : self
toBytes()  : string

Methods

apply()

Apply all marked redactions. Must be called before save/toBytes.

public apply() : self
Return values
self

getPageCount()

public getPageCount() : int
Return values
int

getRedactionCount()

public getRedactionCount() : int
Return values
int

getVersionWarnings()

public getVersionWarnings() : array<int, string>
Return values
array<int, string>

open()

public static open(string $path[, string $password = '' ]) : self
Parameters
$path : string
$password : string = ''
Return values
self

openString()

public static openString(string $pdfBytes[, string $password = '' ]) : self
Parameters
$pdfBytes : string
$password : string = ''
Return values
self

redactArea()

Mark a specific area for redaction.

public redactArea(int $pageNumber, float $x, float $y, float $width, float $height) : self
Parameters
$pageNumber : int

1-based page number

$x : float

Left edge in points

$y : float

Bottom edge in points

$width : float

Width in points

$height : float

Height in points

Return values
self

redactPattern()

public redactPattern(string $regex[, PageSelector|null $pages = null ]) : self
Parameters
$regex : string
$pages : PageSelector|null = null
Return values
self

redactText()

Mark a text string for redaction across pages.

public redactText(string $text[, PageSelector|null $pages = null ]) : self

Text positions are approximated — redaction rectangles cover the approximate line area where the text was found.

Parameters
$text : string
$pages : PageSelector|null = null
Return values
self

save()

public save(string $path) : void
Parameters
$path : string

setRedactionColor()

public setRedactionColor(float $r, float $g, float $b) : self
Parameters
$r : float
$g : float
$b : float
Return values
self

toBytes()

public toBytes() : string
Return values
string

        
On this page

Search results