added font selection

This commit is contained in:
Roland Gruber 2017-10-23 17:58:08 +02:00
parent 8ccaf564ed
commit 6b97541530
7 changed files with 47 additions and 13 deletions

View File

@ -256,6 +256,8 @@ $helpArray = array (
"Text" => _("Here you can export PDF structures to other server profiles (overwrite existing). You may also export a structure to the global templates. In this case it will always be copied to all server profiles that do not yet have a structure with this name.")), "Text" => _("Here you can export PDF structures to other server profiles (overwrite existing). You may also export a structure to the global templates. In this case it will always be copied to all server profiles that do not yet have a structure with this name.")),
"410" => array ("Headline" => _("Alternate recipient"), "410" => array ("Headline" => _("Alternate recipient"),
"Text" => _("Here you can enter an alternative mail address for the password. To use the user's primary email address please leave the field blank.")), "Text" => _("Here you can enter an alternative mail address for the password. To use the user's primary email address please leave the field blank.")),
"411" => array ("Headline" => _("Font"),
"Text" => _("Please select the font for the PDF file. Dejavu will work on all systems but does not support e.g. Chinese and Japan. The other fonts require that an appropriate font is installed on the system where the PDF is opened.")),
// 500 - 599 // 500 - 599
// LAM Pro // LAM Pro
"501" => array ("Headline" => _("LDAP suffix"), "501" => array ("Headline" => _("LDAP suffix"),

View File

@ -603,13 +603,14 @@ class lamList {
// PDF creation Ok // PDF creation Ok
if (isset($_POST['createPDFok'])) { if (isset($_POST['createPDFok'])) {
$pdfStruct = $_POST['pdf_structure']; $pdfStruct = $_POST['pdf_structure'];
$pdfFont = $_POST['pdf_font'];
$option = $_POST['createFor']; $option = $_POST['createFor'];
$filename = ''; $filename = '';
// create for clicked account // create for clicked account
if ($option == 'DN') { if ($option == 'DN') {
$_SESSION["accountPDF"] = new accountContainer($this->type, "accountPDF"); $_SESSION["accountPDF"] = new accountContainer($this->type, "accountPDF");
$_SESSION["accountPDF"]->load_account(base64_decode($_POST['clickedAccount'])); $_SESSION["accountPDF"]->load_account(base64_decode($_POST['clickedAccount']));
$filename = \LAM\PDF\createModulePDF(array($_SESSION["accountPDF"]),$pdfStruct); $filename = \LAM\PDF\createModulePDF(array($_SESSION["accountPDF"]), $pdfStruct, $pdfFont);
unset($_SESSION["accountPDF"]); unset($_SESSION["accountPDF"]);
} }
// create for all selected accounts // create for all selected accounts
@ -624,7 +625,7 @@ class lamList {
$list[$i] = $_SESSION["accountPDF-$i"]; $list[$i] = $_SESSION["accountPDF-$i"];
} }
if (sizeof($list) > 0) { if (sizeof($list) > 0) {
$filename = \LAM\PDF\createModulePDF($list,$pdfStruct); $filename = \LAM\PDF\createModulePDF($list, $pdfStruct, $pdfFont);
for ($i = 0; $i < sizeof($accounts); $i++) { for ($i = 0; $i < sizeof($accounts); $i++) {
unset($_SESSION["accountPDF-$i"]); unset($_SESSION["accountPDF-$i"]);
} }
@ -706,6 +707,13 @@ class lamList {
$container->addElement(new htmlSubTitle(_('Create PDF file')), true); $container->addElement(new htmlSubTitle(_('Create PDF file')), true);
$container->addElement(new htmlTableExtendedSelect('pdf_structure', $pdf_structures, array('default'), _('PDF structure'), '405'), true); $container->addElement(new htmlTableExtendedSelect('pdf_structure', $pdf_structures, array('default'), _('PDF structure'), '405'), true);
$fonts = \LAM\PDF\getPdfFonts();
$fontSelection = new htmlTableExtendedSelect('pdf_font', $fonts, array(), _('Font'), '411');
$fontSelection->setCSSClasses(array('lam-save-selection'));
$fontSelection->setHasDescriptiveElements(true);
$fontSelection->setSortElements(false);
$container->addElement($fontSelection, true);
$container->addElement(new htmlEqualWidth(array('pdf_font', 'pdf_structure')));
$container->addElement(new htmlSpacer(null, '5px'), true); $container->addElement(new htmlSpacer(null, '5px'), true);
$container->addElement(new htmlOutputText(_('Create for'))); $container->addElement(new htmlOutputText(_('Create for')));

View File

@ -52,10 +52,11 @@ include_once('pdfstruct.inc');
* @param string $pdf_structure The filename of the structure definition that should be used * @param string $pdf_structure The filename of the structure definition that should be used
* to create the PDF page. If not submitted the 'default.user' structure definition * to create the PDF page. If not submitted the 'default.user' structure definition
* for the appropriate account type. * for the appropriate account type.
* @param string $font font to use (e.g. DejaVu)
* @param $returnAsString returns the PDF output as String value instead of writing it to a file * @param $returnAsString returns the PDF output as String value instead of writing it to a file
* @return String PDF file name * @return String PDF file name
*/ */
function createModulePDF($accounts, $pdf_structure="default", $returnAsString = false) { function createModulePDF($accounts, $pdf_structure="default", $font, $returnAsString = false) {
$account_type = $accounts[0]->get_type(); $account_type = $accounts[0]->get_type();
// Get PDF structure from xml file // Get PDF structure from xml file
$reader = new PDFStructureReader(); $reader = new PDFStructureReader();
@ -74,7 +75,7 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
} }
} }
$pdfKeys = array_unique($pdfKeys); $pdfKeys = array_unique($pdfKeys);
return createPdfTcpdf($structure, $accounts, $pdfKeys, $account_type, $returnAsString); return createPdf($structure, $accounts, $pdfKeys, $account_type, $font, $returnAsString);
} }
/** /**
@ -86,14 +87,14 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
* @param string $pdf_structure The filename of the structure definition that should be used * @param string $pdf_structure The filename of the structure definition that should be used
* to create the PDF page. If not submitted the 'default.user' structure definition * to create the PDF page. If not submitted the 'default.user' structure definition
* for the appropriate account type. * for the appropriate account type.
* @param string $font font to use
* @param $returnAsString returns the PDF output as String value instead of writing it to a file * @param $returnAsString returns the PDF output as String value instead of writing it to a file
* @return String PDF file name * @return String PDF file name
*/ */
function createPdfTcpdf($structure, $accounts, $pdfKeys, $account_type, $returnAsString) { function createPdf($structure, $accounts, $pdfKeys, $account_type, $font, $returnAsString) {
/** PDF generator class */ /** PDF generator class */
include_once("lamtcpdf.inc"); include_once("lamtcpdf.inc");
$fontName = 'DejaVuSerif'; $pdf = new LAMTCPDF($structure, $font);
$pdf = new LAMTCPDF($structure, $fontName);
// Loop over each account and add a new page in the PDF file for it // Loop over each account and add a new page in the PDF file for it
foreach($accounts as $account) { foreach($accounts as $account) {
@ -107,7 +108,7 @@ function createPdfTcpdf($structure, $accounts, $pdfKeys, $account_type, $returnA
// Now create the PDF file acording to the structure with the submitted values // Now create the PDF file acording to the structure with the submitted values
foreach ($structure->getSections() as $section) { foreach ($structure->getSections() as $section) {
if ($section instanceof PDFTextSection) { if ($section instanceof PDFTextSection) {
$pdf->setFont($fontName, "", LAMPDF_FONT_SIZE); $pdf->setFont($font, "", LAMPDF_FONT_SIZE);
$info_string = str_replace("\r", "", $section->getText()); $info_string = str_replace("\r", "", $section->getText());
$info_string = explode("\n", $info_string); $info_string = explode("\n", $info_string);
foreach ($info_string as $text) { foreach ($info_string as $text) {
@ -124,7 +125,7 @@ function createPdfTcpdf($structure, $accounts, $pdfKeys, $account_type, $returnA
else { else {
$section_headline = $section->getTitle(); $section_headline = $section->getTitle();
} }
$pdf->setFont($fontName, "B", LAMPDF_FONT_SIZE_BIG); $pdf->setFont($font, "B", LAMPDF_FONT_SIZE_BIG);
$pdf->Write(0, $section_headline, '', false, 'L', true); $pdf->Write(0, $section_headline, '', false, 'L', true);
$pdf->Ln(LAMPDF_LINEHEIGHT); $pdf->Ln(LAMPDF_LINEHEIGHT);
// entries // entries
@ -138,10 +139,10 @@ function createPdfTcpdf($structure, $accounts, $pdfKeys, $account_type, $returnA
// Loop over all rows of this entry (most of the time this will be just one) // Loop over all rows of this entry (most of the time this will be just one)
foreach($valueEntries as $valueEntry) { foreach($valueEntries as $valueEntry) {
if ($valueEntry instanceof PDFLabelValue) { if ($valueEntry instanceof PDFLabelValue) {
printLabelValue($pdf, $valueEntry, $fontName); printLabelValue($pdf, $valueEntry, $font);
} }
else if ($valueEntry instanceof PDFTable) { else if ($valueEntry instanceof PDFTable) {
printTable($pdf, $valueEntry, $fontName); printTable($pdf, $valueEntry, $font);
} }
} }
} }

View File

@ -731,4 +731,19 @@ class PDFSectionEntry {
} }
/**
* Returns a list of possible fonts.
*
* @return array list of fonts (description => font name)
*/
function getPdfFonts() {
return array(
'DejaVu' => 'DejaVuSerif',
_('Chinese Traditional') => 'cid0ct',
_('Chinese Simplified') => 'cid0cs',
_('Japan') => 'cid0jp',
_('Korean') => 'cid0kr',
);
}
?> ?>

View File

@ -263,6 +263,7 @@ class Uploader {
private function createPDF() { private function createPDF() {
$file = $_SESSION['mass_pdf']['file']; $file = $_SESSION['mass_pdf']['file'];
$pdfStructure = $_SESSION['mass_pdf']['structure']; $pdfStructure = $_SESSION['mass_pdf']['structure'];
$font = $_SESSION['mass_pdf']['font'];
$pdfZip = new ZipArchive(); $pdfZip = new ZipArchive();
if ($_SESSION['mass_pdf']['counter'] == 0) { if ($_SESSION['mass_pdf']['counter'] == 0) {
$pdfZipResult = @$pdfZip->open($_SESSION['mass_pdf']['file'], ZipArchive::CREATE); $pdfZipResult = @$pdfZip->open($_SESSION['mass_pdf']['file'], ZipArchive::CREATE);
@ -294,7 +295,7 @@ class Uploader {
break; break;
} }
// create and save PDF // create and save PDF
$pdfContent = \LAM\PDF\createModulePDF(array($_SESSION['mass_pdfAccount']), $pdfStructure, true); $pdfContent = \LAM\PDF\createModulePDF(array($_SESSION['mass_pdfAccount']), $pdfStructure, $font, true);
$fileName = $dn . '.pdf'; $fileName = $dn . '.pdf';
$pdfZip->addFromString($fileName, $pdfContent); $pdfZip->addFromString($fileName, $pdfContent);
$_SESSION['mass_pdf']['counter'] ++; $_SESSION['mass_pdf']['counter'] ++;

View File

@ -238,6 +238,7 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
} }
if (isset($_POST['createPDF']) && ($_POST['createPDF'] == 'on')) { if (isset($_POST['createPDF']) && ($_POST['createPDF'] == 'on')) {
$_SESSION['mass_pdf']['structure'] = $_POST['pdfStructure']; $_SESSION['mass_pdf']['structure'] = $_POST['pdfStructure'];
$_SESSION['mass_pdf']['font'] = $_POST['pdf_font'];
$_SESSION['mass_pdf']['counter'] = 0; $_SESSION['mass_pdf']['counter'] = 0;
$_SESSION['mass_pdf']['file'] = '../../tmp/lam_pdf' . getRandomNumber() . '.zip'; $_SESSION['mass_pdf']['file'] = '../../tmp/lam_pdf' . getRandomNumber() . '.zip';
} }

View File

@ -288,7 +288,7 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, $selectedModules) {
$createPDF = true; $createPDF = true;
} }
$pdfCheckbox = new htmlTableExtendedInputCheckbox('createPDF', $createPDF, _('Create PDF files')); $pdfCheckbox = new htmlTableExtendedInputCheckbox('createPDF', $createPDF, _('Create PDF files'));
$pdfCheckbox->setTableRowsToShow(array('pdfStructure')); $pdfCheckbox->setTableRowsToShow(array('pdfStructure', 'pdf_font'));
$inputContainer->addElement($pdfCheckbox, true); $inputContainer->addElement($pdfCheckbox, true);
$pdfStructures = \LAM\PDF\getPDFStructures($type->getId()); $pdfStructures = \LAM\PDF\getPDFStructures($type->getId());
$pdfSelected = array(); $pdfSelected = array();
@ -299,6 +299,12 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, $selectedModules) {
$pdfSelected = array('default'); $pdfSelected = array('default');
} }
$inputContainer->addElement(new htmlTableExtendedSelect('pdfStructure', $pdfStructures, $pdfSelected, _('PDF structure')), true); $inputContainer->addElement(new htmlTableExtendedSelect('pdfStructure', $pdfStructures, $pdfSelected, _('PDF structure')), true);
$fonts = \LAM\PDF\getPdfFonts();
$fontSelection = new htmlTableExtendedSelect('pdf_font', $fonts, array(), _('Font'), '411');
$fontSelection->setCSSClasses(array('lam-save-selection'));
$fontSelection->setHasDescriptiveElements(true);
$fontSelection->setSortElements(false);
$inputContainer->addElement($fontSelection, true);
$inputContainer->addElement(new htmlSpacer(null, '5px'), true); $inputContainer->addElement(new htmlSpacer(null, '5px'), true);
$uploadButton = new htmlButton('submitfile', _('Upload file and create accounts')); $uploadButton = new htmlButton('submitfile', _('Upload file and create accounts'));
$uploadButton->setIconClass('upButton'); $uploadButton->setIconClass('upButton');