如何使用Laravel barryvdh/laravel-dompdf停止ERR_CONNECTION_RESET问题 [英] How to stop a ERR_CONNECTION_RESET issue with Laravel barryvdh/laravel-dompdf

查看:97
本文介绍了如何使用Laravel barryvdh/laravel-dompdf停止ERR_CONNECTION_RESET问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有Laravel的barryvdh/laravel-dompdf软件包来生成要打印的PDF.

I'm using the barryvdh/laravel-dompdf package with Laravel to generate PDF's for printing.

下载PDF时出现此错误.(加载大约10秒钟,然后出现错误)

When I download the PDF I get this error.. (Loads for about 10 sec then error)

无法访问此站点连接已重置.

This site can’t be reached The connection was reset.

尝试:检查连接检查代理和防火墙正在运行Windows网络诊断ERR_CONNECTION_RESET

Try: Checking the connection Checking the proxy and the firewall Running Windows Network Diagnostics ERR_CONNECTION_RESET

URL是有效的链接,就像我使用相同的链接/视图来构建PDF一样.

The URL is a valid link as I was using the same link / view to build the PDF.

这是我从Controller那里获得的代码:

use PDF;
...
    public function haitiKidPdf($childId){
        $haitiKid = Kid::findOrFail($childId);
        $pdf = PDF::loadView('admin.cdp.haiti-kid-pdf', compact('haitiKid'));
        return $pdf->download('haiti-kids.pdf');
}

这就是我用来创建页面并提取数据的方法.(这是我知道URL正确的方式.)

This was what I was using to create the page and pull in the data. (This is how I know the URL is correct.)

    public function haitiKidPdf($childId){
        $haitiKid = Kid::findOrFail($childId);
        return view('admin.cdp.haiti-kid-pdf',compact('haitiKid'));
}

在我的视图内( haiti-kid-pdf.blade.php ).我使用了大量的PHP动态填充所有必需的数据.

Inside my view (haiti-kid-pdf.blade.php) I'm using a lot of PHP to dynamically populate all the necessary data.

<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">

<head>
    <title>PDF</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="{{ asset('/css/app.css') }}" rel="stylesheet">
    <style>
    body {
        font-family: 'Muli', sans-serif;
        background-color: #1E1F26 !important;
    }

    .cutline {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate3d(-50%, -50%, 0);
        border-right: 1px dotted rgba(21, 87, 36, 0.25);
        z-index: 99999;
        width: 5.5;
        height: 8.5in;
....

    @media print {


        * {
            -webkit-print-color-adjust: exact;
        }

        html {
            background: none;
            padding: 0;
        }

        body {
            box-shadow: none;
            margin: 0;
        }
...
    </style>
</head>
...
<img alt="Name Here" src="{{asset("storage/images/cdp/$haitiKid->cin/profile-img/$haitiKid->child_img")}}">
                                </div>
                            </div>
                        </div>
                        <!-- END KID IMAGE -->
                        <div class="kid-name-box relative">
                            <div class="kid-name absolute pin-c-y ml-2 font-black leading-none text-navy-500">
                                <span class="first-name">{{ $haitiKid->first_name }}</span>
                                <span class="last-name">{{ $haitiKid->last_name }}</span>
                            </div>
                        </div>
                        <div class="slot-box absolute bg-red-500">
                            <div class="slot-box-name absolute pin-c-y ml-2">
                                @php
                                $numReceived = $haitiKid->sponsors_received;
                                $numNeeded = $haitiKid->sponsors_needed - $numReceived;
                                @endphp
                                @for($i = 0; $i < $haitiKid->sponsors_needed; $i++ )
                                    @if($numReceived-- > 0)
                                    <span class="slot-circ relative"></span>
                                    @else
                                    <span class="slot-circ-outline relative"></span>
                                    @endif
                                    @endfor
                                    <span class="font-black leading-none text-white uppercase">{{ $numNeeded }} {{ str_plural('Slot', $numNeeded) }} Available</span>
                            </div>
                        </div>
etc...

    }

基本生成此内容以在11英寸x 8.5英寸的纸上打印出来.

Basically generating this to print out on a 11in x 8.5in piece of paper.

https://codepen.io/daugaard47/full/pozgdeM

我的代码不正确,还是需要在php.ini文件中安装其他软件?

  • 我正在使用PHP 7.2.2
  • 当前在本地主机上
  • 我将Enable inline PHP设置为true "enable_php" =>是dompdf.php配置文件
  • 如果我加载视图,然后选择打印">打印为PDF",效果会很好,但这违背了我要达到的目的.
  • I'm using PHP 7.2.2
  • Currently on localhost
  • I have Enable inline PHP set to true "enable_php" => true, in the dompdf.php config file
  • If I load the view and then select Print > Print to PDF it comes out fine, but that defeats the purpose of what I'm trying to accomplish.

在此待了几天.任何帮助将不胜感激.

Been at this for days. Any help would be appreciated.

推荐答案

最终解决方案

  1. /tmp目录的权限
  2. 确保安装php BCMath模块

它对我有用:)

    chmod -R 777 /tmp
    sudo apt install php7.2-bcmath
    
    systemctl restart php7.2-fpm

这篇关于如何使用Laravel barryvdh/laravel-dompdf停止ERR_CONNECTION_RESET问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