You are here

public function TcpPdfExampleController::downloadPdf in TCPDF 8

1 string reference to 'TcpPdfExampleController::downloadPdf'
tcpdf_example.routing.yml in tcpdf_example/tcpdf_example.routing.yml
tcpdf_example/tcpdf_example.routing.yml

File

tcpdf_example/src/Controller/TcpPdfExampleController.php, line 16
Contains \Drupal\tcpdf_example\Controller\TcpPdfExampleController

Class

TcpPdfExampleController

Namespace

Drupal\tcpdf_example\Controller

Code

public function downloadPdf($example_name) {
  switch ($example_name) {
    case 'simple':
      $pdf = $this
        ->generateSimplePdf();
      break;
    default:
      return $this
        ->t('No such example.');
  }

  // Tell the browser that this is not an HTML file to show, but a pdf file to
  // download.
  header('Content-Type: application/pdf');
  header('Content-Length: ' . strlen($pdf));
  header('Content-Disposition: attachment; filename="mydocument.pdf"');
  print $pdf;
  return [];
}