We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43288
    • 35 Posts
    Hi, I have the objective in the title working with Firefox and Chrome, but not with Safari. Safari insists on giving the file a .html ending, even though the body of the downloaded file is a proper PDF file.

    I have a resource with no template whose body is [[!statement]], resource type Document, Content Type HTML, Content Disposition Inline. My snippet is overriding the headers like this:

    <?php
    
    $pdf = "this is actually a binary PDF in PHP variable."
    
    header('Content-Description: Statement');
    header('Content-Type: application/pdf');
    header('Content-Disposition: attachment; filename=Statement.pdf');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    
    return $pdf;
    


    Is there a cleaner approach to making this work properly in the latest IE, Chrome, Firefox and Safari? I can't use static resources, as the content is determined dynamically from an external source.

    Thanks for any suggestions or experience!

    Regards,
    watou

    This question has been answered by Jako. See the first response.

    • discuss.answer
      • 13428 ☆ A M B ☆
      • 1,031 Posts
      Change
      return $pdf;

      into
      echo $pdf;
      exit;
      


      And you could read an existing PDF by
      $pdf = file_get_contents(MODX_BASE_PATH.'whatever.pdf');
        • 43288
        • 35 Posts
        Quote from: Jako at Jan 27, 2015, 03:42 PM
        Change
        return $pdf;

        into
        echo $pdf;
        exit;
        


        Thank you! That is it exactly. I see now why this works, now on all three named browsers.