Dream House

Courage to do something…

DOMPDF Attachment issue in IE (Internet Explorer)

Posted by Mohammad Sajjad Hossain on May 30th, 2008

I have used DOMPDF in my project. But I was facing problem with Attachment. In FireFox it was working fine. But in Internet Explorer (I used IE 6) it ended with an error. In IE it was showing the download dialogue box offering the script page I used to generate the PDF file. When I tried to download the file it showed an error.

I searched the web and found no suitable solution. I followed the instruction given in http://www.corenettech.com/blog/ but it didn’t work :(. But I got an idea from this post. I started digging the code and have done following changes to PDFLib_Adapter class (available in DOMPDF_DiRECTORY/include/pdflib_adapter.cls.php).

I have removed the following line (line 829):

829
header("Cache-Control: private");

and added

829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
{
     header('Expires: 0');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header("Content-Transfer-Encoding: binary");
     header('Pragma: public');
     header("Content-Length: ".strlen($data));
}
else
{
     header("Cache-Control: private");
     header("Content-Transfer-Encoding: binary");
     header('Expires: 0');
     header('Pragma: no-cache');
     header("Content-Length: ".strlen($data));
}

After

header("Content-type: application/pdf");
header("Content-Disposition: $attach; filename=\"$filename\"");

That’s it! My code started working :).

Hope this will save your time of surfing the net ;).

Share/Save/Bookmark

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">