当用户点击按钮时,我的网络应用程序通过tcpdf打开了pdf:
function showOverviewThroughPdf(){
$oResp = $this->getResponse("tcpdf") ;
//NEW PDF DOCUMENT
$oResp->outputFileName = "liste_concepteur_matiere.pdf";
$oResp->doDownload = false;
$oResp->initPdf('L', 'mm', 'A4', null, null);
//settting
$oResp->tcpdf->SetFont ('pdfahelvetica', '', 12) ;
// set margins
$oResp->tcpdf->SetMargins(20, 20, 20) ;
$oResp->tcpdf->SetHeaderMargin(15) ;
$oResp->tcpdf->SetFooterMargin(15) ;
$oResp->tcpdf->SetAutoPageBreak(TRUE, 20) ;
// set image scale factor
$oResp->tcpdf->setImageScale(1.25);
$oResp->tcpdf->AddPage();
$iIdMatiere = $_SESSION["id_matiere"] ;
jClasses::inc ("sujet~questionSrv") ;
jClasses::inc ("commun~toolsSrv") ;
$oCurrentUser = jAuth::getUserSession() ;
$oCurrentUser = toolsSrv::getByCondition ("utilisateurs~users", "login", $oCurrentUser->login) ;
$oCurrentUser = $oCurrentUser [0] ;
$Questions = questionSrv::getAllQuestionsNotValidateByCondition ($iIdMatiere, null , $oCurrentUser->id, "id_question" , null,null, null) ;
$zHtml = "";
$i = 1 ;
foreach ($Questions["toQuestions"] as $tab){
if( $tab->id_type_question == 2){
$zHtml .= "<dt> ". $i ." - " . questionSrv::text_to_texthtml($tab->lib_question) . " </dt>" ;
$zHtml .= "<dd> a) ". questionSrv::text_to_texthtml($tab->qcm_r1)."</dd>";
$zHtml .= "<dd> b) ". questionSrv::text_to_texthtml($tab->qcm_r2)."</dd>";
$zHtml .= "<dd> c) ". questionSrv::text_to_texthtml($tab->qcm_r3)."</dd>";
if(trim($tab->qcm_r4) !="")
$zHtml .= "<dd> d) ".questionSrv::text_to_texthtml($tab->qcm_r4)."</dd>";
if(trim($tab->qcm_r5) !="")
$zHtml .= "<dd> e) ".questionSrv::text_to_texthtml($tab->qcm_r5)."</dd>";
if(trim($tab->qcm_r6) !="")
$zHtml .= "<dd> f) ".questionSrv::text_to_texthtml($tab->qcm_r6)."</dd>" ;
} else {
$zHtml .= "<dt>". $i ." - " . questionSrv::text_to_texthtml($tab->lib_question) . "</dt>";
if($tab->epreuve_phase_sess != 1){
$zHtml .= "<dd> a) VRAI</dd>";
$zHtml .= "<dd> b) FAUX</dd>";
}
}
$i++;
}
$oResp->tcpdf->writeHTML($zHtml, true, 0, true, 0); // this opens the pdf thus creating a temporary file
return $oResp ;
}
在运行时,客户端计算机中的浏览器会创建一个临时文件。那么如何在特定事件中删除此文件,例如当用户与我的应用程序断开连接时?
答案 0 :(得分:0)
你需要返回pdf文件;只需在末尾添加这两行而不是返回$ oResp;
$oResp->tcpdf->Output($file_name, 'F');
return $file_name ;