1

I have tried to make Pdf from razor views.But it always error me. I have used Visual studio 2013, .net framework 4.5 & asp.net mvc5.

For creating i have used to install RazorPdf version 1.0.0.0 package & itextsharp 5.5.2.0 version.

Code snapshot----------

    //controller code
    public PdfResult Pdf()
    {
        return new PdfResult();
    }

    //razor view

   @{
   Layout = null;
    }

<itext creationdate="@DateTime.Now.ToString()" producer="RazorPDF">
<table width="100%" cellpadding="0.5" cellspacing="0.5"   widths="30;70"    borderwidth="1.0" left="false" right="false" top="false"  bottom="false" red="0" green="0" blue="0">
    <row>
        <cell>
            <chunk style="font-weight:bold;">Today:</chunk>
        </cell>
        <cell>
            <chunk style="">@DateTime.Now.ToString("MM/dd/yyyy")</chunk>
        </cell>
    </row>
    <row>
        <cell>
            <chunk style="font-weight:bold;">Yesterday:</chunk>
        </cell>
        <cell>
            <chunk style="">@DateTime.Now.AddDays(-1).ToString("MM/dd/yyyy")</chunk>
        </cell>
    </row>
</table>

----------------------Error Details---------------

Could not load type 'iTextSharp.text.html.HtmlParser' from assembly 'itextsharp, Version=5.5.2.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca'

1 Answer 1

1
  1. Firstly remove the tag itext above your table.
  2. Then create new layout in shared folder.
  3. In that layout just copy and paste below code
<itext creationdate="@DateTime.Now.ToString()" producer="RazorPDF">
    @RenderBody()
</itext>
  1. Then set Layout = "~/Views/Shared/NewlyCreatedLayout.cshtml";

    Hope this will help.

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

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.