删除“打印”从视图渲染PDF之前的按钮 - MVC3 [英] Removing a "Print" button Before Rendering PDF from View - MVC3

查看:82
本文介绍了删除“打印”从视图渲染PDF之前的按钮 - MVC3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我转到 Rotativa (wkhtmltopdf)以获取PDF版本的查看用户打印后,一旦他们点击打印按钮:

I have a view that I pass to Rotativa (wkhtmltopdf) to get a PDF version of the view for users to print, once they click the "print button":

如果用户点击下面的,这是将转换为PDF的渲染视图打印按钮

以下是视图中的按钮代码

Here is the button code from the view

<div id="print-pdf" align="center">
    <a id="print-me"  class = "print-btn"
   href='@Url.Action("PrintMyView", "Report", 
             new { id = Model.MonthlyReportID, 
                   clubKeyNo = Model.ClubKeyNumber, 
                   month = Model.ReportMonth, 
                   year = Model.ReportYear }, null)'>Print Report</a>
</div>

常识告诉我在从视图生成PDF之前需要删除按钮,所以用户无法获得带有按钮的PDF:

Common sense tells me that I need to remove the button before the PDF is generated from the view, so users don't get a PDF with a button on it:

我试图隐藏按钮(.hide())并删除它(.remove())
但是PDF仍然使用按钮进行渲染:

I tried hiding the button (.hide()) and also removing it (.remove()) but the PDF is still rendering with the button:

<script type="text/javascript">

    $(document).ready(function () {

        $('#print-me').show(); 

        $('#print-pdf').click(function () {
            $('#print-me').hide();
        });
    });


</script>

我还可以在这里试试其他什么吗?

Anything else that I could try here?

谢谢!

推荐答案

你可以为PDF做一个版本,这样你就可以处理什么和什么不应该打印

You can do a version for PDF so you can handled what and what no should be printed

javascript中运行的东西不起作用,因为当厄运准备就绪时执行,但Rotativa不会执行任何javascript

what are running in javascript does not work because then executed when the doom is ready, but the Rotativa will not execute any javascript

所以,你只需渲染你需要的东西

so, you render just what you need

@if (Model.mustPrint){ 
    <div id="print-pdf" align="center">
        <a id="print-me"  class = "print-btn"    href='@Url.Action("PrintMyView", "Report",
                     new
                     {
                         id = Model.MonthlyReportID,
                         clubKeyNo = Model.ClubKeyNumber,
                         month = Model.ReportMonth,
                         year = Model.ReportYear
                     }, null)'>Print Report</a> 
    </div>
}

这篇关于删除“打印”从视图渲染PDF之前的按钮 - MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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