2017-08-24 28 views
5

我想要生成一个基本的pdf与wkhtmltopdf phpwrapper。我也在使用yii框架。wkhtmltopdf ContentNotFoundError,代码1

这是我的HTML:

<!doctype html> 
<html> 
    <head> 
    </head> 

    <body> 
      <p>test</p> 
    </body> 
</html> 

我在wktmltopdf设置:

$pdfParams = array(

      'header-html' => $this->tmpHeaderFile->getFileName(), 
      'footer-html' => $this->tmpFooterFile->getFileName(), 

      'username' => 'myUser', 
      'password' => 'myPass', 
     ); 
$this->pdf = new Pdf($pdfParams); 

错误即时得到:

Exception 'Exception' with message 'Could not create PDF: Loading pages (1/6) 
[>               ] 0% 
[======>              ] 10% 
[==============================>        ] 50% 
[============================================================] 100% 
Counting pages (2/6)            
[============================================================] Object 1 of 1 
Resolving links (4/6)              
[============================================================] Object 1 of 1 
Loading headers and footers (5/6)           
[===>              ] 5% 
[======>              ] 10% 
[======>              ] 10% 
[=======>             ] 13% 
[==========>             ] 17% 
[==================================>       ] 57% 
[====================================>      ] 61% 
Warning: Failed to load https://work.mydomain.com/devs/florian/web//devs/florian/web/themes/css/report-footer.css (ignore) 
[============================================================] 100% 
Printing pages (6/6)            
[>               ] Preparing 
[============================================================] Page 1 of 1 
Done                  
Exit with code 1 due to network error: ContentNotFoundError' 

任何想法的问题是什么?

回答

0

我以前遇到类似的问题。使用wkhtmltopdf时,您需要确保将所有静态资产添加到HTML文件中。

例如: CSS文件,使用内部样式表:

<!doctype html> 
<html> 
    <head> 
     <style> 
      html { 
       margin: 0; 
      } 
     </style> 
    </head> 

    <body> 
      <p>test</p> 
    </body> 
</html> 

对于JavaScript文件,直接添加脚本到HTML文件中。

<!doctype html> 
<html> 
    <head> 
     <script type="text/javascript"> 
      var body = document.querySelector('body'); 
     </script> 
    </head> 

    <body> 
      <p>test</p> 
    </body> 
</html> 

我希望这有助于

+0

帮助了我很多感谢 –