views:

159

answers:

1

I have a method that returns a PDF file using DOMPDF. It sends all the right headers. It is generated on the fly (not stored on the server anywhere).

I now have to attach this PDF to outgoing emails. I did this in Kohana 3

        $routeUrl = Route::get('secure_view_pdf')->uri(array('id' => $id));

        $response = Request::factory($routeUrl)->execute();


        $tempFile = DOCROOT . 'tmp/pdf-' . $id . '.pdf';

        file_put_contents($tempFile, $response); 


        $swift = email::connect();
        $message = Swift_Message::newInstance();


        $message->setSubject('My Subject')
              ->setFrom(array('[email protected]' => 'Example'))
              ->setTo(array($clientEmail => html::chars($clientName)))
              ->setBody($body) 
              ->addPart($body, 'text/html') 
              ->attach(Swift_Attachment::fromPath($tempFile));

        $swift->send($message);

The route it is requesting simply sends the headers to download and streams the PDF so the end user can download it. It also uses the Swift Mailer library.

Except when I run this request in the browser, it prompts me to download the file. I want to get the output in $response and ignore the download headers Content-Disposition: attachment; filename="file #1.pdf".

Is it possible to receive this request as-is and then save it to a file like I've described above.

Or should I change the auto generation of PDFs to file, and then simply point to that file with Swift?

Many thanks

+1  A: 
  $response = Request::factory($routeUrl)->execute()->response;
Kemo
Hmm I tried that. And I think it should work normally, except the DOMPDF extension is sending headers itself. I'll accept anyway as this is the usual way to do this thing.
alex