Welcome Guest Search | Active Topics | Sign In | Register

Get the RenderAsPdf of a View into a variable Options
Ramon
Posted: Friday, December 13, 2013 5:52:02 AM
Rank: Member
Groups: Member

Joined: 2/17/2013
Posts: 14
LS,

I'm trying to get the RenderAsPDF result in a variable or other way so I can attach this PDF to an email

pseudo code example:
Code: C#
public ActionResult Confirmed()
{
     var model = getModelData();
     var pdfFile = RenderAsPdfResult(DetailsOfConfirmationView);
     mailToClient(pdfFile);
     return View(model);
}

[RenderAsPDF]
public ActionResult DetailsOfConfirmationView()
{
     var model = getDetailsData();
     return View(model);
}
eo_support
Posted: Friday, December 13, 2013 9:54:06 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

In that case you don't need to use RenderAsPDF attribute. What you will need to do is to render the View into a string, then call HtmlToPdf.ConvertHtml to convert that HTML string into PDF. You will also need to set HtmlToPdf.Options.BaseUrl correctly in order for the converter to correctly resolve relative path (of images, style files, script, etc).

Thanks!
Ramon
Posted: Saturday, December 14, 2013 5:21:55 AM
Rank: Member
Groups: Member

Joined: 2/17/2013
Posts: 14
That works like a charm!!!

Thanks once again for the quick reply!
eo_support
Posted: Saturday, December 14, 2013 9:34:52 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
You are welcome! Please feel free to let us know if there is anything else.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.