2017-12-31 140 views
1

Ich verwende Rotativa, um ein PDF einer Ansicht mit der Absicht zu erstellen, es zu drucken.Open Rotativa Druckdialog automatisch

Ich habe den folgenden Code

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 mir die „PrepareTicket“ Ansicht als pdf öffnen können und dann kann ich drucken.

Problem

Das Problem für mich ist, nimmt die pdf meine ganze Seite über und während ich ich habe keinen Zugriff auf Menüs drucken kann mein Programm ist mehr denn es ist jetzt eine PDF-Ansicht ist.

Fragen

Ist es möglich, dass ich den Druckdialog automatisch statt, welche die pdf nennen?

Ich denke, wird für meine Situation funktionieren.

Grüße

Antwort

0

Hallo, ich habe versucht, eine Probe zu schaffen, das Ihr Problem lösen wird.

  1. Modell
public class Ticketinfo 
{ 
    public string name { get; set; } 
    public int quantity { get; set; } 
} 
  1. ein Controller erstellt, die hat 3 Action-Methode
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. Teilansicht
@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. Übersicht

@{ 
 
    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>

Ausgabe

Output