replace internal PDF API

This commit is contained in:
Roland Gruber 2017-02-15 21:45:26 +01:00
parent 581eb84598
commit ddeafb3503
3 changed files with 178 additions and 97 deletions

View File

@ -33,6 +33,9 @@ $Id$
* @see baseModule
*/
/** PDF functions */
include_once('pdf.inc');
/**
* Parent class of all account modules.
* It implements the complete module interface and uses meta-data
@ -838,7 +841,8 @@ abstract class baseModule {
// TODO workaround for UFPDF, remove when migrated to other PDF library
$value = trim($value);
}
$result[get_class($this) . '_' . $name] = array('<block><key>' . $label . '</key><value>' . $value . '</value></block>');
$result[get_class($this) . '_' . $name][] = new PDFLabelValue($label, $value);
// $result[get_class($this) . '_' . $name] = array('<block><key>' . $label . '</key><value>' . $value . '</value></block>');
}
/**
@ -855,7 +859,8 @@ abstract class baseModule {
natcasesort($value);
$value = implode($delimiter, $value);
}
$result[get_class($this) . '_' . $name] = array('<block><key>' . $label . '</key><value>' . $value . '</value></block>');
$result[get_class($this) . '_' . $name][] = new PDFLabelValue($label, $value);
// $result[get_class($this) . '_' . $name] = array('<block><key>' . $label . '</key><value>' . $value . '</value></block>');
}
/**
@ -869,7 +874,8 @@ abstract class baseModule {
if (empty($table->rows)) {
return;
}
if (!empty($table->label)) {
$result[get_class($this) . '_' . $name][] = $table;
/* if (!empty($table->label)) {
$result[get_class($this) . '_' . $name][] = '<block><tr><td><b>' . $table->label . ':</b></td></tr></block>';
}
foreach ($table->rows as $row) {
@ -881,7 +887,7 @@ abstract class baseModule {
}
$xml .= '</tr></block>';
$result[get_class($this) . '_' . $name][] = $xml;
}
}*/
}
/**
@ -1963,80 +1969,4 @@ abstract class baseModule {
}
/**
* Represents a table for PDF export.
*
* @package PDF
* @author Roland Gruber
*/
class PDFTable {
/** optional label of table */
public $label = null;
/** list of PDFTableRow elements */
public $rows = array();
/**
* Constructor
*
* @param String $label label
*/
public function __construct($label = null) {
$this->label = $label;
}
}
/**
* Represents a table row for PDF export.
*
* @package PDF
* @author Roland Gruber
*/
class PDFTableRow {
/** list of PDFTableCell */
public $cells = array();
}
/**
* Represents a table cell for PDF export.
*
* @package PDF
* @author Roland Gruber
*/
class PDFTableCell {
const ALIGN_LEFT = 'L';
const ALIGN_RIGHT = 'R';
const ALIGN_CENTER = 'C';
/** content text of cell */
public $content = '';
/** text alignment */
public $align = self::ALIGN_LEFT;
/** cell width (e.g. "20%") */
public $width = null;
/** bold text */
public $bold = false;
/**
* Constructor.
*
* @param String $content cell content
* @param String $width width (e.g. "20%")
* @param String $align cell alignment (default: left)
* @param boolean $bold print in bold
*/
public function __construct($content, $width = null, $align = null, $bold = false) {
$this->content = empty($content) ? ' ' : $content;
$this->align = ($align == null) ? self::ALIGN_LEFT : $align;
$this->width = $width;
$this->bold = $bold;
}
}
?>

View File

@ -2018,7 +2018,8 @@ class accountContainer {
if (isset($this->finalDN)) {
$dn = $this->finalDN;
}
$return = array_merge($return,array('main_dn' => array('<block><key>' . _('DN') . '</key><value>' . $dn . '</value></block>')));
$return = array_merge($return,array('main_dn' => array(new PDFLabelValue(_('DN'), $dn))));
//$return = array_merge($return,array('main_dn' => array('<block><key>' . _('DN') . '</key><value>' . $dn . '</value></block>')));
return $return;
}

View File

