duanfu3634 2017-04-05 10:15
浏览 127
已采纳

合并几个pdf文件

I want to merge several pdf files. How can I do that ?

What I have so far is this.

I'm trying to use this package myokyawhtun/PDFMerger.

    include base_path('vendor/myokyawhtun/pdfmerger/PDFMerger.php');

    $pdf = new \PDFMerger;

    $pdf->addPDF(public_path('doc/uploads/doc_1.pdf'), 'all');
    $pdf->addPDF(public_path('doc/uploads/doc_2.pdf'), 'all');

    $pdf->merge('file', public_path('doc/files/test.pdf'));

The errors are different depending on what files I try to merge.

  • If I try to merge the same pdf twice, the file is generated but all blank.
  • If I try with the code above, I get HTTP ERROR 500.
  • If I try with more files, I get tcpdi_parser - Out of memory error.

Bottom line is that it doesn't seem to work.

I already tried several other packages that use FPDI. Problem is that it only works with pdf versions equal or lower to 1.4 (if I'm not mistaken). So using any of those doesn't seem to be an option.

I'm well aware that the question has already been asked, none of the solution seems to work.

  • 写回答

1条回答 默认 最新

  • dongmeng2509 2017-04-05 10:25
    关注

    you could try to call an external tool with exec

    exec("convert -density 300x300 -quality 100 " 
        . public_path('doc/uploads/doc_1.pdf') . " "
        . public_path('doc/uploads/doc_2.pdf') . " "
        . public_path('doc/uploads/merged.pdf')
    

    see other possible tools than convert: here

    Warning: keep in mind that calling exec is not a good idea in general, you should try to avoid it due to potential security leaks. Be absolutely safe, that the public_path function cannot inject malicious commands from user input!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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