TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Convert View into the PDF in MVC
Mukesh Kumar
Oct 24
2015
Code
3.7
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
public
ActionResult ConvertAboutPageToPdf()
{
// get the About view HTML code
string
htmlToConvert = RenderViewAsString(
"About"
,
null
);
// the base URL to resolve relative images and css
String thisPageUrl =
this
.ControllerContext.HttpContext.Request.Url.AbsoluteUri;
String baseUrl = thisPageUrl.Substring(0, thisPageUrl.Length -
"Home/ConvertAboutPageToPdf"
.Length);
// instantiate the HiQPdf HTML to PDF converter
HtmlToPdf htmlToPdfConverter =
new
HtmlToPdf();
// render the HTML code as PDF in memory
byte
[] pdfBuffer = htmlToPdfConverter.ConvertHtmlToMemory(htmlToConvert, baseUrl);
// send the PDF file to browser
FileResult fileResult =
new
FileContentResult(pdfBuffer,
"application/pdf"
);
fileResult.FileDownloadName =
"AboutMvcViewToPdf.pdf"
;
return
fileResult;
}
mvc
Convert View into the PDF
C#