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 $sourceURL
status
private string $status
orient
private string $orient = 'self'
size
private string $size = 'A4'
Methods
__construct
Hazaar\File\PDF constructor.
public __construct(?string $file, ?Manager $manager, ?string $relative_path): void
Parameters
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 |
$relative_path | 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): void
By default orientation is portrait.
Parameters
Parameter | Type | Description |
---|---|---|
$mode | string | use constants from this class |
setPageSize
Set page/paper size.
public setPageSize(string $size): void
By 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): ?int
This 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): void
Parameters
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(): string
mimeContentType
public mimeContentType(): string
render
FILE_FILTER_SET Content filter to convert HTML to PDF.
protected render(?string $bytes): bool
This 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