Search code examples
c#asp.net-mvcrazorpdf

Create pdf with RazorPDF


I want to create a simple pdf with RazorPDF.

I installed it from Nuget Package. (itexsharp and razorpdf appear in reference)

Here's my controller:

public ActionResult Index()
{
    return new RazorPDF.PdfResult();
}

And, I have a simple view that shows "hello".

When I use return view(), everything is ok and "hello" is displayed, but when I use return new RazorPDF.PdfResult();, the following error occurs:

The view 'Pdf' or its master was not found or no view engine supports the searched locations. The following locations were searched: view/home/pdf.aspx


Solution

  • Actually you have to create your own separate masterpage for the PDF view. Just add one partial view masterpage in shared folder and in that page just copy paste below code.

        <itext creationdate="@DateTime.Now.ToString()" producer="RazorPDF">
              @RenderBody()
        </itext>