How do I get PDF content generated by Rotativa?

4

I'm using Rotativa for PDF generation from a .cshtml I can download the file through the application correctly using the command below:

DadosConvite convidado = new DadosConvite(); 
convidado.nome = "teste";
return new Rotativa.ViewAsPdf("ConvitePDF", convidado) { FileName = "Convite.pdf"};

But I need to send this PDF by email, instead of just making it available to the user.

How can I get the content (byte []) of this PDF to be attached to the email?

    
asked by anonymous 24.11.2014 / 14:18

1 answer

5

ViewAsPdf has one more parameter called SaveOnServerPath , where you pass the path to be saved to disk:

var myPDF = new ViewAsPdf("ConvitePDF")
{
    FileName = "Convite.pdf",
    PageSize = Size.A4,
    SaveOnServerPath = caminho // preecha caminho com o diretório a ser salvo
};

// Reabra o arquivo aqui e envie como e-mail

return View("Index"); // Use o redirect normal e retorne para alguma View.

Or, better yet, you use the BuildPdf method and retrieve an array of bytes:

var pdfResult = new ActionAsPdf("ActionParaFazerOConvite", new { name = "Convite" }) 
                                                 { FileName = "Convite.pdf" };

var arrayDeBytes = pdfResult.BuildPdf(this.ControllerContext);
    
24.11.2014 / 18:53