2014-10-28 23 views
5

Sto usando Rotativa per generare PDF nella mia applicazione "MVC". Come posso salvare Rotativa PDF? Ho bisogno di salvare il documento su un server dopo che tutto il processo è completato.Come salvare Rotativa PDF sul server

codice qui sotto:

public ActionResult PRVRequestPdf(string refnum,string emid) 
{ 
    var prv = functions.getprvrequest(refnum, emid);    
    return View(prv); 

} 
public ActionResult PDFPRVRequest() 
{ 
    var prv = Session["PRV"] as PRVRequestModel; 
    byte[] pdfByteArray = Rotativa.WkhtmltopdfDriver.ConvertHtml("Rotativa", "Approver", "PRVRequestPdf"); 
    return new Rotativa.ViewAsPdf("PRVRequestPdf", new { refnum = prv.rheader.request.Referenceno });    

} 

risposta

12

È possibile dare una prova

var actionResult = new ActionAsPdf("PRVRequestPdf", new { refnum = prv.rheader.request.Referenceno, emid = "Whatever this is" }); 
var byteArray = actionResult.BuildPdf(ControllerContext); 
var fileStream = new FileStream(fullPath, FileMode.Create, FileAccess.Write); 
fileStream.Write(byteArray, 0, byteArray.Length); 
fileStream.Close(); 

Se questo non fa il trucco, allora, è possibile seguire le risposte here

Basta fare in modo se lo fai in questo modo non avere PRVRequestPdf restituire come una vista PDF, piuttosto una normale vista come hai sopra (solo menzione come riuscito a cadere fallo di quello stesso causando un sacco di divertimento).

2

Un'altra risposta utile:

ho trovato la soluzione here

  var actionPDF = new Rotativa.ActionAsPdf("YOUR_ACTION_Method", new { id = ID, lang = strLang } //some route values) 
      { 
       //FileName = "TestView.pdf", 
       PageSize = Size.A4, 
       PageOrientation = Rotativa.Options.Orientation.Landscape, 
       PageMargins = { Left = 1, Right = 1 } 
      }; 
      byte[] applicationPDFData = actionPDF.BuildPdf(ControllerContext); 

Questo è l'originale thread

+0

Questa soluzione utilizza la risposta di Daniel troppo. – meJustAndrew

Problemi correlati