Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the Content-type in Joomla?

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.

like image 475
Antoine Aubry Avatar asked Sep 25 '08 13:09

Antoine Aubry


1 Answers

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.

like image 85
Tomalak Avatar answered Sep 22 '22 01:09

Tomalak