【问题标题】:How to use laravel snappyPDF on localhost:8000/storage/file.html?如何在 localhost:8000/storage/file.html 上使用 laravel snappyPDF?
【发布时间】:2018-02-12 16:11:57
【问题描述】:

我目前正在尝试使用 snappy laravel 从 html 文件生成 pdf。当我调用我的 to pdf 方法时,我的服务器冻结并输出 60 秒超时错误。我在github issue 中读到 wkhtmltopdf 不喜欢使用端口 8000,我想知道是否有任何解决方法,我尝试将google.com 打印为 pdf 和它正在工作......

我也无法从我的 html 文件内容(存储在变量中的内容)打印 pdf,我猜这是因为 css 文件,这是我正在做的一个示例:

$snappy->generate('http:localhost:8000/storage/file.html', $fileName.'.pdf');

这是 file.html 的内容。

<div class="pdfContainer">
    <meta charset="UTF-8">
    <link href="http://localhost:8000/css/pdfpreview.css" rel="stylesheet" type="text/css">
    <div class="headerPreview">
        <img src="http://localhost:8000/image/logo.png">
        <div class="soumissionInfoContainer">
            <div>
                <strong>Soumission # </strong>
                <strong>Projet :</strong>
                <strong>Date : </strong>
            </div>
            <div>
                <p> S1-17</p>
                <p>Garage de béton</p>
                <p> 20-02-2017</p>
            </div>
        </div>
        <div class="infoComp">
            <p>2236, rue de l'Ardoise, Jonquière (QC) G8A 0A5</p>
            <p>Saguenay : 418-550-5382 Alma : 418-719-0588</p>
            <p>R.B.Q.: 5670-0578-01</p>
        </div>
        <h2>SOUMISSION</h2>
        <div class="clientInfoContainer">
            <div style="width:70px;"><p style="font-size: 12px;text-align: right">Destinataire: </p>
            </div>
            <div>
                <p>Jean Tremblay</p>
               <p>1010 St Hubert
                    , G7H 2B1</p>
                <p>418 555 5555</p>
            </div>
    </div>
    </div>
<table class="previewTable" id="previewTable">
    <tbody>
    <tr>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <th>Quantité</th>
        <th>Description</th>
        <th>Prix</th>
    </tr>
    <tr>
        <td></td>
        <td>
            <textarea id="title1" onchange="setInnerHTML('title1')"
                      style="font-size: 2em; background: rgba(0, 0, 0, 0) none repeat scroll 0% 0%; height: 99px;">Excavation lol</textarea>
        </td>
        <td><textarea id="total1" onchange="setInnerHTML('total1')"
                      style="background: rgba(0,0,0,0); width: 100px; height: 70px">919.51</textarea>
        </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <textarea id="desc1" onchange="setInnerHTML('desc1')" style="resize: horizontal; width: 553px;" rows="5"
                      cols="50" title="">                            this is working</textarea>
        </td>
    </tr>
    </tbody>
</table>
<script>
    function setInnerHTML(id) {
        var area = document.getElementById(id);
        area.innerHTML = area.value;
    }
</script>
<textarea class="totalSoumission" id="totalSoumission" onchange="setInnerHTML('totalSoumission')">TOTAL AVANT TAXES: 919.51 $</textarea>
    <div class="ligne_signature">
        <p>À la signature, ce devis est bon pour travaux et valide 90 jours</p>
    </div>
</div>

我最关心的是,当我收到消息输出错误时,我复制并粘贴了确切的命令并将其粘贴到我的终端中,并且在不到一秒钟的时间内生成了 pdf,所以这意味着真的有我的 pdf 使用问题...

【问题讨论】:

    标签: php laravel wkhtmltopdf snappy


    【解决方案1】:

    snappy 失败的原因是 wkhtmltopdf 不喜欢使用当前主机资源。使用 wkhtmltopdf 时,您无法从主机获取任何内容。您需要在 URI 中转换您的图像,这样您就不会从您的公共目录中获取它们,并且您需要在您的 html 中插入您的 css,链接不会这样做。 对于我自己,我使用刀片将 css 与我的页面分开。在我的情况下,这失败的主要原因是因为我试图从 127.0.0.1:8000(我当前的主机)获取 ccs 表。

    问题:

     <link href="http://localhost:8000/css/pdfpreview.css" rel="stylesheet" type="text/css">
    

    解决方案:

    <style>
    ...
    </style>
    

    【讨论】:

      猜你喜欢
      • 2016-03-28
      • 2016-06-14
      • 1970-01-01
      • 2016-03-31
      • 1970-01-01
      • 2017-10-21
      • 2021-11-21
      • 1970-01-01
      • 2019-06-14
      相关资源
      最近更新 更多