使用 FPDF 类生成多个 pdf

发布于 2024-09-02 05:07:05 字数 156 浏览 0 评论 0原文

我在页面上添加了一个链接,单击该链接会生成 pdf 并要求下载我使用的 fpdf 类。

我的新要求是,单击链接应生成 n 个具有不同内容的 pdf,并应要求下载这些 pdf。

我无法找到完成同样任务的方法。

请帮我解决这个问题。

谢谢

I have added 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

冬天旳寂寞 2024-09-09 05:07:05

http://www.phpconcept.net/pclzip/ 你会找到一个不错的 php zip图书馆。 的文件名数组

$filenames = array(
    "file_01.txt",
    "file_02.doc",
    "file_03.pdf"
);

想象一下,有一个像代码这样

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");

(未经测试)希望这会有所帮助;-)

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 ;-)

幸福不弃 2024-09-09 05:07:05

您无法将多个文件发送给用户,但您可以生成它们,在服务器上使用例如 zip 进行打包并作为一个文件发送。

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.

浅笑依然 2024-09-09 05:07:05

将生成的文件发送到浏览器的正确方法是 $pdf->Output() - 这仅允许您发送一个生成的 pdf 文件。发送更多文件的唯一选择是将它们压缩 [1],然后发送包文件。

[1] http://www.devco.net/archives/2005 /05/24/creating_zip_files_with_php.php

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

自由如风 2024-09-09 05:07:05

我在我的 php 页面中使用了以下代码:

 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>";  
    }}
     }

single_letter_fixation.php 中 pdf 文件的输出选项是:

$pdf->Output('D', $personal_file_number.pdf');

效果很好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文