Question

I am developing a Joomla component and one of the views needs to render itself as PDF. In the view, I have tried setting the content-type with the following line, but when I see the response, it is text/html anyways.

header('Content-type: application/pdf');

If I do this in a regular php page, everything works as expected. It seems that I need to tell Joomla to use application/pdf instead of text/html. How can I do it?

Note: Setting other headers, such as Content-Disposition, works as expected.

Was it helpful?

Solution

Since version 1.5 Joomla has the JDocument object. Use JDocument::setMimeEncoding() to set the content type.

$doc =& JFactory::getDocument();
$doc->setMimeEncoding('application/pdf');

In your special case, a look at JDocumentPDF may be worthwile.

OTHER TIPS

For those of you thinking that the above is a very old answer, I confirm that the JDocument::setMimeEncoding() still works, even on the 1.6 version (haven't tried it on 1.7 yet).

I had the same problem in joomla 2.5. After 8 hours of clicking around in the joomla admin panel I found a solution.

  1. Log into your joomla admin panel and click on media manager
  2. Click the options button in the top right hand corner. This opens a configuration tab with various options
  3. In the box for legal file extensions, application/pdf or whatever you need. Values are separated by a comma. Note, apparently you have to list things in alphabetical order according to a forum I just found
  4. Click save button

You should now be able to load pdfs into media manager. Hope this works for you. I just set mine up to upload .mov extensions.

The problem is it only worked once. Now the browse link doesn't work whenever I navigate to a movie .mov file on my hard drive. But it does if I select any other file type ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top