Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4022452
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:28:37+00:00 2026-05-20T10:28:37+00:00

I built a simple action in symfony which generates a PDF-file via wkhtmltopdf and

  • 0

I built a simple action in symfony which generates a PDF-file via wkhtmltopdf and outputs it to the browser.

Here’s the code:

  $response = $this->getResponse();
  $response->setContentType('application/pdf');
  $response->setHttpHeader('Content-Disposition', "attachment; filename=filename.pdf");
  $response->setHttpHeader('Content-Length', filesize($file));
  $response->sendHttpHeaders();
  $response->setContent(file_get_contents($file));
  return sfView::NONE;

That works fine in my local development environment – my browser gets the headers as expected, showing the download-dialogue.

Now I updated my testing-environment, running Apache 2.2.9-10+lenny9 with PHP 5.3.5-0.dotdeb.0.
If i call that URL now for the testing-environment, my browser don’t get any custom set headers:

Date    Mon, 07 Mar 2011 10:34:37 GMT
Server  Apache
Keep-Alive  timeout=15, max=100
Connection  Keep-Alive
Transfer-Encoding   chunked

If I set them manually via header() in my action, Firebug shows the headers as expected.
Does anybody know what could be wrong? Is it a symfony bug, or a php or apache2 configuration issue? I don’t get it. :-/

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:28:37+00:00Added an answer on May 20, 2026 at 10:28 am

    Your problem is here:

    return sfView::NONE;
    

    Change this to:

    return sfView::HEADERS_ONLY;
    

    edit update due to extra comments.

    Since you are trying to download a pdf, you’re approach the problem incorrectly. Do not use sendContent(). See below (this is a snippet from a production site I’ve written and has proven to work across all major browsers):

    $file = '/path/to/file.pdf';
    $this->getResponse()->clearHttpHeaders();
    $this->getResponse()->setStatusCode(200);
    $this->getResponse()->setContentType('application/pdf');
    $this->getResponse()->setHttpHeader('Pragma', 'public'); //optional cache header
    $this->getResponse()->setHttpHeader('Expires', 0); //optional cache header
    $this->getResponse()->setHttpHeader('Content-Disposition', "attachment; filename=myfile.pdf");
    $this->getResponse()->setHttpHeader('Content-Transfer-Encoding', 'binary');
    $this->getResponse()->setHttpHeader('Content-Length', filesize($file));
    
    return $this->renderText(file_get_contents($file));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a simple file browser on our intranet, built using ASP/vbscript. The files
I have controller action in which I update a simple value in domain object:
I have built a simple C#.Net app on a M/C with only .Net FX
I've built a simple application that applies grid-lines to an image or just simple
I have built a simple Eclipse plugin where a user may use a TableViewer
I'm an ASP.NET web part novice. I've built a few simple ones using only
Stackoverflow is built on MVC and does a bunch of simple but nice things
So in my simple learning website, I use the built in ASP.NET authentication system.
I have a site built with Symfony 1.2. I'm trying to integrate Wordpress 2.8.4
I have a site built with simple templates; header.tpl, navigation.tpl, body_home.tpl, body_about.tpl, body_anotherpage.tpl, etc.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.