• 在ASP.NET CORE下生成PDF文档



    原文链接:https://www.c-sharpcorner.com/article/creating-pdf-in-asp-net-core-mvc-using-rotativa-aspnetcore/

    1528265575(1)

    引入类库:Rotativa.AspNetCore

    修改类Startup的方法Configure(IApplicationBuilder app, IHostingEnvironment env)

    添加如下代码:

    RotativaConfiguration.Setup(env);

    调用ViewAsPdf 方法

    public IActionResult Index()
    {
         return new ViewAsPdf("Index");
    }

    zai www文件夹中添加必要的文件:

    1528265872(1)

    view 内容

    @{
         Layout = null;
    }

    <!DOCTYPE html>

    <html>
    <head>
         <meta name="viewport" content="width=device-width" />
         <title>Index</title>
    </head>
    <body>
         <header>
             <h1>Invoice</h1>
             <address contenteditable>
                 <p>Jonathan Neal</p>
                 <p>101 E. Chapman Ave<br>Orange, CA 92866</p>
                 <p>(800) 555-1234</p>
             </address>
         </header>
         <article>
             <h1>Recipient</h1>
             <address contenteditable>
                 <p>Demo Company<br>c/o Saineshwar</p>
             </address>
             <table class="meta">
                 <tr>
                     <th><span contenteditable>Invoice #</span></th>
                     <td><span contenteditable>000001</span></td>
                 </tr>
                 <tr>
                     <th><span contenteditable>Date</span></th>
                     <td><span contenteditable>January 1, 2018</span></td>
                 </tr>
                 <tr>
                     <th><span contenteditable>Amount Due</span></th>
                     <td><span id="prefix" contenteditable>र </span><span>600.00</span></td>
                 </tr>
             </table>
             <table class="inventory">
                 <thead>
                     <tr>
                         <th><span contenteditable>Item</span></th>
                         <th><span contenteditable>Description</span></th>
                         <th><span contenteditable>Rate</span></th>
                         <th><span contenteditable>Quantity</span></th>
                         <th><span contenteditable>Price</span></th>
                     </tr>
                 </thead>
                 <tbody>
                     <tr>
                         <td><a class="cut">-</a><span contenteditable>Front End Consultation</span></td>
                         <td><span contenteditable>Experience Review</span></td>
                         <td><span data-prefix>र </span><span contenteditable>150.00</span></td>
                         <td><span contenteditable>4</span></td>
                         <td><span data-prefix>र </span><span>600.00</span></td>
                     </tr>
                 </tbody>
             </table>

            <table class="balance">
                 <tr>
                     <th><span contenteditable>Total</span></th>
                     <td><span data-prefix>र </span><span>600.00</span></td>
                 </tr>
                 <tr>
                     <th><span contenteditable>Amount Paid</span></th>
                     <td><span data-prefix>र </span><span contenteditable>0.00</span></td>
                 </tr>
                 <tr>
                     <th><span contenteditable>Balance Due</span></th>
                     <td><span data-prefix>र </span><span>600.00</span></td>
                 </tr>
             </table>
         </article>

        <aside>
             <h1><span contenteditable>Additional Notes</span></h1>
             <div contenteditable>
                 <p>A finance charge of 1.5% will be made on unpaid balances after 30 days.</p>
             </div>
         </aside>
    </body>
    </html>

    最终效果图:

    1528331432(1)


  • 相关阅读:
    21Gorm关联关系.md
    18项目的关闭与重启.md
    15最兼容标准库的日志库logrus.md
    接口性能指标QPSTPS并发量
    19Gorm入门.md
    20Gorm增删查改.md
    17配置管理神器Viper.md
    ssh长时间连接不上
    mount.nfs: Failed to resolve server XXX.isilon.com: System error
    zabbix_agentd [5878]: cannot create PID file [/var/run/zabbix/zabbix_agentd.pid]: [13] Permission denied
  • 原文地址:https://www.cnblogs.com/mikechang/p/9148784.html
Copyright © 2020-2023  润新知