Skip to content

Commit

Permalink
Fix mpdf relative url's and logging
Browse files Browse the repository at this point in the history
Relative url's weren't supported, because mpdf was trying to get it by
hostname in the request. If however a proxy should update the hostname
it wouldn't work. Therefore the `base` html tag was added which was
supported by mpdf for resolving absolute urls. Also the
logging was added and decent symfony shutdown.
  • Loading branch information
pablothedude committed Jan 9, 2019
1 parent f2cce28 commit 67a3c27
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="screen, print" />
{% endstylesheets %}
{% endblock head_style %}
{% block head_bottom %}
<base href="{{ app.request.schemeAndHttpHost ~ app.request.baseUrl }}">
{% endblock head_bottom %}

{% block navbar %}
{#{{ mopa_bootstrap_navbar('frontendNavbar') }}#}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Surfnet\StepupSelfService\SelfServiceBundle\Value\AvailableTokenCollection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class RegistrationController extends Controller
Expand Down Expand Up @@ -178,9 +179,25 @@ public function registrationPdfAction($secondFactorId)
'tempDir' => sys_get_temp_dir(),
)
);
$mpdf->setLogger($this->get('logger'));

$mpdf->WriteHTML($content);
$mpdf->Output('registration-code.pdf', MpdfDestination::DOWNLOAD);
$output = $mpdf->Output('registration-code.pdf', MpdfDestination::STRING_RETURN);

$response = new Response($output);
$response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
'registration-code.pdf'
);

$response->headers->set('Content-Description', 'File Transfer');
$response->headers->set('Content-Transfer-Encoding', 'binary');
$response->headers->set('Cache-Control', 'public, must-revalidate, max-age=0');
$response->headers->set('Pragma', 'public');
$response->headers->set('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT');
$response->headers->set('Last-Modified', '' . gmdate('D, d M Y H:i:s') . ' GMT');
$response->headers->set('Content-Type', 'application/pdf');

exit;
return $response;
}
}

0 comments on commit 67a3c27

Please sign in to comment.