3

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

快速的.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

头文件.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>

页脚.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>
4

0 回答 0