2016-10-12 140 views
0

嘿,我很難安裝wkhtmltopdf和php wkhtmltopdf。我需要首先將它放在本地服務器上,但稍後必須安裝在Web服務器上。我首先在我的項目文件夾中安裝了wkhtmltopdf,然後我通過作曲家安裝了php wkhtmltopdf 1,這是我從未使用過的。所以我不完全確定我是否正確安裝了它,但似乎很簡單,我不認爲這是問題所在。當我運行一個測試PHP腳本我收到此錯誤信息:在本地服務器上安裝php wkhtmltopdf

警告:proc_open():CreateProcess的失敗,錯誤代碼 - 2在C:\ XAMPP \ htdocs中\刪除\供應商\ mikehaertl \ PHP-shellcommand \第313行的src \ Command.php 無法運行命令cd「wkhtmltopdf \ bin」& & wkhtmltopdf.exe「C:\ Users \ Robert \ AppData \ Local \ Temp \ tmpE437.tmp.html」「C:\ Users \羅伯特\應用程序數據\本地的\ Temp \ tmpE438.tmp.pdf」

這裏是我的測試代碼:

/** 
* Register Composer Autloader 
*/ 
define('VENDOR_DIR', __DIR__ . '\vendor' . DIRECTORY_SEPARATOR); 

if (!is_file(VENDOR_DIR . 'autoload.php')) { 
    throw new \RuntimeException(
     '[Error] Bootstrap: Could not find "vendor/autoload.php".' . PHP_EOL . 
     'Did you forget to run "composer install --dev"?' . PHP_EOL 
    ); 
} 

require VENDOR_DIR . 'autoload.php'; 

/** 
* Use library 
*/ 

use mikehaertl\wkhtmlto\Pdf; 


$pdf = new Pdf(array(
    'binary' => 'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe', 
    'ignoreWarnings' => true, 
    'commandOptions' => array(
     'procEnv' => array(
      // Check the output of 'locale' on your system to find supported languages 
      'LANG' => 'en_US.utf-8', 
     ), 
     'escapeArgs' => false, 
     'procOptions' => array(
      // This will bypass the cmd.exe which seems to be recommended on Windows 
      'bypass_shell' => true, 
      // Also worth a try if you get unexplainable errors 
      'suppress_errors' => true, 
     ), 
    ), 
)); 

$pdf->addPage('<html> 
<head> 
</head> 
<body> 

    <div id="print-area"> 
     <div id="header"> 
      This is an example header. 
     </div> 
     <div id="content"> 
      <h1>Demo</h1> 
      <p>This is example content</p> 
     </div> 
     <div id="footer"> 
      This is an example footer. 
     </div> 
    </div> 

</body> 
</html>'); 

if (!$pdf->saveAs('page.pdf')) { 
    echo $pdf->getError(); 
} 

有誰知道這個問題可能是什麼?我需要從本地服務器執行wkhtmltopdf,因爲它需要聯機工作。我發現另一個有用的堆棧溢出主題,我將鏈接2,我經歷了所有的步驟,但無法正確執行它。任何幫助將非常感激! :)

php wkhtmltopdf stack overflow -installing php wkhtmltopdf

回答

0

從命令二進制路徑

刪除.exe文件添加'useExec'=>真選項

檢查這個代碼:

include __DIR__ . '/../vendor/autoload.php'; 

use mikehaertl\wkhtmlto\Pdf; 

$pdf = new Pdf(array(
    'binary' => 'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf', 
    'ignoreWarnings' => true, 
    'commandOptions' => array(
     'useExec' => true, 
     'procEnv' => array(
      'LANG' => 'en_US.utf-8', 
     ), 
     'escapeArgs' => false, 
     'procOptions' => array(
      'bypass_shell' => true, 
      'suppress_errors' => true, 
     ), 
    ), 
)); 

$pdf->addPage('<html><body><h1>test</h1></body></html>'); 

if (!$pdf->saveAs('page.pdf')) { 
    echo $pdf->getError(); 
} 
相關問題