You are here

public function FillPdfDownloadAction::execute in FillPDF 8.4

Same name and namespace in other branches
  1. 5.0.x src/Plugin/FillPdfActionPlugin/FillPdfDownloadAction.php \Drupal\fillpdf\Plugin\FillPdfActionPlugin\FillPdfDownloadAction::execute()

Executes this plugin.

Sends the PDF file to the user's browser.

Return value

\Symfony\Component\HttpFoundation\Response Sends the PDF file to the browser.

Overrides FillPdfActionPluginInterface::execute

File

src/Plugin/FillPdfActionPlugin/FillPdfDownloadAction.php, line 29

Class

FillPdfDownloadAction
Action plugin sending a generated PDF file to the users browser.

Namespace

Drupal\fillpdf\Plugin\FillPdfActionPlugin

Code

public function execute() {
  $response = new Response($this->configuration['data']);

  // This ensures that the browser serves the file as a download.
  $disposition = $response->headers
    ->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $this->configuration['filename']);
  $response->headers
    ->set('Content-Disposition', $disposition);
  $response->headers
    ->set('Content-Type', 'application/pdf');
  $response->headers
    ->set('Content-Length', strlen($this->configuration['data']));
  return $response;
}