diff --git a/lam/help/help.inc b/lam/help/help.inc index 66af25ef..d387a9d2 100644 --- a/lam/help/help.inc +++ b/lam/help/help.inc @@ -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.")), "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.")), + "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 // LAM Pro "501" => array ("Headline" => _("LDAP suffix"), diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index f114960b..2e52b053 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -603,13 +603,14 @@ class lamList { // PDF creation Ok if (isset($_POST['createPDFok'])) { $pdfStruct = $_POST['pdf_structure']; + $pdfFont = $_POST['pdf_font']; $option = $_POST['createFor']; $filename = ''; // create for clicked account if ($option == 'DN') { $_SESSION["accountPDF"] = new accountContainer($this->type, "accountPDF"); $_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"]); } // create for all selected accounts @@ -624,7 +625,7 @@ class lamList { $list[$i] = $_SESSION["accountPDF-$i"]; } if (sizeof($list) > 0) { - $filename = \LAM\PDF\createModulePDF($list,$pdfStruct); + $filename = \LAM\PDF\createModulePDF($list, $pdfStruct, $pdfFont); for ($i = 0; $i < sizeof($accounts); $i++) { unset($_SESSION["accountPDF-$i"]); } @@ -706,6 +707,13 @@ class lamList { $container->addElement(new htmlSubTitle(_('Create PDF file')), 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 htmlOutputText(_('Create for'))); diff --git a/lam/lib/pdf.inc b/lam/lib/pdf.inc index 6eccd359..0b8dbf45 100644 --- a/lam/lib/pdf.inc +++ b/lam/lib/pdf.inc @@ -52,10 +52,11 @@ include_once('pdfstruct.inc'); * @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 * 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 * @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(); // Get PDF structure from xml file $reader = new PDFStructureReader(); @@ -74,7 +75,7 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString = } } $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 * to create the PDF page. If not submitted the 'default.user' structure definition * 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 * @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 */ include_once("lamtcpdf.inc"); - $fontName = 'DejaVuSerif'; - $pdf = new LAMTCPDF($structure, $fontName); + $pdf = new LAMTCPDF($structure, $font); // Loop over each account and add a new page in the PDF file for it 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 foreach ($structure->getSections() as $section) { 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 = explode("\n", $info_string); foreach ($info_string as $text) { @@ -124,7 +125,7 @@ function createPdfTcpdf($structure, $accounts, $pdfKeys, $account_type, $returnA else { $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->Ln(LAMPDF_LINEHEIGHT); // 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) foreach($valueEntries as $valueEntry) { if ($valueEntry instanceof PDFLabelValue) { - printLabelValue($pdf, $valueEntry, $fontName); + printLabelValue($pdf, $valueEntry, $font); } else if ($valueEntry instanceof PDFTable) { - printTable($pdf, $valueEntry, $fontName); + printTable($pdf, $valueEntry, $font); } } } diff --git a/lam/lib/pdfstruct.inc b/lam/lib/pdfstruct.inc index 6d5e6568..39f63465 100644 --- a/lam/lib/pdfstruct.inc +++ b/lam/lib/pdfstruct.inc @@ -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', + ); +} + ?> diff --git a/lam/lib/upload.inc b/lam/lib/upload.inc index 37fc5b44..3395f1e0 100644 --- a/lam/lib/upload.inc +++ b/lam/lib/upload.inc @@ -263,6 +263,7 @@ class Uploader { private function createPDF() { $file = $_SESSION['mass_pdf']['file']; $pdfStructure = $_SESSION['mass_pdf']['structure']; + $font = $_SESSION['mass_pdf']['font']; $pdfZip = new ZipArchive(); if ($_SESSION['mass_pdf']['counter'] == 0) { $pdfZipResult = @$pdfZip->open($_SESSION['mass_pdf']['file'], ZipArchive::CREATE); @@ -294,7 +295,7 @@ class Uploader { break; } // 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'; $pdfZip->addFromString($fileName, $pdfContent); $_SESSION['mass_pdf']['counter'] ++; diff --git a/lam/templates/upload/massBuildAccounts.php b/lam/templates/upload/massBuildAccounts.php index 5313e9ee..f6bbe9f2 100644 --- a/lam/templates/upload/massBuildAccounts.php +++ b/lam/templates/upload/massBuildAccounts.php @@ -238,6 +238,7 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) { } if (isset($_POST['createPDF']) && ($_POST['createPDF'] == 'on')) { $_SESSION['mass_pdf']['structure'] = $_POST['pdfStructure']; + $_SESSION['mass_pdf']['font'] = $_POST['pdf_font']; $_SESSION['mass_pdf']['counter'] = 0; $_SESSION['mass_pdf']['file'] = '../../tmp/lam_pdf' . getRandomNumber() . '.zip'; } diff --git a/lam/templates/upload/masscreate.php b/lam/templates/upload/masscreate.php index 0bedd53c..55640082 100644 --- a/lam/templates/upload/masscreate.php +++ b/lam/templates/upload/masscreate.php @@ -288,7 +288,7 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, $selectedModules) { $createPDF = true; } $pdfCheckbox = new htmlTableExtendedInputCheckbox('createPDF', $createPDF, _('Create PDF files')); - $pdfCheckbox->setTableRowsToShow(array('pdfStructure')); + $pdfCheckbox->setTableRowsToShow(array('pdfStructure', 'pdf_font')); $inputContainer->addElement($pdfCheckbox, true); $pdfStructures = \LAM\PDF\getPDFStructures($type->getId()); $pdfSelected = array(); @@ -299,6 +299,12 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, $selectedModules) { $pdfSelected = array('default'); } $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); $uploadButton = new htmlButton('submitfile', _('Upload file and create accounts')); $uploadButton->setIconClass('upButton');