PDF File class for generating PDFs from HTML.
This class can be used to generate PDFs from HTML sources. It extends the Hazaar\File class so all of it's methods are available. The difference here is that when calling Hazaar\File\PDF::set_content(), the content is filtered throught the PDF generator. So you can set the content as HTML and the actual stored content will be in PDF format.
If the content being set is already in PDF format, there is protection coded in that does not attempt to re-render the content.
Constants
PDF_PORTRAIT
public const PDF_PORTRAIT = 'portrait'PDF_LANDSCAPE
public const PDF_LANDSCAPE = 'landscape'Properties
sourceURL
public string $sourceURLstatus
private string $statusorient
private string $orient = 'self'size
private string $size = 'A4'Methods
__construct
Hazaar\File\PDF constructor.
public __construct(?string $file, ?Manager $manager, ?string $relativePath): voidParameters
| Parameter | Type | Description |
|---|---|---|
$file | string | Filename to use if the file will be written to disk. If null, the file can exist only in memory. |
$manager | Manager | An optional file manager for accessing public file data |
$relativePath | string | internal relative path when accessing the file through a Hazaar\File\Dir object |
setOrientation
Set orientation, use constants from this class.
public setOrientation(string $mode): voidBy default orientation is portrait.
Parameters
| Parameter | Type | Description |
|---|---|---|
$mode | string | use constants from this class |
setPageSize
Set page/paper size.
public setPageSize(string $size): voidBy default page size is A4.
Parameters
| Parameter | Type | Description |
|---|---|---|
$size | string | Formal paper size (eg; A4, letter...) |
setContents
Set the HTML content of the new PDF file.
public setContents(?string $content): ?intThis content should be HTML format and will be converted into a PDF immediately and stored in memory. set_content() will not directly write the file to storage. If you want to do that, use put_content() instead.
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | The HTML content to convert into a PDF |
setSource
Set source URL of content.
public setSource(string $url): voidParameters
| Parameter | Type | Description |
|---|---|---|
$url | string | A url accessible from the host that will be rendered to a PDF |
getStatus
Returns WKPDF print status.
public getStatus(): stringmimeContentType
public mimeContentType(): stringrender
FILE_FILTER_SET Content filter to convert HTML to PDF.
protected render(?string $bytes): boolThis is the guts of it really. This is the method that converts the HTML content being set into a PDF.
Parameters
| Parameter | Type | Description |
|---|---|---|
$bytes | string |
Generated by Hazaar API Doc Generator on Tue, 30 Sep 2025 00:01:36 +0000