0

该页面包含下拉列表、文本输入、日期。当我运行wkhtmltopdf它保存空白。解决这个问题的方法是什么。以及如何像下载一样保存。我在哪里可以看到调试结果?谢谢。

测试pdf.php

echo shell_exec("C:\wkhtmltopdf\wkhtmltopdf.exe http://localhost/bigkpo/po/select.php --debug-javascript C:\Taopix\MediaAlbumWeb\webroot\bigkpo\PO\pdf\PO.pdf");

jquery 提交

$(document).ready(function(){
    //disable not 1st select
    $("#description").attr("disabled","disabled");
    $("#orientation").attr("disabled","disabled");
    $("#page").attr("disabled","disabled");

        //start----------------------compny
        $("select#company").change(function()
            {
            $("#description").empty();
            $("#description").html("<option>wait...</option>");
            var id = $("#company option:selected").attr('value');
                        $.post("./includes/select_type.php", {id:id}, 
                        function(data0){
                        $("#description").removeAttr("disabled");
                        $("#description").html(data0);
                        });
                        });

        //start----------------------page
        $("#description").change(function()
            {
            $("#page").empty();
            $("#page").html("<option>wait...</option>");
            var id2 = $("#description option:selected").attr('value');
                        $.post("./includes/select_producprice_n_showpage.php", {id2:id2},
                        function(data1){
                        $("#page").removeAttr("disabled");
                        $("#page").html(data1);

                        //show price---------------------------
                        $("#productPrice").html(data1);
                        $("#productPrice2").html(data1);
                        });
                        });

        //start----------------------orientation
        $("#page").change(function()
            {
            $("#orientation").empty();
            $("#orientation").html("<option>wait...</option>");
            var id3 = $("#page option:selected").attr('value');
                        $.post("./includes/select_pageprice_n_showrientation.php", {id3:id3},
                        function(data2){
                        $("#orientation").removeAttr("disabled");
                        $("#orientation").html(data2);

                        //show insidepagePrice-----------------
                        $("#insidepagePrice").html(data2);
                        $("#insidepagePrice2").html(data2);
                        });

                        var quantity = $("#qty").val();
                        var id2 = $("#description option:selected").attr('value');
                        $.post("./includes/select_total.php", {id2: id2, id3: id3, quantity:quantity},
                        function(data3){

                        //computation------------------------------
                        $("#total").html(data3);
                        var vat = Math.round(data3 / 1.12 * 0.12).toFixed(2);
                        $("#vat").html(vat);
                        $("#sub").html(data3 - vat);
                        });
                        });


        $("form#select_form").submit(function(){
            var side = $("#select_form").html();
            console.log(side);
            });
            });

