开发者

Export more than one pdf generated one the fly as zip using the symfony framework

Iam currently working on an symfony app that needs to be able to output some documents as pdf, which is no problem at all using TCPDF.

What I try to do now is to generate a zip file containing one ore more of these pdf´s generated on the fly. What I basically do is (using php´s) zip library:

1.) Create a new zip archive. 2.) Add all the PDF´s 3.) Output the generated zip.

The stran开发者_如何转开发ge thing is, that this works when using some demo pdf´s on sone different server. However when I try to export my own documents (spezified by url, such as url_dor('documents/pdf?id/1') ) , the page just keeps loading for forever until I reach max time...

To be honest I have no clue at all why this does not work. Any help is greatly appreciated!


Well the time it takes to zip the pdfs (or any file) is going to vary with the size and number of those PDF's. So the first question you should be asking is how long is it going to take to process these?


Try using very small PDF files when testing and if still problematic, set you PHP timeout variable higher to run your tests.


Here's my code inside the action class:

$this->setLayout(false);
$tmpFileName = tempnam("/tmp", "some_prefix_");
$zip = new ZipArchive();
$zip->open($tmpFileName, ZipArchive::CREATE);
foreach ($files as $file) {
    $real_file = $file->getAbsoluteFilePath();
    $zip->addFile($real_file, 'sub_folder_name/' . $file->getTitle() . '.pdf');
}
$zip->close();
$this->getResponse()->clearHttpHeaders();
$this->getResponse()->setContent(file_get_contents($tmpFileName));
unlink($tmpFileName);
$this->getResponse()->setHttpHeader('Content-Type', 'application/zip');
$this->getResponse()->setHttpHeader('Content-Disposition', 'attachment; filename=archive_name.zip');
return sfView::NONE;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