【问题标题】:Integrating HTML2PDF in laravel 5.1在 laravel 5.1 中集成 HTML2PDF
【发布时间】:2015-12-20 18:50:59
【问题描述】:

我正在尝试在 laravel 5.1 中集成 html2pdf 库。但它显示如下错误Class 'App\Http\Controllers\HTML2PDF' not found 我的控制器代码如下

require_once(dirname(__FILE__).'/libs/html2pdf/html2pdf.class.php');
$html2pdf = new HTML2PDF('P','A4','en',true,'UTF-8',array(0, 0, 0, 0));
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->WriteHTML($html22);

我的文件夹路径是app/Http/Controllers/libs/html2pdf/html2pdf.class.php

我给出了正确的路径,但它仍然显示错误,例如 HTML2PDF not found。请任何人告诉我如何整合html2pdf?还是我应该在compose.json 文件中做任何更改?

甚至我在控制器页面的顶部添加了 App\Http\Controllers\HTML2PDF 行,但没有用。

请帮帮我。

谢谢

【问题讨论】:

    标签: php laravel laravel-5.1 html2pdf


    【解决方案1】:

    我刚刚下载了最新的,好像没有命名空间。

    删除use App\Http\Controllers\HTML2PDF 并尝试像$html2pdf = new \HTML2PDF('P','A4','en',true,'UTF-8',array(0, 0, 0, 0)); 一样实例化html2pdf

    【讨论】:

    • FatalErrorException in html2pdf.class.php line 0: Method Illuminate\View\View::__toString() must not throw an exception 这是我现在遇到的错误..你能帮帮我吗。
    • 你一定是在呼应什么?
    • 这是代码中其他地方的另一个问题。您应该检查一下,如果它不能回答您的问题,请创建一个新问题。 stackoverflow.com/questions/26534016/…
    • @user3158900 我刚刚浏览了您共享的链接,然后我在 view 添加了 render() 。现在我收到此错误:TokenMismatchException in VerifyCsrfToken.php line 53:。为此,我在视图刀片 php 页面中添加了 <input type="hidden" name="_token" value="{{{ csrf_token() }}}" />。但它仍然给出同样的错误。请帮帮我
    【解决方案2】:

    你可以使用这个包:https://packagist.org/packages/ensepar/html2pdf

    将此添加到您的 composer.json

    "ensepar/html2pdf": "4.0.6"
    

    并运行作曲家更新

    之后,您可以像这样在控制器中使用它

    // add this to the beginning of your controller under the namespace declaration
    use HTML2PDF;
    
    // after that, you can use the class like so
    $html2pdf = new HTML2PDF('P','A4','de',false,'UTF-8');
    $doc = "<page><h1>Hello World</h1></page>";
    $html2pdf->setDefaultFont('Arial');
    $html2pdf->writeHTML($doc,false);
    $html2pdf->Output(base_path().'/storage/app/helloworld.pdf','F');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-06
      • 2016-12-26
      • 2016-03-02
      • 1970-01-01
      • 2017-05-11
      • 2018-01-25
      • 2015-11-02
      • 1970-01-01
      相关资源
      最近更新 更多