<?php
if($data != ''){
    if(!isset($_GET['view']))
        header('Content-disposition: attachment; filename='.$fileName);
    
    header('Content-type: application/pdf');
    echo $data;
    exit();   
}
else{
    throw new CHttpException(400, 'Binary data is empty');
}
?>