2011-03-28 46 views
2

我正在检查用raw php编写的应用程序,没有任何框架。在一个模块中,有报告使用FPDF生成并且工作正常,除了pdf被缓存。在生成过程的初始调用是如何使FPDF生成的pdf不可缓存?

<a href="tr_inci_print.php" target="_new">Print</a> 

tr_inci_print.php使用2个参数,年份和月份中存储的会话。我已将代码更改为

<a href="tr_inci_print.php?anio=<?php echo $anio; ?>&mes=<?php echo $mes; ?>" target="_new">Imprimir</a> 

由于每个月都会更改URI,因此部分解决了问题。但是,如果数据在外部发生变化并且浏览器仍在原始页面中,则重新链接链接确实会生成未更新的pdf。

有什么办法可以改变$ FPDF-> output()来使pdf不可缓存?

------部分解决-------------------

以下oezi答案,改:

$oPdf->output() 

$buffer=$oPdf->Output('','S'); 

header('Content-Type: application/pdf'); 
header('Content-Length: '.strlen($buffer)); 
header('Content-Disposition: inline; filename="doc.pdf"'); 
header("Cache-Control: no-cache, must-revalidate, max-age=1"); // HTTP/1.1 
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // any date in the past 
header('Pragma: public'); 
ini_set('zlib.output_compression','0'); 
echo $buffer; 

上解决了在Chrome和IE浏览器的问题,但不能在Firefox 4

回答

2

你只需要设置一个头实现这一目标,只是添加的F olowing行到你的tr_inci_print.php

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // any date in the past 

编辑:请务必之前添加此行调用output()

+0

谢谢oezi,但没有工作。我在output()之前插入代码,但它没有效果,仍然获得缓存版本。 – 2011-03-28 10:49:47

+0

不好意思。它在Chrome中运行,在FF4中失败。 – 2011-03-28 11:00:45

+0

from output()函数:\t header('Cache-Control:private,max-age = 0,must-revalidate');所以它重写了指令。将尝试做我自己的输出。 – 2011-03-28 11:07:51

1

尝试:

<a href="tr_inci_print.php?t=<?php echo time(); ?>" target="_new">Print</a> 

编辑:添加JavaScript以确保即使没有重新加载主页,pdf也是新鲜的:

<a href="tr_inci_print.php?t=<?php echo time(); ?>" 
    onclick="document.location.href='tr_inci_print.php?t='+new Date().getTime(); return false;" > 
    Print 
</a> 
+0

感谢塔科内。问题是带链接的页面没有被重新加载,所以直到那时href才会改变。可能会有几个js可以产生效果。 – 2011-03-28 13:21:13

+1

tacone 2011-03-28 13:54:16

+0

没关系,是这个想法,考虑到PDF应该在另一个窗口中打开,所以只需轻轻一点,它就会成为我正在寻找的东西。谢谢! – 2011-03-29 09:57:08

相关问题