zoukankan      html  css  js  c++  java
  • 在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)


  • 相关阅读:
    java基础3 循环语句:While 循环语句、do while 循环语句、 for 循环语句 和 break、continue关键字
    java基础2 判断语句:if ... else 语句和 switch 语句
    IT行业经典面试技巧及方法思路。
    Java基础1,入门基础知识
    SVN的使用、分支合并及解决冲突详解
    VC工程产生文件后缀名解释
    ireport报表,打印时,报表加载失败的解决方法
    MySQL 事务、视图、索引
    MySQL高级查询
    MySQL中的主键约束和外键约束
  • 原文地址:https://www.cnblogs.com/mikechang/p/9148784.html
Copyright © 2011-2022 走看看