dongqingcheng2903 2014-02-21 12:10
浏览 218

如何使用PHP将dom pdf生成的pdf文件添加到ZipArchive

I have used dom pdf to create a .pdf file from html text content. At the same time I have to create a zip archive and add that pdf file to zip.

That zip contains more two folders as well. I am stuck while adding DOMPDF generated file to the zip archive. Can anyone provide me a solution for this?

  • 写回答

1条回答 默认 最新

  • dongyan0629 2014-02-26 07:41
    关注

    Use this code to make pdf file from html content.

    $html = "put your html code here";
    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->set_paper("a4", "portrait");
    $dompdf->render();
    $output = $dompdf->output();
    file_put_contents('Otherfile.pdf', $output);
    

    After using render() function use output() function to store pdf file in variable. And put that content inside new file using file_put_contents(). Then use that file to put inside .zip using following code.

    $files = 'Otherfile.pdf';
    $zipname = 'zipname.zip';
    $zip = new ZipArchive;      
    $zip->open($zipname, ZipArchive::OVERWRITE);
    $zip->addFile($files);
    
    $zip->close();
    header('Content-Type: application/zip');
    header("Content-Disposition: attachment; filename='".$zipname."'");
    header("Pragma: no-cache"); 
    header("Expires: 0");
    header('Cache-Control: must-revalidate');
    header('Content-Length: ' . filesize($zipname));
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度