Rotativa ViewAsPDF服务器上的速度非常慢

问题描述

到目前为止我做了什么

我正在开发一个程序,其中有一些可以显示用户的收据。发生这种情况时,我有一个按钮,可以单击以将收据生成为pdf。我已经使用Rotativa ActionAsPdf和ViewsAsPDF在本地笔记本电脑上完成此操作。但这就是我的成功停滞不前的地方。

问题

我将所有这些转移到服务器上,而ActionAsPdf绝对拒绝工作,我必须至少阅读了23篇有关dll和运行时的文章,并将其放在Rotativa文件夹中,但这些对我都不起作用。我尝试使用Viewaspdf,在这里我再次获得了一些成功,但是当我将代码移到服务器上时,再次失败了。 pdf的渲染虽然在笔记本电脑上大约需要1/2的渲染速度,但是在服务器上却非常缓慢,我在论坛上看到有关外部CSS并添加“ --print-media-type”的问题,但这些都没有解决我的问题。我还应该注意,我可以手动运行wkhtmltopdf。

请在下面找到代码

[AllowAnonymous]
public ActionResult viewInvoice(Guid cartID)
{

    var invoice = from t in db.Transactions
                  join p in db.Payment_Types
                    on t.paymentTypeId_FK equals p.paymentTypeId
                  join c in db.Carts
                    on t.cartId_FK equals c.cartId
                  join u in db.Users
                    on c.accountId_FK equals u.Id
                  join d in db.Departments
                       on p.deparmentId_FK equals d.departmentId
                  join m in db.Ministries
                      on d.ministryId equals m.ministryId
                  where t.cartId_FK == cartID
                  select new
                  {
                      t.amount,c.totalAmount,p.name,c.invoiceNum,c.datePaid,c.taxAmt,c.finalAmt,c.cartId,u.FirstName,u.LastName,d.departmentName,m.ministryName
                  };


    ViewBag.minName = invoice.Select(e => e.ministryName).FirstOrDefault();
    ViewBag.departmentName = invoice.Select(e => e.departmentName).FirstOrDefault();
    ViewBag.datePaid = invoice.Select(e => e.datePaid).FirstOrDefault();
    ViewBag.invoiceNum = invoice.Select(e => e.invoiceNum).FirstOrDefault();
    ViewBag.fullName = invoice.Select(e => e.FirstName + " " + e.LastName).FirstOrDefault();
    ViewBag.amount = invoice.Select(e => e.totalAmount).FirstOrDefault();
    ViewBag.taxAmt = invoice.Select(e => e.taxAmt).FirstOrDefault();
    ViewBag.finalAmt = invoice.Select(e => e.finalAmt).FirstOrDefault();
    ViewBag.cartId = invoice.Select(e => e.cartId).FirstOrDefault();


    OrderHistory orderHistory = new OrderHistory();

    orderHistory.no = db.vw_OrderHistory.Where(d => d.cartId_FK == cartID).Select(d => new noVm
    {


        amount = d.amount,name = d.name,}).ToList();




    var z = new Viewaspdf("InvoicePreview",orderHistory);

     z.Cookies = Request.Cookies.AllKeys.ToDictionary(k => k,k => Request.Cookies[k].Value);
    z.FormsAuthenticationCookieName = System.Web.Security.FormsAuthentication.FormsCookieName;
    //z.CustomSwitches = "--load-error-handling ignore";
    //z.CustomSwitches = "--print-media-type";
    //z.FormsAuthenticationCookieName = FormsAuthentication.FormsCookieName;
    return z;

}

查看

@{
    Layout = null;
}
<head>

 
    <Meta charset="utf-8">
    <Meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=0,minimal-ui">
    <Meta http-equiv="X-UA-Compatible" content="IE=edge" /> 

    <!-- Favicon icon -->
    <link rel="icon" href="~/Content/assets/images/favicon.ico" type="image/x-icon">
 
    <!-- prism css -->
    <!-- vendor css -->
    <link rel="stylesheet" href="~/Content/assets/css/style.css">
    <title> </title>
 

    @*<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://code. jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>*@
    <link rel="stylesheet" href="~/Content/jquery-ui.css">
    <script src="~/Scripts/jquery-ui.min.js"></script>

    <style>
        body {
            background-color: white !important;
        }
    </style>
</head>

