add footer to resume

This commit is contained in:
iIronside
2022-11-21 13:54:58 +03:00
parent 816b39fc74
commit 18dd5a5d36
8 changed files with 136 additions and 34 deletions

View File

@ -276,59 +276,84 @@ class UserCardController extends Controller
$userCard->resume_text = $resumeText;
}
public function actionDownloadResumePdf($id)
public function actionDownloadResume(int $id, string $type)
{
$userCard = UserCard::findOne($id);
$model = $this->findModel($id);
$model->scenario = $model::SCENARIO_DOWNLOAD_RESUME;
if ($model->validate()) {
if ($type == 'pdf') {
$this->downloadResumePdf($model);
} elseif ($type == 'docx') {
$this->downloadResumeDocx($model);
}
}
return $this->render('resume', [
'model' => $model
]);
}
private function downloadResumePdf(UserCard $userCard)
{
// $userCard = UserCard::findOne($id);
$resumeTemplate = ResumeTemplate::findOne($userCard->resume_template_id);
if (empty($resumeTemplate->header_text)) {
$headerText = 'Generated by ITGuild.info At: ' . date("d/m/Y");
} else {
$headerText = $resumeTemplate->header_text;
}
$headerText = $resumeTemplate->header_text ? : 'Generated by ITGuild.info At: ' . date("d/m/Y");
$headerImagePath = $resumeTemplate->header_image ? Yii::getAlias('@frontend') . '/web' . $resumeTemplate->header_image : null;
$footerText = $resumeTemplate->footer_text ?? null;
$footerImg = $resumeTemplate->footer_image ? Yii::getAlias('@frontend') . '/web' . $resumeTemplate->footer_image : null;
$pdf = new Pdf();
$mpdf = $pdf->api;
if (!pathinfo($resumeTemplate->header_image, PATHINFO_EXTENSION)) {
$mpdf->SetHeader($headerText);
} else {
$imagePath = Yii::getAlias('@frontend') . '/web' . $resumeTemplate->header_image;
$mpdf->setAutoTopMargin='stretch';
$mpdf->SetHTMLHeader(
"<div style='border-bottom: 1px solid #999;'>
<p><img src=$imagePath style='width: 100px; height: 40px; margin: 0; vertical-align: middle;'/>$headerText</p>
</div>"
);
}
$mpdf->SetFooter('{PAGENO}');
$mpdf->SetHTMLHeader("
<table width='100%' style='border-bottom: 1px solid #999; vertical-align: bottom; font-family: serif; font-size: 8pt; color:
#000000; font-weight: bold; font-style: italic;'><tr>
<td width='33%'><span style='font-weight: bold; font-style: italic;'><img src=$headerImagePath style='width: 100px; height: 40px; margin: 0; vertical-align: middle;'></span></td>
<td width='33%' align='center' style='font-weight: bold; font-style: italic;'>$headerText</td>
<td width='33%' style='text-align: right; '>{PAGENO}</td>
</tr></table>
");
$mpdf->SetHTMLFooter("
<table width='100%' style='border-top: 1px solid #999; vertical-align: bottom; font-family: serif; font-size: 8pt; color:
#000000; font-weight: bold; font-style: italic;'><tr>
<td width='33%'><span style='font-weight: bold; font-style: italic;'><img src=$footerImg style='width: 100px; height: 40px; margin: 0; vertical-align: middle;'></span></td>
<td width='33%' align='center' style='font-weight: bold; font-style: italic;'>$footerText</td>
<td width='33%' style='text-align: right; '>{PAGENO}</td>
</tr></table>
");
$mpdf->WriteHTML("<div>$userCard->resume_text</div>");
$mpdf->Output("Resume - {$userCard->fio}", 'D'); // call the mpdf api output as needed
exit;
}
public function actionDownloadResumeDocx($id)
private function downloadResumeDocx(UserCard $model)
{
$model = UserCard::findOne($id);
$resumeTemplate = ResumeTemplate::findOne($model->resume_template_id);
$imagePath = Yii::getAlias('@frontend') . '/web' . $resumeTemplate->header_image;
if (empty($resumeTemplate->header_text)) {
$headerText = 'Generated by ITGuild.info At: ' . date("d/m/Y");
} else {
$headerText = $resumeTemplate->header_text;
}
$headerText = $resumeTemplate->header_text ? : 'Generated by ITGuild.info At: ' . date("d/m/Y");
$footerText = $resumeTemplate->footer_text ?? null;
$pw = new \PhpOffice\PhpWord\PhpWord();
// (B) ADD HTML CONTENT
$section = $pw->addSection();
$header = $section->addHeader();
$footer = $section->addFooter();
if (pathinfo($resumeTemplate->header_image, PATHINFO_EXTENSION)) {
$header->addImage($imagePath, ['width' => 70, 'height' => 30, 'align' => 'left']);
$header->addImage(Yii::getAlias('@frontend') . '/web' . $resumeTemplate->header_image, ['width' => 70, 'height' => 30, 'align' => 'left']);
}
$header->addText($headerText, array('bold' => false), array('space' => array('before' => 0, 'after' => 280)));
if (pathinfo($resumeTemplate->footer_image, PATHINFO_EXTENSION)) {
$footer->addImage(Yii::getAlias('@frontend') . '/web' . $resumeTemplate->footer_image, ['width' => 70, 'height' => 30, 'align' => 'left']);
}
$footer->addText($footerText, array('bold' => false), array('space' => array('before' => 0, 'after' => 280)));
$footer->addPreserveText('{PAGE}', null, ['align' => 'right']);
$resumeText = str_replace(array('<br/>', '<br>', '</br>'), ' ', $model->resume_text);
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $resumeText, false, false);