How to obtain PDF content generated by Rotary?

Asked

Viewed 1,682 times

4

I am using Rotary 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"};

However I need to send this PDF by email, instead of only making the download available to the user.

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

1 answer

6


ViewAsPdf has one more parameter called SaveOnServerPath, in which you pass the way to be saved on 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 method BuildPdf and recovers an array of bytes:

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

var arrayDeBytes = pdfResult.BuildPdf(this.ControllerContext);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.