TCPDF进度条

时间:2014-02-14 20:23:47

标签: php jquery joomla tcpdf

我使用php和TCPDF从几个MySQL查询生成自定义PDF文件。用户单击“生成PDF”按钮后,将打开一个新选项卡并启动PDF进程。平均而言,构建PDF需要大约10秒钟。文件准备就绪后,浏览器将关闭空白页面并显示另存为对话窗口。

我想在创建PDF时向用户显示某种类型的消息。在AJAX / JQUERY方面,我有点像菜鸟,但尝试实施多种解决方案却没有成功。

注意事项:

  1. 后端是Joomla!
  2. 使用$pdf->Output('example.pdf','D')生成pdf
  3. $pdf-Output之前使用ob_end_clean以避免“TCPDF:数据已输出”错误。
  4. 我尝试过在页面末尾添加<div>的方法,以及在页面加载时显示动画gif的jQuery / CSS。它不起作用,我不知何故感觉这是由ob_end_clean或Joomla引起的!框架。

2 个答案:

答案 0 :(得分:2)

1)对于进度条,您必须通过ajax

运行脚本

2)您在每个页面上都有pdf页数......创建可以更改进度条值

3)你必须为每个创建的pdf页面使用php输出控制功能 php有一个很好的功能列表

我没看到你的代码,但你必须做这样的事情

$i = 1;
while($i< PDF_PAGE_COUNT){
        ob_start();
        pdf_create_page($i);
        echo $i/PDF_PAGE_COUNT;
        ob_flush();
        flush();
$i++;
}

p.s:为了更好的答案,请在此处粘贴您的代码!

答案 1 :(得分:0)

&#13;
&#13;
$(document).ready(function(){
 $("#PDF").click(function(){
		/*-------------- validate filters	-------------------------------*/
		if(!(validarFecha(fecha_ymd(rj.Get('#TxtFechaIni').value())))){Warn2.show();return false; }
		if(!(validarFecha(fecha_ymd(rj.Get('#TxtFechaFin').value())))){Warn3.show();return false; }	
		if(Date.parse(fecha_ymd(rj.Get('#TxtFechaIni').value()))>=Date.parse(fecha_ymd(rj.Get('#TxtFechaFin').value()))){Warn.show();return false; }
	/* is alll right */	
	else {		
				/* show a message while generating report*/
				WinSnd.Message({type:'info', title:'generating report', value:'Please, wait ...', buttons:' '}).show();	
				/* url with params to send */
				var url="report.php?&slash="+'<?php echo(isset($_POST['slash'])?@$_POST['slash']:@$_GET['slash']);?>'+"&module="+'<?php echo (isset($_POST['module'])?@$_POST['module']:@$_GET['module']);?>'
				+"&TxtCheck=excel"
				+"&TxtFechaIni="+rj.Get('#TxtFechaIni').value()
				+"&TxtFechaFin="+rj.Get('#TxtFechaFin').value()
				+"&LkpTdoc="+rj.Get('#LkpTdoc').value();

				var filename = <?php echo '"'.$gSave.'"';?>; /* name for report, i set*/
				var xhr = new XMLHttpRequest();
				xhr.responseType = 'blob';
				
				xhr.onload = function(){
						WinSnd.hide(); /* hide message */
						var a = document.createElement('a');
						a.href = window.URL.createObjectURL(xhr.response); // xhr.response es un blob file
						a.target = '_blank';
						a.download = filename; // file name 
						a.style.display = 'none';
						document.body.appendChild(a);
						a.click(); // action
						delete a; //
				};
				xhr.open('GET', url);
				xhr.send();	
						
		}// fin validaciones
			
    });//fin function	
});// fin 		
&#13;
&#13;
&#13;