自动打开 Rotativa 打印对话框

Open Rotativa print dialog automatically

我正在使用 Rotativa 生成视图的 PDF 以打印它。

我有以下代码

public ActionResult PrintTicket(string tempTickID)
{
   //var tick = ctx.vw_printTicket.Where(e => e.noTicket == tempTickID).FirstOrDefault();
   // return View(tick);

    var report = new ActionAsPdf("PrepareTicket", new { tempTickID = tempTickID });
    return report;
}

ActionAsPdf 允许我以 pdf 格式打开 "PrepareTicket" 视图,然后我可以打印。

问题

我的问题是,pdf 占据了我的整个页面,虽然我可以打印,但我无法再访问我的程序菜单,因为它现在是 PDF 视图。

问题

我可以自动调用打印对话框而不是显示 pdf 吗?

我认为适合我的情况。

此致

您好,我已尝试创建一个示例来解决您的问题。

  1. Model
public class Ticketinfo
{
    public string name { get; set; }
    public int quantity { get; set; }
}
  1. Created a Controller which has 3 Action Method
public class GenerateController : Controller
{

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult PrintTicket(string tempTickID)
        {
            return new ActionAsPdf("RotativaPartialViewAsPdf", new { tempTickID = tempTickID });
        }

        public ActionResult RotativaPartialViewAsPdf(string tempTickID)
        {
            Ticketinfo Ticketinfo = new Ticketinfo()
            {
                name =  "Demo",
                quantity = 5
            };

            return PartialView("_RotativaPartialViewAsPdfl", Ticketinfo);
        }

}
  1. Partial View
@model WebApplication6.Models.Ticketinfo
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link href="~/Content/bootstrap.css" rel="stylesheet" />
</head>
<body>
    <div class="container">
        <table class="table">
            <tr class="info">
                <td>Lot</td>
                <td>Name</td>
                <td>Quantity</td>
            </tr>
            <tr class="success">
                <td>@Model.name</td>
                <td>@Model.quantity</td>
            </tr>
        </table>
    </div>
</body>
</html>
  1. Index View

 @{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        <iframe src="@Url.Action("PrintTicket", "Generate", new {tempTickID = "1"})" 
                width="800px" height="600px">
        </iframe>
    </div>
</body>
</html>

Output