class PrincePDF in Forena Reports 8
Provides PDF file exports using Prince XML
Plugin annotation
@FrxDocument(
id= "pdf-prince",
name="PDF Generation using Prince XML",
ext="pdf"
)
Hierarchy
- class \Drupal\forena\FrxPlugin\Document\DocumentBase implements DocumentInterface uses FrxAPI
Expanded class hierarchy of PrincePDF
File
- forena_pdf/
src/ FrxPlugin/ Document/ PrincePDF.php, line 20 - PrincePDF
Namespace
Drupal\forena_pdf\FrxPlugin\DocumentView source
class PrincePDF extends DocumentBase {
use FrxAPI;
private $p;
public function __construct() {
include_once 'libraries/prince/prince.php';
$this->content_type = 'application/pdf';
$prince_path = \Drupal::config('forena_pdf.settings')
->get('prince_path');
if (class_exists('\\Prince') && forena_library_file('prince')) {
$this->p = new \Prince($prince_path);
}
}
/**
* [@inheritdoc}
*/
public function flush() {
//@TODO: figure out how to deal with options
$options = [];
//@TODO: Figure out how to pass style portions of css doucments to the PDF.
$css = '';
$style_css = '';
$disable_links = \Drupal::config('forena_pdf.settings')
->get('disable_links');
$html = $this->write_buffer;
if ($disable_links) {
$html = preg_replace('/<a href=\\"(.*?)\\">(.*?)<\\/a>/', "\\2", $html);
}
$link_class = $disable_links ? 'prince-disable-links' : '';
$output = '<html><head>';
$output .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>';
if (!empty($options['css']) || isset($r->rpt_xml->head->style)) {
$output .= '<style type="text/css">';
$output .= $css;
if ($style_css) {
$sheet = (string) $r->rpt_xml->head->style;
$output .= $sheet;
}
$output .= '</style>';
}
$output .= '<title>' . $this->title . "</title></head><body class='forena-report {$link_class}'><h1>" . $this->title . '</h1>' . $html . '</body></html>';
$prince_css = drupal_get_path('module', 'forena_pdf') . '/forena_pdf_prince.css';
// Generate the document
if ($this->p) {
$p = $this->p;
foreach ($this
->documentManager()->stylesheets as $type => $sheets) {
foreach ($sheets as $sheet) {
switch ($type) {
case 'all':
case 'print':
case 'screen':
case 'pdf':
$p
->addStyleSheet($sheet);
break;
}
}
}
$msg = array();
$pdf_file = tempnam(file_directory_temp(), 'prince_pdf');
if ($p
->convert_string_to_file($output, $pdf_file, $msg)) {
$output = file_get_contents($pdf_file);
}
else {
$this
->app()
->error('Could not generate PDF File', print_r($msg, 1));
$output = '';
}
// We don't care if this fails because it's temproary.
@unlink($pdf_file);
return $output;
}
else {
$this
->error(t('Prince XML Not Properly Installed'));
return '';
}
}
/**
* {@inheritdoc}
*/
public function header() {
$this->headers['Content-Type'] = $this->content_type;
$this->headers['Cache-Control'] = '';
$this->headers['Pragma'] = '';
$this->headers['Cache-Control'] = 'must-revalidate';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DocumentBase:: |
public | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
protected | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
protected | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
protected | property | ||
DocumentBase:: |
protected | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
protected | property | ||
DocumentBase:: |
public | function | ||
DocumentBase:: |
public | function | Wrapper function for check output to default the right type. | |
DocumentBase:: |
public | function |
Clear the buffer Overrides DocumentInterface:: |
|
DocumentBase:: |
public | function | Perform character set conversion | |
DocumentBase:: |
public | function |
No default footer. Overrides DocumentInterface:: |
1 |
DocumentBase:: |
public | function | ||
DocumentBase:: |
public | function |
Overrides DocumentInterface:: |
|
DocumentBase:: |
public | function |
Overrides DocumentInterface:: |
|
DocumentBase:: |
public | function |
Write Overrides DocumentInterface:: |
|
FrxAPI:: |
public | function | Returns containing application service | |
FrxAPI:: |
public | function | Get the current data context. | |
FrxAPI:: |
public | function | ||
FrxAPI:: |
public | function | Returns the data manager service | |
FrxAPI:: |
public | function | Return Data Service | |
FrxAPI:: |
public | function | Returns the fornea document manager | |
FrxAPI:: |
public | function | Report an error | |
FrxAPI:: |
public | function | Get the context of a specific id. | |
FrxAPI:: |
public | function | Get the current document | |
FrxAPI:: |
public | function | Load the contents of a file in the report file system. | |
FrxAPI:: |
function | Enter description here... | 1 | |
FrxAPI:: |
public | function | Pop data off of the stack. | |
FrxAPI:: |
public | function | Push data onto the Stack | |
FrxAPI:: |
public | function | Run a report with a particular format. | 1 |
FrxAPI:: |
public | function | Get the current report file system. | |
FrxAPI:: |
public | function | Set Data context by id. | |
FrxAPI:: |
public | function | Change to a specific document type. | |
FrxAPI:: |
public | function | Get list of skins. | |
PrincePDF:: |
private | property | ||
PrincePDF:: |
public | function |
[@inheritdoc} Overrides DocumentBase:: |
|
PrincePDF:: |
public | function |
Default implementation to put in content type based headers. Overrides DocumentBase:: |
|
PrincePDF:: |
public | function |