PHP Class kartik\mpdf\Pdf

Since: 1.0
Author: Kartik Visweswaran ([email protected])
Inheritance: extends yii\base\Component
ファイルを表示 Open project: kartik-v/yii2-mpdf Class Usage Examples

Public Properties

Property Type Description
$content the HTML content to be converted to PDF
$cssFile css file to prepend to the PDF
$cssInline additional inline css to append after the cssFile
$defaultFont sets the default font-family for the new document. Uses default value set in defaultCSS unless codepage has been set to "win-1252". If codepage="win-1252", the appropriate core Adobe font will be set i.e. Helvetica, Times, or Courier.
$defaultFontSize sets the default document font size in points (pt)
$destination the output destination
$filename the output filename
$format
$marginBottom sets the page bottom margin for the new document (in millimetres).
$marginFooter sets the page footer margin for the new document (in millimetres).
$marginHeader sets the page header margin for the new document (in millimetres).
$marginLeft sets the page left margin for the new document. All values should be specified as LENGTH in millimetres. If you are creating a DOUBLE-SIDED document, the margin values specified will be used for ODD pages; left and right margins will be mirrored for EVEN pages.
$marginRight sets the page right margin for the new document (in millimetres).
$marginTop sets the page top margin for the new document (in millimetres).
$methods the mPDF methods that will called in the sequence listed before rendering the content. Should be an associative array of $method => $params format, where: - $method: string, is the mPDF method / function name - $param: mixed, are the mPDF method parameters
$mode specifies the mode of the new document. If the mode is set by passing a country/language string, this may also set: available fonts, text justification, and directionality RTL.
$options the mPDF configuration options entered as a $key => value associative array, where: - $key: string is the mPDF configuration property name - $value: mixed is the mPDF configured property value
$orientation specifies the default page orientation of the new document.
$tempPath the folder path for storing the temporary data generated by mpdf. If not set this defaults to Yii::getAlias('@runtime/mpdf').

Protected Properties

Property Type Description
$_css the css file content
$_mpdf api instance
$_pdfAttachements Array of file-pathes that should be attached to the generated PDF

Public Methods

Method Description
addPdfAttachement ( string $filePath ) add an PDF to attach to the generated PDF
configure ( $options = [] ) Configures mPDF options
execute ( $method, $params = [] ) : mixed Calls the mPDF method with parameters
getApi ( ) : mPDF Initializes (if needed) and fetches the mPDF API instance
getCss ( ) : string Fetches the content of the CSS file if supplied
getPdfAttachements ( ) : array
init ( )
initTempPaths ( ) Initialize folder paths to allow mpdf to write temporary data.
output ( $content = '', $file = '', $dest = self::DEST_BROWSER ) : mixed Generates a PDF output
render ( ) Renders and returns the PDF output. Uses the class level property settings.
setApi ( ) Sets the mPDF API instance

Protected Methods

Method Description
definePath ( string $prop, string $dir ) : boolean Defines a mPDF temporary path if not set
parseFormat ( ) Parse the format automatically based on the orientation

Private Methods

Method Description
writePdfAttachement ( mPDF $api, String $attachement ) appends the given attachement to the generated PDF

Method Details

addPdfAttachement() public method

add an PDF to attach to the generated PDF
public addPdfAttachement ( string $filePath )
$filePath string

configure() public method

Configures mPDF options
public configure ( $options = [] )

definePath() protected static method

Defines a mPDF temporary path if not set
protected static definePath ( string $prop, string $dir ) : boolean
$prop string the mPDF constant to define
$dir string the directory to create
return boolean

execute() public method

Calls the mPDF method with parameters
public execute ( $method, $params = [] ) : mixed
return mixed

getApi() public method

Initializes (if needed) and fetches the mPDF API instance
public getApi ( ) : mPDF
return mPDF instance

getCss() public method

Fetches the content of the CSS file if supplied
public getCss ( ) : string
return string

getPdfAttachements() public method

public getPdfAttachements ( ) : array
return array Array of attachements

init() public method

public init ( )

initTempPaths() public method

Initialize folder paths to allow mpdf to write temporary data.
public initTempPaths ( )

output() public method

Generates a PDF output
public output ( $content = '', $file = '', $dest = self::DEST_BROWSER ) : mixed
return mixed

parseFormat() protected method

Parse the format automatically based on the orientation
protected parseFormat ( )

render() public method

Renders and returns the PDF output. Uses the class level property settings.
public render ( )

setApi() public method

Sets the mPDF API instance
public setApi ( )

Property Details

$_css protected_oe property

the css file content
protected $_css

$_mpdf protected_oe property

api instance
protected $_mpdf

$_pdfAttachements protected_oe property

Array of file-pathes that should be attached to the generated PDF
protected $_pdfAttachements

$content public_oe property

the HTML content to be converted to PDF
public $content

$cssFile public_oe property

css file to prepend to the PDF
public $cssFile

$cssInline public_oe property

additional inline css to append after the cssFile
public $cssInline

$defaultFont public_oe property

sets the default font-family for the new document. Uses default value set in defaultCSS unless codepage has been set to "win-1252". If codepage="win-1252", the appropriate core Adobe font will be set i.e. Helvetica, Times, or Courier.
public $defaultFont

$defaultFontSize public_oe property

sets the default document font size in points (pt)
public $defaultFontSize

$destination public_oe property

the output destination
public $destination

$filename public_oe property

the output filename
public $filename

$format public_oe property

public $format

$marginBottom public_oe property

sets the page bottom margin for the new document (in millimetres).
public $marginBottom

$marginFooter public_oe property

sets the page footer margin for the new document (in millimetres).
public $marginFooter

$marginHeader public_oe property

sets the page header margin for the new document (in millimetres).
public $marginHeader

$marginLeft public_oe property

sets the page left margin for the new document. All values should be specified as LENGTH in millimetres. If you are creating a DOUBLE-SIDED document, the margin values specified will be used for ODD pages; left and right margins will be mirrored for EVEN pages.
public $marginLeft

$marginRight public_oe property

sets the page right margin for the new document (in millimetres).
public $marginRight

$marginTop public_oe property

sets the page top margin for the new document (in millimetres).
public $marginTop

$methods public_oe property

the mPDF methods that will called in the sequence listed before rendering the content. Should be an associative array of $method => $params format, where: - $method: string, is the mPDF method / function name - $param: mixed, are the mPDF method parameters
public $methods

$mode public_oe property

specifies the mode of the new document. If the mode is set by passing a country/language string, this may also set: available fonts, text justification, and directionality RTL.
public $mode

$options public_oe property

the mPDF configuration options entered as a $key => value associative array, where: - $key: string is the mPDF configuration property name - $value: mixed is the mPDF configured property value
public $options

$orientation public_oe property

specifies the default page orientation of the new document.
public $orientation

$tempPath public_oe property

the folder path for storing the temporary data generated by mpdf. If not set this defaults to Yii::getAlias('@runtime/mpdf').
public $tempPath