doubingjiu3199 2012-02-03 14:17
浏览 107
已采纳

在linux centos上通过php运行pdftk

I would like to run pdftk on my webserver. It's a Linux Centos with PHP 5.3.2.

When I connect it by commande line I do

pdftk --version

It's OK

pdftk A=p1-9.pdf cat A1 output p1.pdf

It's OK.

Now, I do this by php :

exec(pdftk A=p1-9.pdf cat A1 output p1.pdf)

It isn't OK. Why?? I search about the link of file, but it looks OK.

This doesn't work too :

exec(pdftk --version)

I install pdftk with this How do I install Pdftk on my server?

So what's wrong??

Thank for your help!

  • 写回答

1条回答 默认 最新

  • douche3791 2012-02-03 14:54
    关注

    I've run into this issue before. Assuming that you're wrapping your commands string in quotes (as gioele noted), the issue may be that you need to set your path when running the system command. Try this:

    $command = "pdftk A=p1-9.pdf cat A1 output p1.pdf";
    system("PATH=\$PATH:/usr/bin/ && $command",$response);
    if ($response===FALSE){
       //there was an error, handle it
    }
    

    (I've added a little response handling there as well). If that doesn't work, check to see what path you should use (it will depend on where you installed PDFTK).

    I believe you can also get the same result by using putenv("PATH=" .[your path]); and I've used system() here, but exec() should be affected in the same way

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

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度