Обучаю битриксу программистов, интеграторов

Генерация pdf c помощью tFPDF

Задача: генерировать pdf-файл с данными о лицензии

Библиотека tFPDF
свой компонент

класс собирает $arResult по своей логике
template.php генерирует pdf, который сразу можно скачать

global $APPLICATION;

if(!empty($arResult["license"]["supportPeriod"])){
    $firstColumnX  = 58;
    $secondColumnW = 130;
}
else{
    $firstColumnX  = 43;
    $secondColumnW = 140;
}

$secondColumnX = $firstColumnX + 14;

$APPLICATION->RestartBuffer(); //чтобы header.php не попал
$license = new \tFPDF\PDF();


$license->AddFont('OpenSansBold','','OpenSans-Bold.ttf',true);
$license->AddFont('OpenSans','','OpenSans.ttf',true);


//Добавляем страничку в документ
$license->AddPage();

//Выводим заголовок
$license->Image($_SERVER['DOCUMENT_ROOT'].'/local/templates/europe-personal/assets/img/cert-header.png',0,0, 210);
$license->Ln(105);

//// Выводим данные пользователя
$license->SetFont('OpenSans','',15);
$license->Cell(0,0,GetMessage('TITLE_CERTIFICATE'),0,0,'C');
$license->Ln(9);

$license->SetFont('OpenSansBold','',19);
$license->Cell(0,0, $arResult["FIO"],0,0,'C');
$license->Ln(9);


if (!empty($arResult['COMPANY'])) {
    $cmpName = explode(' ', $arResult['COMPANY']);
    $company = $cmpName[0];
    $arCompanyName[0] = $company;
    $maxLenght = 40;
    $k = 0;
    for($i=0;$i<count($cmpName);$i++) {
        if (strlen($company.' '.$cmpName[$i+1]) < $maxLenght){
            $company .= ' '.$cmpName[$i+1];
            $arCompanyName[$k] = $company;
        }
        else{
            $company = $cmpName[$i+1];
            $k++;
        }
    }
    foreach ($arCompanyName as $string){
        $license->Cell(0,0, htmlspecialchars_decode($string),0,0,'C');
        $license->Ln(9);
    }
}

$license->SetFont('OpenSans','',15);
$license->Cell(0,0,GetMessage('IS_LICENSED'),0,0,'C');
$license->Ln(9);

$license->SetFont('OpenSansBold','',19);
$license->Cell(0,0, $arResult["license"]["productTitle"]." ver. ".$arResult["license"]["productVersion"].$arResult["license"]["productType"],0,0,'C');
$license->Ln(20);

if(!empty($arResult["license"]["modules"])) {
    $license->SetFont('OpenSans', '', 10);
    $license->Cell($firstColumnX, 5, GetMessage('LIST_OF_MODULES'), 0, 0, 'R');
    $license->SetFont('OpenSansBold', '', 11);
    $license->SetX($secondColumnX);
    $license->MultiCell($secondColumnW, 5, $arResult["license"]["modules"], 0);
    $license->Ln(5);
}

$license->SetFont('OpenSans','',10);
$license->Cell($firstColumnX,5,GetMessage('SERIAL_NUM'),0,0,'R');
$license->SetFont('OpenSansBold','',11);
$license->SetX($secondColumnX);
$license->MultiCell( $secondColumnW, 5, $arResult["license"]["shortSN"], 0);
$license->Ln(5);

$license->SetFont('OpenSans','',10);
$license->Cell($firstColumnX,5,GetMessage('PERMITTED'),0,0,'R');
$license->SetFont('OpenSansBold','',11);
$license->SetX($secondColumnX);
$license->MultiCell( $secondColumnW, 5, $arResult["license"]["quantity"], 0);
$license->Ln(5);

$license->SetFont('OpenSans','',10);
$license->Cell($firstColumnX,5,GetMessage('VALIDITY'),0,0,'R');
$license->SetFont('OpenSansBold','',11);
$license->SetX($secondColumnX);
$license->MultiCell( $secondColumnW, 5, $arResult["license"]["activePeriod"], 0);
$license->Ln(5);

if(!empty($arResult["license"]["supportPeriod"])){
    $license->SetFont('OpenSans','',10);
    $license->Cell($firstColumnX,5,GetMessage('SUPPORT_PERIOD'),0,0,'R');
    $license->SetFont('OpenSansBold','',11);
    $license->SetX($secondColumnX);
    $license->MultiCell( $secondColumnW, 5, $arResult["license"]["supportPeriod"], 0);
    $license->Ln(2);   
}

$license->SetY(-50);
$license->SetFont('OpenSans','',8);
$license->Cell(0,2,GetMessage('DATE_AND_TIME').$arResult["DATETIME"],0,0,'C');
$license->Ln(4);
$license->Cell(0,2,GetMessage('N_INFO'),0,0,'C');
$license->Ln(4);

$license->SetTextColor(44,119,210);
$license->Cell(0,2,GetMessage('LINK'),0,0,'C','',GetMessage('HREF'));
$license->SetTextColor(0);
$license->Ln(6);
$license->Cell(0,2,GetMessage('USE_OF_COMPUTER'),0,0,'C');
$license->Ln(6);
$license->Cell(0,2,GetMessage('IN_THE_EVENT'),0,0,'C');
$license->Ln(4);
$license->Cell(0,2,GetMessage('TO_VERIFY'),0,0,'C');

$pdfContent = $license->output();
header('Content-Type: application/x-download');
header('Content-Disposition: attachment; filename=cert.pdf');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
echo $pdfContent;
die();
Если блог был полезным, можете угостить меня "чашечкой кофе" :)

Сбер по номеру телефона +7 (953) 585-13-09 Вероника.
Спасибо!