Skip to content

Instantly share code, notes, and snippets.

@chukShirley
Created September 20, 2016 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chukShirley/bfd954b24e38c9301f37771e459fb818 to your computer and use it in GitHub Desktop.
Save chukShirley/bfd954b24e38c9301f37771e459fb818 to your computer and use it in GitHub Desktop.
<?php
class GeneratePdfController extends AbstractActionController
{
public function indexAction()
{
$filename = '/path/to/myFile.pdf';
$response = new Stream();
$headers = new Headers();
$headers
->addHeaderLine('Pragma', 'public')
->addHeaderLine('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
->addHeaderLine('Content-Type', 'application/pdf')
->addHeaderLine('Content-disposition', 'inline; filename="' . basename($filename) . '";')
->addHeaderLine('Content-Transfer-Encoding', 'binary')
->addHeaderLine('Content-Length', filesize($filename))
->addHeaderLine('Accept-Ranges', 'bytes');
$response->setHeaders($headers);
$response->setContentLength(filesize($filename));
$response->setStream(fopen($filename, 'r'));
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment