Create and Save PDF using Rotativa in MVC Application

<div style=”text-align:right;padding-top:20px!important;”>@Html.ActionLink(“Print About Page”,”PrintAboutPage”)</div><div><h2>@ViewBag.Title.</h2><h3>@ViewBag.Message</h3><p>Use this area to provide additional information.</p></div>
public ActionResult About(){ViewBag.Message = “Your application description page.”;return View();}public ActionResult PrintAboutPage(){var report = new Rotativa.ActionAsPdf(“About”);return report;}
<div style=”text-align:right;padding-top:20px!important;”>@Html.ActionLink(“Print Contact Page”, “PrintContactPage”)</div><div><h2>@ViewBag.Title.</h2><h3>@ViewBag.Message</h3></div>
public ActionResult PrintContactPage(){var report = new Rotativa.ActionAsPdf(“Contact”, new { name = “Vaibhav” });return report;}
<div style=”text-align:right;padding-top:20px!important;”>@Html.ActionLink(“Print About Page”,”PrintAboutPage”)</div><div style=”text-align:right;padding-top:20px!important;”>@Html.ActionLink(“Save About Page”, “SaveAboutPage”)</div><div><h2>@ViewBag.Title.</h2><h3>@ViewBag.Message</h3><p>Use this area to provide additional information.</p></div>
public ActionResult SaveAboutPage(){string fileName = “Test.pdf”;string fullPath = @”C:\Users\Vaibhav\Documents\RotativaPdf\” + fileName;var report = new Rotativa.ActionAsPdf(“About”){PageOrientation = Rotativa.Options.Orientation.Portrait,PageSize = Rotativa.Options.Size.A4,PageMargins = new Margins(0, 0, 0, 0),};if (!System.IO.File.Exists(fullPath)){var byteArray = report.BuildPdf(ControllerContext);var fileStream = new FileStream(fullPath, FileMode.Create, FileAccess.Write);fileStream.Write(byteArray, 0, byteArray.Length);fileStream.Close();}return report;}

--

--

--

Technical Speaker | Computer Engineer | Full Stack Web Developer | ML Enthusiast | * Knowledge Shared = Knowledge² *

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Legacy Migration to Microservices

Three Pillars You Should Master When you Define your Enterprise Integration on the Cloud.

How to add tags in Django

EveryDay code #4

POSIX Alternatives for Readlink

2020 Year in Review: Growth in a Difficult Time

From Zero to Motoko

Install Laravel on Ubuntu 18.04 with Apache, MySQL, PHP7 (LAMP) stack

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vaibhav Bhapkar

Vaibhav Bhapkar

Technical Speaker | Computer Engineer | Full Stack Web Developer | ML Enthusiast | * Knowledge Shared = Knowledge² *

More from Medium

How to Build Windows Desktop Barcode and QR Code Scanner in .NET 6

Convert Excel XLSX Files to XML Files in C#

Using Exception.Data property to log user-defined information about exceptions

Zack.DotNetTrimmer, a .NET Core tailor, has updated the engine and supported recording and playback