Skip to content

Commit

Permalink
Merge pull request #162 from OpenConext/bugfix/fix-mpdf-relative-urls…
Browse files Browse the repository at this point in the history
…-and-logging

Fix mpdf relative url's and logging
  • Loading branch information
pablothedude committed Jan 14, 2019
2 parents f4ab9c8 + 8fe1ec8 commit 0f4f190
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app/Resources/views/base.html.twig
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
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 @@ -165,8 +166,6 @@ public function registrationEmailSentAction($secondFactorId)
/**
* @param $secondFactorId
* @return Response
*
* @SuppressWarnings(PHPMD.ExitExpression) MPDF requires bypassing Symfony, so we exit() when MPDF is done.
*/
public function registrationPdfAction($secondFactorId)
{
Expand All @@ -178,9 +177,26 @@ 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);
$disposition = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
'registration-code.pdf'
);

$response->headers->set('Content-Disposition', $disposition);
$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 0f4f190

Please sign in to comment.