The prince.php file defines a class called Prince that contains methods that can be called to convert XML and HTML documents into PDF.
Note that the Prince class is written for PHP 5, and requires modification to work with PHP 4.
When instantiating the Prince class, pass in the full path of the Prince executable to the constructor as a string argument. For example, on Linux or MacOS X:
$prince = new Prince('/usr/local/bin/prince');
On Windows, be sure to specify the path to the prince.exe
file
located within the Engine\bin
subfolder of the Prince
installation.
convert_file
convert_file_to_file
convert_multiple_files
convert_string_to_file
convert_file_to_passthru
convert_multiple_files_to_passthru
convert_string_to_passthru
addStyleSheet
clearStyleSheets
addScript
clearScripts
addFileAttachment
clearFileAttachments
setLicenseFile
setLicenseKey
setInputType
setHTML
setJavaScript
setLog
setBaseURL
setXInclude
setHttpUser
setHttpPassword
setHttpProxy
setHttpTimeout
setInsecure
setFileRoot
setEmbedFonts
setSubsetFonts
setNoArtificialFonts
setAuthMethod
setAuthUser
setAuthPassword
setAuthServer
setAuthScheme
setNoAuthPreemptive
setPageSize
setPageMargin
setCompress
setPDFTitle
setPDFSubject
setPDFAuthor
setPDFKeywords
setPDFCreator
setEncrypt
setEncryptInfo
setOptions
public function convert_file($xmlPath, &$msgs = array())
Convert an XML or HTML file to a PDF file. The name of the output PDF file will be the same as the name of the input file but with an extension of ".pdf". Returns true if a PDF file was generated successfully.
xmlPath
msgs
'err'
, 'wrn'
or 'inf'
), the message
location (eg. a filename) and the message text.returns
public function convert_file_to_file($xmlPath, $pdfPath, &$msgs = array())
Convert an XML or HTML file to a PDF file. Returns true if a PDF file was generated successfully.
xmlPath
pdfPath
msgs
'err'
, 'wrn'
or 'inf'
), the message
location (eg. a filename) and the message text.returns
public function convert_multiple_files($xmlPaths, $pdfPath, &$msgs = array())
Convert multiple XML or HTML files to a PDF file. Returns true if a PDF file was generated successfully.
xmlPaths
pdfPath
msgs
'err'
, 'wrn'
or 'inf'
), the message
location (eg. a filename) and the message text.returns
public function convert_string_to_file($xmlString, $pdfPath, &$msgs = array())
Convert an XML or HTML string to a PDF file. Returns true if a PDF file was generated successfully.
xmlString
pdfPath
msgs
'err'
, 'wrn'
or 'inf'
), the message
location (eg. a filename) and the message text.returns
public function convert_file_to_passthru($xmlPath, &$msgs = array())
Convert an XML or HTML file to a PDF file, which will be passed through to the output buffer of the current PHP page. Returns true if a PDF file was generated successfully.
xmlPath
msgs
'err'
, 'wrn'
or 'inf'
), the message
location (eg. a filename) and the message text.returns
Note that to have the browser correctly display the PDF output, the following two lines will be needed before the convert method is called:
header('Content-Type: application/pdf'); header('Content-Disposition: inline; filename="foo.pdf"');
You may also specify attachment
for the Content-Disposition
header instead of inline
, so that the browser will prompt the
user to save the PDF file instead of displaying it.
public function convert_multiple_files_to_passthru($xmlPaths, &$msgs = array())
Convert multiple XML or HTML files to a PDF file, which will be passed through to the output buffer of the current PHP page. Returns true if a PDF file was generated successfully.
xmlPaths
msgs
'err'
, 'wrn'
or 'inf'
), the message
location (eg. a filename) and the message text.returns
Note that to have the browser correctly display the PDF output, the following two lines will be needed before the convert method is called:
header('Content-Type: application/pdf'); header('Content-Disposition: inline; filename="foo.pdf"');
You may also specify attachment
for the Content-Disposition
header instead of inline
, so that the browser will prompt the
user to save the PDF file instead of displaying it.
public function convert_string_to_passthru($xmlString, &$msgs = array())
Convert an XML or HTML string to a PDF file, which will be passed through to the output buffer of the current PHP page. Returns true if a PDF file was generated successfully.
xmlString
msgs
'err'
, 'wrn'
or 'inf'
), the message
location (eg. a filename) and the message text.returns
Note that to have the browser correctly display the PDF output, the following two lines will be needed before the convert method is called:
header('Content-Type: application/pdf'); header('Content-Disposition: inline; filename="foo.pdf"');
You may also specify attachment
for the Content-Disposition
header instead of inline
, so that the browser will prompt the
user to save the PDF file instead of displaying it.
public function addStyleSheet($cssPath)
Add a CSS style sheet that will be applied to each input document.
The addStyleSheet
function can be called more than once to add
multiple style sheets. This function can called before calling a convert
function.
cssPath
public function clearStyleSheets()
Clear all of the CSS style sheets accumulated by calling
addStyleSheet
.
public function addScript($jsPath)
Add a JavaScript script that will be run before conversion.
The addScript
function can be called more than once to add
multiple scripts. This function can be called before calling a convert
function.
jsPath
public function clearScripts()
Clear all of the scripts accumulated by calling
addScript
.
public function addFileAttachment($filePath)
Add a file attachment that will be attached to the PDF file.
TheaddFileAttachment
can be called more
than once to add multiple file attachments.
filePath
public function clearFileAttachments()
Clear all of the file attachments accumulated by calling
addFileAttachment
.
public function setLicenseFile($file)
Specify the license file.
file
public function setLicenseKey($key)
Specify the license key.
key
public function setInputType($inputType)
Specify the input type of the document.
inputType
public function setHTML($html)
Specify whether documents should be parsed as HTML or XML/XHTML.
html
public function setJavaScript($js)
Specify whether JavaScript found in documents should be run.
js
public function setLog($logFile)
Specify a file that Prince should use to log error/warning messages.
logFile
public function setBaseURL($baseURL)
Specify the base URL of the input document.
baseURL
public function setXInclude($xinclude)
Specify whether XML Inclusions (XInclude) processing should be applied to input documents. XInclude processing will be performed by default unless explicitly disabled.
xinclude
public function setHttpUser($user)
Specify a username to use when fetching remote resources over HTTP.
user
public function setHttpPassword($password)
Specify a password to use when fetching remote resources over HTTP.
password
public function setHttpProxy($proxy)
Specify the URL for the HTTP proxy server, if needed.
proxy
public function setHttpTimeout($timeout)
Specify the timeout for HTTP requests.
timeout
public function setInsecure($insecure)
Specify whether to disable SSL verification.
insecure
public function setFileRoot($fileRoot)
Specify the root directory for absolute filenames. This can be used when converting a local file that uses absolute paths to refer to web resources. For example, /images/logo.jpg can be rewritten to /usr/share/images/logo.jpg by specifying "/usr/share" as the root.
fileRoot
public function setEmbedFonts($embedFonts)
Specify whether fonts should be embedded in the output PDF file. Fonts will be embedded by default unless explicitly disabled.
embedFonts
public function setSubsetFonts($subsetFonts)
Specify whether embedded fonts should be subset in the output PDF file. Fonts will be subset by default unless explicitly disabled.
subsetFonts
public function setNoArtificialFonts($noArtificialFonts)
Specify whether artificial bold/italic fonts should be generated if necessary. Artificial fonts are enabled by default.
noArtificialFonts
public function setAuthMethod($authMethod)
Specify HTTP authentication methods. (basic, digest, ntlm, negotiate)
authMethod
public function setAuthUser($authUser)
Specify username for HTTP authentication.
authUser
public function setAuthPassword($authPassword)
Specify password for HTTP authentication.
authPassword
public function setAuthServer($authServer)
Only send USER:PASS to this server.
authServer
public function setAuthScheme($authScheme)
Only send USER:PASS for this scheme. (HTTP, HTTPS)
authScheme
public function setNoAuthPreemptive($noAuthPreemptive)
Do not authenticate with named servers until asked.
noAuthPreemptive
public function setPageSize($pageSize)
Specify the page size (eg. A4).
pageSize
public function setPageMargin($pageMargin)
Specify the page margin (eg. 20mm).
pageMargin
public function setCompress($compress)
Specify whether compression should be applied to the output PDF file. Compression will be applied by default unless explicitly disabled.
compress
public function setPDFTitle($pdfTitle)
Specify the document title for PDF metadata.
public function setPDFSubject($pdfSubject)
Specify the document subject for PDF metadata.
public function setPDFAuthor($pdfAuthor)
Specify the document author for PDF metadata.
public function setPDFKeywords($pdfKeywords)
Specify the document keywords for PDF metadata.
public function setPDFCreator($pdfCreator)
Specify the document creator for PDF metadata.
public function setEncrypt($encrypt)
Specify whether encryption should be applied to the output PDF file. Encryption will not be applied by default unless explicitly enabled.
encrypt
public function setEncryptInfo($keyBits, $userPassword, $ownerPassword, $disallowPrint = false, $disallowModify = false, $disallowCopy = false, $disallowAnnotate = false)
Set the parameters used for PDF encryption. Calling this method will
also enable encryption, equivalent to calling
setEncrypt(true)
. It should be called before calling a convert
method for encryption information to be applied.
keyBits
userPassword
ownerPassword
disallowPrint
disallowModify
disallowCopy
disallowAnnotate
public function setOptions($options)
Set other options.
options
Copyright © 2005-2013 YesLogic Pty. Ltd.