2014-02-26 47 views
2

我是symfony2的新手,非常喜歡使用外部庫。 我想使用我的第一個第三方軟件包KNP Snappy Bundle使用knp snappy包生成pdf - symfony2

我完全是在git鏈接中告訴的。

{ 
    "require": { 
     "knplabs/knp-snappy-bundle": "dev-master" 
    } 
} 

//應用程序/ AppKernel.php

public function registerBundles() 
{ 
    $bundles = array(
     //... 
     new Knp\Bundle\SnappyBundle\KnpSnappyBundle(), 

應用/配置/ config.yml

knp_snappy: 
    pdf: 
     enabled: true 
     binary:  /usr/local/bin/wkhtmltopdf 
     options: [] 
    image: 
     enabled: true 
     binary:  /usr/local/bin/wkhtmltoimage 
     options: [] 

然後,我添加下面的行中ACME歡迎控制器以測試

$this->get('knp_snappy.pdf')->generate('http://www.google.fr', '/Symfony/file.pdf'); 

它說The exit status code '1' says something went wrong: stderr: "The system cannot find the path specified. " stdout: "" command: /usr/local/bin/wkhtmltoimage --format "jpg" "http://www.google.fr" "/Symfony/file.pdf".

我試圖

$this->get('knp_snappy.pdf')->generateFromHtml(
    $this->renderView(
     'AcmeDemoBundle:Welcome:index.html.twig'), 
     '/Symfony/file.pdf' 
    ); 

它顯示The exit status code '1' says something went wrong: stderr: "The system cannot find the path specified. " stdout: "" command: /usr/local/bin/wkhtmltopdf --lowquality "C:\Windows\TEMP\knp_snappy530da4525584b8.92211088.html" "/Symfony/file.pdf".

什麼我失蹤?我需要安裝任何東西嗎?請描述我如何運行它並生成一個合適的pdf?我搜索,我猜我需要安裝wkhtmltoimage等,但從哪裏和如何?

+0

好吧,它看起來像你在Windows上,並且你指定了一個Linux路徑......我假設你沒有[download](http://wkhtmltopdf.org/)二進制文件。 – Touki

+0

@Touki安裝了二進制文件。未能配置Windows的路徑。二進制文件位於C:\ Program Files \ wkhtmltopdf \ bin中。所以我在config.php中顯示了路徑。它仍然說'退出狀態碼'1'表示出了點問題:stderr:''C:/ Program'不被識別爲內部或外部命令,可操作程序或批處理文件。' – AtanuCSE

+0

向我們展示配置文件 –

回答

4

幾個月後,但這是什麼幫助我。

我把路徑放到了wkthmltopdf文件夾中的轉義雙引號中。

knp_snappy: 
    pdf: 
     binary: "\"C:/Program Files (x86)/wkhtmltopdf/wkhtmltopdf.exe\"" 
0

你能做到這些

1-更新的一個你config.yml

pdf: 
    enabled: true 
    binary:  wkhtmltopdf 
    options: [] 
  • 和更新您的窗戶,path/to/my/wkhtmltopdf

2-環境路徑或設置路徑直接在config.yml中

pdf: 
     enabled: true 
     binary:  /path/to/my/wkhtmltopdf 
     options: [] 
+0

wkhtmltopdf位於C:\ Program Files \ wkhtmltopdf \ bin中,並使用它生成此'退出狀態代碼'1'表示出錯: stderr:「'C:/ Program'不被識別爲內部或外部命令, 可操作的程序或批處理文件。'和'二進制:wkhtmltopdf'它說'退出狀態代碼'1'說出了點問題: stderr:'''wkhtmltopdf'不被識別爲內部或外部命令' – AtanuCSE

+0

我試圖設置路徑變量爲bin文件夾和.exe文件,它們都不起作用。 – AtanuCSE

7

您還可以管理與作曲家wkhtmltopdf過,我做到了,在最近的一個項目:

在composer.json

您可以添加:

"h4cc/wkhtmltopdf-amd64": "0.11.0-RC1" 

,並在您config.yml:

binary:  %kernel.root_dir%/../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 
+1

二進制代碼在Windows中不起作用。 – parisssss