2014-10-02 76 views
0

我有一個Controller('RenderView')方法,使用PDF :: API2即時創建PDF。Perl催化劑:創建並強制下載PDF

我不想保存PDF,而是想強制下載對話框。事情是這樣的僞代碼:

... create pdf on-the-fly ... 
$pdf->saveas($fullPathToFilename); # is there a way to avoid this? 
binmode STDOUT; 
$c->res->content_type('application/pdf'); 
$c->res->header('Content-Disposition', qq[attachment;filename='$shortFilename']); 
$c->res->header('someOtherHeaders'); 
... here, stream binary content to client ?? ... 
return $self->status_ok($c, entity => 'PDF'); 

我想我可以反覆測試所創建的文件的存在,並服務於它時,它的保存和發現。這對我來說似乎非常糟糕。

任何人都有更好的解決方案?

謝謝, 諾亞

回答

1

documentation

$string = $pdf->stringify(); 

返回文檔作爲字符串並從內存中刪除該對象的結構。

+0

工程就像一個魅力!謝謝! – 2014-10-02 20:20:43