barryvdh / laravel-snappy-退出状态代码“ 1”表示出了点问题:\ nstderr:\“正在加载页面(1/6)\ r \ n

时间:2019-07-29 12:41:37

标签: php laravel laravel-nova laravel-snappy phpwkhtmltopdf

Laravel 5.8 PHP 7.3.15 新星2.0 操作系统Windows 10专业版

Snappy.php

return array(
    'pdf' => array(
        'enabled' => true,
        // 'binary'  => '/usr/local/bin/wkhtmltopdf',
        'binary'  => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),
    'image' => array(
        'enabled' => true,
        // 'binary'  => '/usr/local/bin/wkhtmltoimage',
        'binary'  => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage"',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),
);

在新星行动中

$pdf = app('snappy.pdf.wrapper')->loadView('nova::mytemplates.mytemplate', ['value' => $value])
            ->setWarnings(false)
            ->setPaper('a4')
            ->setOption('header-html', route('pdf.header'))
            ->setOption('footer-html', route('pdf.footer'))
            ->save(base_path() . '/public/prints/' . $filename);

可以在控制台中确认安装正确

C:\Program Files\wkhtmltopdf\bin>wkhtmltopdf http://127.0.0.1:8000/pdf-header D:/test.pdf
Loading pages (1/6)
QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files
QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

C:\Program Files\wkhtmltopdf\bin>wkhtmltopdf http://127.0.0.1:8000/pdf-footer D:/test.pdf
Loading pages (1/6)
QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files
QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files
libpng warning: iCCP: known incorrect sRGB profile           ] 42%
libpng warning: iCCP: known incorrect sRGB profile           ] 52%
libpng warning: iCCP: known incorrect sRGB profile
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

Header.blade.php

<!DOCTYPE Html>
<html lang="en">
    <head>
        <link rel="stylesheet" href="{{ public_path('css\style.css') }}" media="all" />
    </head>
    <body>
        {{-- Hear content of header  --}}
    </body>
</html>

footer.blade.php

<!DOCTYPE Html>
    <html lang="en">
        <head>
            <link rel="stylesheet" href="{{ public_path('css\style.css') }}" media="all" />
        </head>
        <body>
            {{-- Hear content of footer  --}}
        </body>
    </html>

mytemplate.blade.php

<div id="my-print-content" class="my-print-content">
     {{-- Hear main content  --}}
</div>

但是当我执行操作时,我得到了错误

The exit status code '1' says something went wrong:\nstderr: \"Loading pages (1/6)\r\n

生成的HTML header.php

<!DOCTYPE Html>
<html dir="ltr" lang="en" class="no-js">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width" />

    <title>sprSimple Invoice</title>

    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>

    <link rel="stylesheet" href="D:\work\www\myapp\public\css\reset.css" media="all" />
    <link rel="stylesheet" href="D:\work\www\myapp\public\css\style.css" media="all" />
    <!--<link rel="stylesheet" href="D:\work\www\myapp\public\css\print.css" media="print" />-->

    <!-- give life to HTML5 objects in IE -->
    <!--[if lte IE 8]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->

    <!-- js HTML class -->
    <script>(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement)</script>

    <style>
        @page  {
            margin: 0cm 0cm 0cm 0cm ;
        }
        @media  print {
          body {
              margin: 0cm 1.25cm 2.9cm 1.25cm;
          }
        }
        #footer-main{
          /*position: fixed!important;
          bottom: 0;
          left:0;
          right: 0;
          height: 2.9cm;*/
          margin-top: 20px;
        }
    </style>
</head>
<body>
<!-- begin markup -->



<div id="invoice" class="new"><!-- print -->

    <header id="header"><!-- HEADER -->
        <div class="invoice-logo">
            <img src="http://127.0.0.1:8000/img/logo.jpg" width="100%" alt="">
        </div>


        <div class="invoice-from"><!-- HEADER FROM -->
            <div class="org">My company<br>company address</div>
            <div class="org">Phone: 0123456789</div>
                <a class="email" href="mailto:info@mycompany.com">E-mail: info@mycompany.com</a>
        </div><!-- HEADER FROM -->

    </header><!-- HEADER -->
    <!-- e: print header -->
</body>
</html>

和页脚html

<!DOCTYPE Html>
<html dir="ltr" lang="en" class="no-js">
<head>

<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>

<link rel="stylesheet" href="D:\work\www\myapp\public\css\reset.css" media="all" />
<link rel="stylesheet" href="D:\work\www\myapp\public\css\style.css" media="all" />
<!--<link rel="stylesheet" href="D:\work\www\myapp\public\css\print.css" media="print" />-->

<!-- give life to HTML5 objects in IE -->
<!--[if lte IE 8]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->

<!-- js HTML class -->
<script>(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement)</script>

<style>
    @page  {
        margin: 0cm 0cm 0cm 0cm ;
    }
    @media  print {
      body {
          margin: 0cm 1.25cm 2.9cm 1.25cm;
      }
    }
    #footer-main{
      /*position: fixed!important;
      bottom: 0;
      left:0;
      right: 0;
      height: 2.9cm;*/
      margin-top: 20px;
    }
</style>
</head>
<body>
<footer id="footer">
    <ul class="cust-footer-cont">
        <li>
            <img src="http://127.0.0.1:8000/img/email.png" alt=""> <span>info@mycompany.com</span>
        </li>
        <li>
            <img src="http://127.0.0.1:8000/img/phone.png" alt=""> <span>0123456789</span>
        </li>
        <li>
            <img src="http://127.0.0.1:8000/img/company.png" alt=""> <span>www.mycompany.com</span>
        </li>
    </ul>
    <!-- <div class="foot-cont content-first">
        <div class="footer-mail">info@mycompany.com</div>
        <div class="footer-phone">0123456789</div>
        <div class="footer-web">www.mycompany.com</div>
        <div style="clear: both;"></div>
    </div> -->
</footer>
</div>
</div>

</body>
</html>

0 个答案:

没有答案