1

我试图从剃刀意见中制作 Pdf。但它总是让我出错。我使用过 Visual Studio 2013、.net 框架 4.5 和 asp.net mvc5。

为了创建,我曾经安装过 RazorPdf 版本 1.0.0.0 包和 itextsharp 5.5.2.0 版本。

代码快照----------

    //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>

- - - - - - - - - - - 错误详情 - - - - - - - -

无法从程序集“itextsharp,版本=5.5.2.0,文化=中性,PublicKeyToken=8354ae6d2174ddca”加载类型“iTextSharp.text.html.HtmlParser”

4

1 回答 1

1
  1. 首先删除表格上方的标签 itext。
  2. 然后在共享文件夹中创建新布局。
  3. 在该布局中,只需复制并粘贴以下代码
<itext creationdate="@DateTime.Now.ToString()" producer="RazorPDF">
    @RenderBody()
</itext>
  1. 然后设置Layout = "~/Views/Shared/NewlyCreatedLayout.cshtml";

    希望这会有所帮助。

于 2016-02-11T06:58:49.793 回答