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

报告相同问题?

悬赏问题

  • ¥15 用三极管设计一个单管共射放大电路
  • ¥20 fluent无法启动
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架