<div class="main-body ">
    <div class="page-wrapper">
        <!-- [ Main Content ] start -->
        <div class="row">
            <!-- [ Invoice ] start -->
            <div class="container" id="printTable">
                <div>
                    <div class="card">
                        <div class="row invoice-contact">
                            <div class="col-md-8">
                                <div class="invoice-Box row">
                                    <div class="col-sm-12">
                                        <table class="table table-responsive invoice-table table-borderless">
                                            <tbody>
                                                <tr>
                                                    @*<td><img src="~/Content/assets/images/logo-dark.png" class="m-b-10" alt=""></td>*@
                                                </tr>
                                                <tr>
                                                    <td>  </td>
                                                </tr>
                                                <tr>
                                                    <td> </td>
                                                </tr>
                                                <tr>
                                                    <td><a class="text-secondary" href="sdm" target="_top"> </a></td>
                                                </tr>
                                                <tr>
                                                    <td> </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4"></div>
                        </div>
                        <div>
                            <table width="100%" style="margin:auto;vertical-align:top" align="center">
                                <tr>
                                    <td valign="top" width="30%">
                                        <h6>Client information :</h6>
                                        <h6 class="m-0">@ViewBag.fullName</h6>
                                        @*<p class="m-0 m-t-10">1065 Mandan Road,Columbia MO,Missouri. (123)-65202</p>
                                            <p class="m-0">(1234) - 567891</p>
                                            <p><a class="text-secondary" href="mailto:demo@gmail.com" target="_top">demo@gmail.com</a></p>*@
                                    </td>
                                    <td valign="top" width="30%">
                                        <h6>Order information </h6>
                                        <table class="table table-responsive invoice-table invoice-order table-borderless">
                                            <tbody>
                                                <tr>
                                                    <td><b> Date :</b> @ViewBag.datePaid</td>

                                                </tr>
                                                <tr>
                                                    <td><b>Status :</b>   <span class="label label-success">Paid</span></td>

                                                </tr>
                                                <tr>
                                                    @*
                                                        <th>Id :</th>
                                                        <td>
                                                            #146859
                                                        </td>*@
                                                </tr>
                                            </tbody>
                                        </table>

                                    </td>
                                    <td valign="top" width="30%">

                                        <h6 class="m-b-20">Invoice Number: <span>@ViewBag.invoiceNum</span></h6>
                                        <h6 class="text-uppercase text-primary">
                                            Total Paid :
                                            <span>$@ViewBag.finalAmt</span>
                                        </h6>

                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="card-block">

                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="table-responsive">
                                        <table class="table  invoice-detail-table">
                                            <thead>
                                                <tr class="thead-default">
                                                    <th style="text-align:left">Description</th>
                                                    <th></th>
                                                    <th></th>
                                                    <th style="text-align:right;padding-right:100px">Total</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                @foreach (var item in Model.no)
                                                {
                                                    <tr>

                                                        <td>
                                                            <h6>@item.name</h6>
                                                            <p>@ViewBag.minName - @ViewBag.departmentName</p>
                                                        </td>
                                                        <td></td>
                                                        <td></td>
                                                        <td style="text-align:right;padding-right:100px">@item.amount</td>
                                                    </tr>
                                                }
                                                @*<tr>
                                                        <td>
                                                            <h6>logo Design</h6>
                                                            <p>lorem ipsum dolor sit amet,consectetur adipisicing elit,sed do eiusmod tempor incididunt </p>
                                                        </td>
                                                        <td>7</td>
                                                        <td>$100.00</td>
                                                        <td>$700.00</td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <h6>logo Design</h6>
                                                            <p>lorem ipsum dolor sit amet,sed do eiusmod tempor incididunt </p>
                                                        </td>
                                                        <td>5</td>
                                                        <td>$150.00</td>
                                                        <td>$750.00</td>
                                                    </tr>*@
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12">
                                    <table class="table table-responsive invoice-table invoice-total">
                                        <tbody style="padding-right:90px">
                                            <tr>
                                                <th>Sub Total :</th>
                                                <td>$@ViewBag.amount</td>
                                            </tr>
                                            <tr>
                                                <th>Service Charge(3%) :</th>
                                                <td>$@ViewBag.taxAmt</td>
                                            </tr>
                                            @*<tr>
                                                    <th>discount (5%) :</th>
                                                    <td>$45.00</td>
                                                </tr>*@
                                            <tr class="text-info">
                                                <td>
                                                    <hr />
                                                    <h5 class="text-primary m-r-10">Total :</h5>
                                                </td>
                                                <td>
                                                    <hr />
                                                    <h5 class="text-primary">$@ViewBag.finalAmt</h5>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12">
                                    <h6>Terms And Condition :</h6>
                                    <p>

                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <!-- [ Invoice ] end -->
        </div>
        <!-- [ Main Content ] end -->
    </div>
</div>

我有很多明智的做法,但是我不认为这是速度问题。但是,我首先显示发票,然后有一个调用Viewaspdf的按钮,该按钮再次进行相同的计算,我认为这不是最好的。另外,我也在寻找Rotativia的替代产品,我们将为您提供任何帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)