2

I'm looking for a way to take a view in my MVC site and save it to a PDF and save it locally on disk. I have found a lot of answers that are similar to what I'm asking, but none of them actually answer it. How can I do this?

1

3 Answers 3

2

I've used WkHtmlToPdf before with good success.

It's a command line tool that you can install on your server.

Sign up to request clarification or add additional context in comments.

6 Comments

does it save with all the css styles applied? and hide the elements that are hidden on print?
Yes. It renders the URL you give it and then generates a PDF based on what is rendered. Same as if you had a PDF Print driver installed and printed it locally to a pdf that way from the web browser...except this sits on your server.
do they have a nuget package? or i need to install something in my pc?
I found Codaxy.WkHtmlToPdf on nuget, but the Codazy prefix throws me off, don't know if it's a port or from the WkHtmlToPdf folks.
i tried Rotativa problem is that i don't see an option to save it on disk
|
1

I have used Rotativa, it worked great
Rotativa
The implementation is quite simple ,very few lines of code.
For example you would need just these lines to render view as a pdf

public ActionResult PrintInvoice(int invoiceId)
{
  return new ActionAsPdf(
                 "Invoice", 
                 new { invoiceId= invoiceId }) 
                 { FileName = "Invoice.pdf" };
}

For more info
Code Project

Comments

0

I've used the Aspose.pdf library (not free) for this in the past.

I believe this blog post here gives a very in-depth explanation of how to do it.

http://daveaglick.com/posts/using-aspnet-mvc-and-razor-to-generate-pdf-files

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.