Generate multiple pdfs using FPDF class
I have adde开发者_如何学运维d a link on a page clicking on which generates a pdf and asks for download for which i have used fpdf class.
My new requirement is that clicking on the link should generate n number of pdf with different content and should ask for downloading these pdfs.
I am unable to find out the method to accomplish the same.
Please help me on this.
Thanks
At http://www.phpconcept.net/pclzip/ you'll find a nice php zip library. Imagine having an array of filenames like
$filenames = array(
"file_01.txt",
"file_02.doc",
"file_03.pdf"
);
the code would look like this (untested)
require_once('pclzip.lib.php');
$archive = new PclZip('archive.zip');
foreach($filenames as $filename) {
$result = $archive->add($filename);
if($result==0) {
die ("Error: " . $archive->errorInfo(true));
}
}
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=archive.zip");
readfile("archive.zip");
Hope this helps ;-)
You can't send multiple files to user but you can generate them, pack with e.g. zip on server and send as one file.
The correct method to send your generated file to the browser is the $pdf->Output()
- this will only allow you to send one generated pdf file. The only option to send more files is to zip them [1] and then send the package file.
[1] http://www.devco.net/archives/2005/05/24/creating_zip_files_with_php.php
I used the flowing code in my php page:
if(isset($_GET['get_pdf'])){
$query = "SELECT * FROM tbl_fixation WHERE postedby = '$name_user' ORDER BY fixation_id ASC ";
$data_query = $hrmdb->select($query);
if($data_query ){
$i=0;
while ($rows= $data_query ->fetch_assoc()) {
$i++;
$fixation_id = $rows['fixation_id'];
echo "<script> window.open('allpdf/single_letter_fixation.php?fixation_id=".$fixation_id."','_blank');</script>";
}}
}
Output option for pdf file in single_letter_fixation.php is:
$pdf->Output('D', $personal_file_number.pdf');
It works well.
精彩评论