php表单

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
    <link rel="stylesheet" type="text/css" href="css/styles.css">
    </head>

    <body>

    <?php include "./includes/select.class.php"; ?>

    <div id="wraper">

    <div id="header">
    </div>

    <div id="content">
        <div class="contenthead">
            <img src="css/img/kdi.jpg" align="left" /> 
            <h1> PURCHASE <br> ORDER </h1>
            <table align="right">
                <tr>
                <td><b> Date: </b>  </td> <td>&nbsp; <?php echo date('jS \of F Y'); ?></td>
                </tr>
                <tr>
                <td><b> Ref Number: </b> </td> <td> &nbsp; 271 </td>
                </tr>
            </table>
        </div>

        <div class="contentbody">
        <form id="select_form" action="testpdf.php" method="post">

            <table width="900px">
            <thead>
                <tr align="left">
                    <th class="boldlabel" colspan="3"> Company Name:<br>
                            <select id="company">
                                <?php echo $opt->ShowCategory(); ?>
                            </select>
                    </th>
                    <th class="boldlabel" colspan="2"> <b>  Ship to:    </b> 
                </tr>
                <tr>
                    <td width="110" align="center" class="boldlabel"> QTY </td>
                    <td width="110" align="center" class="boldlabel"> UOM </td>
                    <td width="456" align="center" class="boldlabel"> Description </td>
                    <td width="100" align="center" class="boldlabel"> UNIT PRICE </td>
                    <td width="100" align="center" class="boldlabel"> TOTAL </td>
                </tr>
            </thead>

            <tbody>
                <tr class="top row">
                    <td width="100" align="center"> <input id="qty" type="text" name="qty" style="width: 50px; text-align:center"  align="middle"> </td>
                    <td align="center"> <select>
                                            <option> PC </option>
                                            <option> BOX</option>
                                            <option> PACK</option>
                                        </select>
                                        </td>
                    <td align="left">   <select id="description"></select>  </td>
                    <td align="center"> <label id="productPrice"></label>   </td>
                    <td align="center"> <label id="productPrice2"></label>  </td>
                </tr>
                <tr class="side">
                    <td align="center">&nbsp;   </td>
                    <td align="center">&nbsp;   </td>
                    <td align="left">   <select id="page"></select>
                    </td>
                    <td align="center"> <label id="insidepagePrice"></label>    </td>
                    <td align="center"> <label id="insidepagePrice2"></label>   </td>
                </tr>
                <tr class="side">
                    <td align="center">&nbsp;   </td>
                    <td align="center">&nbsp;   </td>
                    <td align="left">  <select id="orientation"></select>   </td>
                    <td align="center">         </td>
                    <td align="center">         </td>
                </tr>
                <tr class="bottom row">
                    <td align="center">&nbsp;   </td>
                    <td align="center">&nbsp;   </td>
                    <td align="center">         </td>
                    <td align="center">         </td>
                    <td align="center">         </td>
                </tr>

                <tfoot>
                <tr>
                    <td colspan="3">&nbsp;  </td>
                    <td class="leftfoot" align="left"> <b> subtotal </b></td>
                    <td class="rightfoot" align="center"> <label id="sub"></label></td>
                </tr>
                <tr>
                    <td colspan="3">&nbsp;  </td>
                    <td class="leftfoot" align="left"><b> 12% VAT </b></td><br />
                    <td class="rightfoot" align="center">  <label id="vat"> </label> </td>
                </tr>
                <tr>
                    <td colspan="3">&nbsp;  </td>
                    <td class="buttomleftfoot" align="left"> <b> Total Amount </b></td>
                    <td class="buttomrightfoot" align="center"> <label id="total"> </label> </td>
                </tr>
                </tfoot>
            </tbody>
            </table>

            <div class="contentfoot">
            <table width="900px">
            <tr>
            <td width="194"> Requested by: <br> <input type="text" name="qty" style="width: 200px; text-decoration:underline"  align="middle"> </td>
            <td width="476">&nbsp;  </td>
            <td width="214"> Noted by: <br> _____________________ </td>
            </tr>
            <tr>
            <td colspan="1">&nbsp;  </td>

                    <td>
                        <input type="button" value="    Print    ">
                        <br>
                        <input type="submit" value="  Submit  " name="submit"/>
                    </td>
            </tr>
            </table>
            </form>
        </div>
    </div>
        <script type="text/javascript" src="./scripts/jquery-1.8.2.js"></script>
        <script type="text/javascript" src="scripts/process.js"> </script>
</div>
</body>
</html>
4

3 回答 3

0

确保您可以使用表单中的内容转换整个页面需要付出相当多的努力。您实际上必须进行一些服务器端处理才能使用内容重新生成页面,然后传递给 wkhtmltopdf。

仅使用 Web 服务并让您的访问者单击返回 PDF 的链接可能会少很多工作。看看pdfmyform

于 2013-07-08T17:13:36.510 回答
0

您可以使用以下设置来允许呈现 JavaScript 内容。

--enable-javascript
--javascript-delay

有关更多选项,请参阅文档

https://code.google.com/p/wkhtmltopdf/wiki/Usage

您应该能够像这样将参数添加到 shell_exec 命令还尝试将所有参数放在一行并添加扩展名

echo shell_exec("C:\Taopix\MediaAlbumWeb\webroot\wkhtmltopdf\wkhtmltopdf.exe http://localhost/bigkpo/po/select.php C:\Taopix\MediaAlbumWeb\webroot\pdf\google.pdf --enable-javascript --javascript-delay 500");

这将启用 javascript 并在创建屏幕截图之前等待 500 毫秒。您可以添加--debug-javascript以获得有关页面上可能出现问题的调试输出。

更新:
我可以从您的代码中推断出您想要制作一个打印屏幕,以便从用户当前选择的值创建某种收据。您将无法从用户正在显示的浏览器中的页面创建屏幕截图,这不是 wkhtmltopdf 的工作方式。

您将需要存储用户选择的值,然后完全在服务器端重建页面或在客户端提供自动化以填充字段,以便 wkhtmltopdf 可以创建正确的屏幕截图,这需要进行一些重大的重构。我不能再帮你了。

于 2013-05-24T08:50:28.863 回答
0

当涉及到 DOM 文档和 select 语句时,您通常必须自己处理数据。

我的最终解决方案是将预期值与所有可用<option>值进行比较,然后 setAttribute("selected", true) ...

这是我能够解决这个问题的唯一方法(在 PHP 中)。

于 2018-05-14T00:44:16.790 回答