@ -33,6 +33,7 @@ $Id$
/** PDF line width */
define('LAMPDF_LINEWIDTH',190);
define('LAMPDF_FONT_SIZE', 7);
/** XML functions */
include_once('xml_parser.inc');
@ -138,18 +139,21 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
// skip non-existent entries
if (isset($entries[$name])) {
// Get current entry
$value_entry = $entries[$name];
$valueEntries = $entries[$name];
// Print entry only when module sumitted values for it
if(is_array($value_entry)) {
if(is_array($valueEntries)) {
// Loop over all rows of this entry (most of the time this will be just one)
foreach($value_entry as $line) {
foreach($valueEntries as $valueEntry) {
if ($valueEntry instanceof PDFLabelValue) {
printLabelValue($pdf, $valueEntry, $fontName);
}
// Substitue XML syntax with valid FPDF methods
$methods = processLine($line,true,$fontName);
/**$methods = processLine($line,true,$fontName);
// Call every method
foreach($methods as $method) {
call_user_func_array(array(&$pdf,$method[0]),$method[1]);
}
}*/
}
}
}
@ -177,19 +181,26 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
/**
* Creates a section headline.
*
* @param string $line section name
* @param PDFEntry $entry content entry
*
* @return string XML code for headline
* @return string headline
*/
function getSectionHeadline($line) {
$headline_pattern = '/<block>.*<value>(.*)<\/value><\/block>/';
if(preg_match($headline_pattern,$line,$matches)) {
$valueStyle = processFormatTags($matches[1],'');
return $valueStyle[1];
}
else {
return '';
}
function getSectionHeadline($entry) {
return $entry->getLabel();
}
/**
* Prints a PDFLabelValue entry.
*
* @param lamPDF $pdf PDF
* @param PDFLabelValue $valueEntry entry
* @param string $fontName font name
*/
function printLabelValue(&$pdf, $valueEntry, $fontName) {
$pdf->SetFont($fontName, 'B', LAMPDF_FONT_SIZE);
$pdf->Cell(50, 5, $valueEntry->getLabel() . ':',0,0,'R',0);
$pdf->SetFont($fontName, '', LAMPDF_FONT_SIZE);
$pdf->MultiCell(0, 5, $valueEntry->getValue(), 0, 'L', 0);
}
/**
@ -344,3 +355,142 @@ function processAttributes($attrs,$return = array()) {
return $return;
}
}
interface PDFEntry {
/**
* Returns the label of the entry.
*
* @return string label
*/
public function getLabel();
}
/**
* Represents a table for PDF export.
*
* @package PDF
* @author Roland Gruber
*/
class PDFTable implements PDFEntry {
/** optional label of table */
private $label = '';
/** list of PDFTableRow elements */
public $rows = array();
/**
* Constructor
*
* @param String $label label
*/
public function __construct($label = null) {
$this->label = $label;
}
/**
* Returns the label.
*
* @return string $label label
*/
public function getLabel() {
return $this->label;
}
}
/**
* Represents a table row for PDF export.
*
* @package PDF
* @author Roland Gruber
*/
class PDFTableRow {
/** list of PDFTableCell */
public $cells = array();
}
/**
* Represents a table cell for PDF export.
*
* @package PDF
* @author Roland Gruber
*/
class PDFTableCell {
const ALIGN_LEFT = 'L';
const ALIGN_RIGHT = 'R';
const ALIGN_CENTER = 'C';
/** content text of cell */
public $content = '';
/** text alignment */
public $align = self::ALIGN_LEFT;
/** cell width (e.g. "20%") */
public $width = null;
/** bold text */
public $bold = false;
/**
* Constructor.
*
* @param String $content cell content
* @param String $width width (e.g. "20%")
* @param String $align cell alignment (default: left)
* @param boolean $bold print in bold
*/
public function __construct($content, $width = null, $align = null, $bold = false) {
$this->content = empty($content) ? ' ' : $content;
$this->align = ($align == null) ? self::ALIGN_LEFT : $align;
$this->width = $width;
$this->bold = $bold;
}
}
/**
* Simple PDF object to print label value entries.
*
* @package PDF
* @author Roland Gruber
*/
class PDFLabelValue implements PDFEntry {
private $label = '';
private $value = '';
/**
* Constructor
*
* @param string $label label
* @param string $value value
*/
public function __construct($label, $value) {
$this->label = $label;
$this->value = $value;
}
/**
* Returns the label.
*
* @return string $label label
*/
public function getLabel() {
return $this->label;
}
/**
* Returns the value.
*
* @return string $value value
*/
public function getValue() {
return $this->value;
}
}