diff --git a/application/pdfpage.class.inc.php b/application/pdfpage.class.inc.php index cabdafbc5..f0705d801 100644 --- a/application/pdfpage.class.inc.php +++ b/application/pdfpage.class.inc.php @@ -1,4 +1,5 @@ sDocumentTitle = $sDocumentTitle; @@ -23,20 +24,20 @@ class iTopPDF extends TCPDF { // Title // Set font - $this->SetFont('dejavusans', 'B', 10); - + $this->SetFont(self::GetPdfFont(), 'B', 10); + $iPageNumberWidth = 25; $aMargins = $this->getMargins(); - + // Display the title (centered) $this->SetXY($aMargins['left'] + $iPageNumberWidth, 0); $this->MultiCell($this->getPageWidth() - $aMargins['left'] - $aMargins['right'] - 2*$iPageNumberWidth, 15, $this->sDocumentTitle, 0, 'C', false, 0 /* $ln */, '', '', true, 0, false, true, 15, 'M' /* $valign */); - $this->SetFont('dejavusans', '', 10); - + $this->SetFont(self::GetPdfFont(), '', 10); + // Display the page number (right aligned) // Warning: the 'R'ight alignment does not work when using placeholders like $this->getAliasNumPage() or $this->getAliasNbPages() $this->MultiCell($iPageNumberWidth, 15, Dict::Format('Core:BulkExport:PDF:PageNumber' ,$this->page), 0, 'R', false, 0 /* $ln */, '', '', true, 0, false, true, 15, 'M' /* $valign */); - + // Branding logo $sBrandingIcon = APPROOT.'images/itop-logo.png'; if (file_exists(MODULESROOT.'branding/main-logo.png')) @@ -51,6 +52,17 @@ class iTopPDF extends TCPDF { // No footer } + + /** + * @return string font in the config file (export_pdf_font) + */ + public static function GetPdfFont() + { + $oConfig = utils::GetConfig(); + $sPdfFont = $oConfig->Get('export_pdf_font'); + + return $sPdfFont; + } } /** @@ -58,42 +70,39 @@ class iTopPDF extends TCPDF */ class PDFPage extends WebPage { - /** - * Instance of the TCPDF object for creating the PDF - * @var TCPDF - */ + /** @var \iTopPDF Instance of the TCPDF object for creating the PDF */ protected $oPdf; - + public function __construct($s_title, $sPageFormat = 'A4', $sPageOrientation = 'L') { parent::__construct($s_title); define(K_PATH_FONTS, APPROOT.'lib/tcpdf/fonts'); $this->oPdf = new iTopPDF($sPageOrientation, 'mm', $sPageFormat, true, 'UTF-8', false); - + // set document information $this->oPdf->SetCreator(PDF_CREATOR); $this->oPdf->SetAuthor('iTop'); $this->oPdf->SetTitle($s_title); $this->oPdf->SetDocumentTitle($s_title); - + $this->oPdf->setFontSubsetting(true); - + // Set font // dejavusans is a UTF-8 Unicode font. Standard PDF fonts like helvetica or times new roman are NOT UTF-8 - $this->oPdf->SetFont('dejavusans', '', 10, '', true); - + $this->oPdf->SetFont(iTopPDF::GetPdfFont(), '', 10, '', true); + // set auto page breaks $this->oPdf->SetAutoPageBreak(true, 15); // 15 mm break margin at the bottom $this->oPdf->SetTopMargin(15); - + // Add a page, we're ready to start $this->oPdf->AddPage(); - + $this->SetContentDisposition('inline', $s_title.'.pdf'); $this->SetDefaultStyle(); - + } - + /** * Sets a default style (suitable for printing) to be included each time $this->oPdf->writeHTML() is called */ @@ -124,9 +133,9 @@ td.icon { width: 30px; } EOF - ); + ); } - + /** * Get access to the underlying TCPDF object * @return TCPDF @@ -136,7 +145,7 @@ EOF $this->flush(); return $this->oPdf; } - + /** * Writes the currently buffered HTML content into the PDF. This can be useful: * - to sync the flow in case you want to access the underlying TCPDF object for some specific/graphic output @@ -156,7 +165,7 @@ EOF $this->s_content = ''; } } - + /** * Whether or not the page is a PDF page * @return boolean @@ -165,7 +174,7 @@ EOF { return true; } - + /** * Generates the PDF document and returns the PDF content as a string * @return string @@ -185,7 +194,7 @@ EOF $this->flush(); echo $this->oPdf->Output($this->s_title.'.pdf', 'S'); } - + public function get_pdf() { $this->flush(); diff --git a/core/config.class.inc.php b/core/config.class.inc.php index e43a8d84d..f2cb4ed50 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -89,7 +89,8 @@ class Config * New way to store the settings ! * * @var array - * @since 2.5 db* variables + * @since 2.5.0 db* variables + * @since 2.7.0 export_pdf_font param */ protected $m_aSettings = array( 'app_env_label' => array( @@ -328,6 +329,14 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => true, ), + 'export_pdf_font' => array( // @since 2.7 PR #49 + 'type' => 'string', + 'description' => 'Font used when generating a PDF file', + 'default' => 'DejaVuSans', + 'value' => '', + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ), 'access_mode' => array( 'type' => 'integer', 'description' => 'Access mode: ACCESS_READONLY = 0, ACCESS_ADMIN_WRITE = 2, ACCESS_FULL = 3', diff --git a/core/displayablegraph.class.inc.php b/core/displayablegraph.class.inc.php index 0d9996bfe..ae54f59ab 100644 --- a/core/displayablegraph.class.inc.php +++ b/core/displayablegraph.class.inc.php @@ -161,8 +161,8 @@ class DisplayableNode extends GraphNode $idx++; } } - - $oPdf->SetFont('dejavusans', '', 24 * $fScale, '', true); + + $oPdf->SetFont(iTopPDF::GetPdfFont(), '', 24 * $fScale, '', true); $width = $oPdf->GetStringWidth($this->GetProperty('label')); $height = $oPdf->GetStringHeight(1000, $this->GetProperty('label')); $oPdf->setAlpha(0.6 * $Alpha); @@ -547,9 +547,9 @@ class DisplayableRedundancyNode extends DisplayableNode $oPdf->Circle($this->x*$fScale, $this->y*$fScale, 16*$fScale, 0, 360, 'DF'); $oPdf->SetTextColor(255, 255, 255); - $oPdf->SetFont('dejavusans', '', 28 * $fScale, '', true); + $oPdf->SetFont(iTopPDF::GetPdfFont(), '', 28 * $fScale, '', true); $sLabel = (string)$this->GetProperty('label'); - $width = $oPdf->GetStringWidth($sLabel, 'dejavusans', 'B', 24*$fScale); + $width = $oPdf->GetStringWidth($sLabel, iTopPDF::GetPdfFont(), 'B', 24 * $fScale); $height = $oPdf->GetStringHeight(1000, $sLabel); $xPos = (float)$this->x*$fScale - $width/2; $yPos = (float)$this->y*$fScale - $height/2; @@ -794,7 +794,7 @@ class DisplayableGroupNode extends DisplayableNode $oPdf->Image($sIconPath, ($this->x - 17)*$fScale, ($this->y - 17)*$fScale, 16*$fScale, 16*$fScale); $oPdf->Image($sIconPath, ($this->x + 1)*$fScale, ($this->y - 17)*$fScale, 16*$fScale, 16*$fScale); $oPdf->Image($sIconPath, ($this->x -8)*$fScale, ($this->y +1)*$fScale, 16*$fScale, 16*$fScale); - $oPdf->SetFont('dejavusans', '', 24 * $fScale, '', true); + $oPdf->SetFont(iTopPDF::GetPdfFont(), '', 24 * $fScale, '', true); $width = $oPdf->GetStringWidth($this->GetProperty('label')); $oPdf->SetTextColor(0, 0, 0); $oPdf->Text($this->x*$fScale - $width/2, ($this->y + 25)*$fScale, $this->GetProperty('label')); @@ -1295,7 +1295,7 @@ class DisplayableGraph extends SimpleGraph $aIcons = array(); $aContexts = array(); $aContextIcons = array(); - $oPdf->SetFont('dejavusans', '', $fFontSize, '', true); + $oPdf->SetFont(iTopPDF::GetPdfFont(), '', $fFontSize, '', true); foreach($oIterator as $sId => $oNode) { if ($sClass = $oNode->GetObjectClass()) diff --git a/core/pdfbulkexport.class.inc.php b/core/pdfbulkexport.class.inc.php index d27cd67e5..d5693795f 100644 --- a/core/pdfbulkexport.class.inc.php +++ b/core/pdfbulkexport.class.inc.php @@ -180,7 +180,7 @@ EOF require_once(APPROOT.'application/pdfpage.class.inc.php'); $oPage = new PDFPage(Dict::Format('Core:BulkExportOf_Class', MetaModel::GetName($this->oSearch->GetClass())), $this->aStatusInfo['page_size'], $this->aStatusInfo['page_orientation']); $oPDF = $oPage->get_tcpdf(); - $oPDF->SetFont('dejavusans', '', 8, '', true); + $oPDF->SetFont(iTopPDF::GetPdfFont(), '', 8, '', true); $oPage->add(file_get_contents($this->aStatusInfo['tmp_file'])); $oPage->add($sData); diff --git a/pages/ajax.render.php b/pages/ajax.render.php index fb38afce2..1c49b922c 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -2063,7 +2063,7 @@ EOF } $oPage->get_tcpdf()->AddPage(); - $oPage->get_tcpdf()->SetFont('dejavusans', '', 10, '', true); // Reset the font size to its default + $oPage->get_tcpdf()->SetFont(iTopPDF::GetPdfFont(), '', 10, '', true); // Reset the font size to its default $oPage->add(''); $iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop'); foreach($aResults as $sListClass => $aObjects)