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

引入类库:Rotativa.AspNetCore

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

添加如下代码:

RotativaConfiguration.Setup(env);

调用ViewAsPdf 方法

public IActionResult Index()

{
     return new ViewAsPdf("Index");

}

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

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>

最终效果图:

在ASP.NET CORE下生成PDF文档的更多相关文章

  1. 第二十节:Asp.Net Core WebApi生成在线文档

    一. 基本概念 1.背景 使用 Web API 时,了解其各种方法对开发人员来说可能是一项挑战. Swagger 也称为OpenAPI,解决了为 Web API 生成有用文档和帮助页的问题. 它具有诸 ...

  2. 使用PHP生成PDF文档

    原文:使用PHP生成PDF文档 实际工作中,我们要使用PHP动态的创建PDF文档,目前有许多开源的PHP创建PDF的类库,今天我给大家来介绍一款优秀的PDF库,它就是TCPDF,TCPDF是一个用于快 ...

  3. DocFX生成PDF文档

    使用DocFX生成PDF文档,将在线文档转换为PDF离线文档. 关于DocFX的简单介绍使用DocFX生成文档 使用docfx 命令 1.下载 https://github.com/dotnet/do ...

  4. Spring Boot集成JasperReports生成PDF文档

    由于工作需要,要实现后端根据模板动态填充数据生成PDF文档,通过技术选型,使用Ireport5.6来设计模板,结合JasperReports5.6工具库来调用渲染生成PDF文档.本人文采欠缺,写作能力 ...

  5. 手把手教你使用 Java 在线生成 pdf 文档

    一.介绍 在实际的业务开发的时候,研发人员往往会碰到很多这样的一些场景,需要提供相关的电子凭证信息给用户,例如网银/支付宝/微信购物支付的电子发票.订单的库存打印单.各种电子签署合同等等,以方便用户查 ...

  6. 利用Java动态生成 PDF 文档

    利用Java动态生成 PDF 文档,则需要开源的API.首先我们先想象需求,在企业应用中,客户会提出一些复杂的需求,比如会针对具体的业务,构建比较典型的具备文档性质的内容,一般会导出PDF进行存档.那 ...

  7. Aspose.Words操作word生成PDF文档

    Aspose.Words操作word生成PDF文档 using Aspose.Words; using System; using System.Collections.Generic; using ...

  8. 如何从Windows Phone 生成PDF文档

    我需要从我的Windows Phone应用程序生成PDF. 遗憾的是没有标准的免费的PDF生成库在Windows Phone上运行. 我不得不自己生成PDF,通过直接写入到文件格式. 这竟然是真的很容 ...

  9. qt 利用 HTML 生成PDF文档,不能显示jpg图片

    利用 QPrinter 和html 生成 pdf文档 其中用html语句有显示图片的语句 但只能显示png格式的图片,不能显示jpg格式图片. 经过排查:语法,文件路径等都正确,最终在stack ov ...

随机推荐

  1. xocodebulid 自动化打包 解决提示 ld: library not found for -lPods 问题

    如果你的项目用到cocopod 第三方库.使用xcodebulid 估计会出现 ld: library not found for -lPods 以下 是我的解决办法 xcodebuild -work ...

  2. oracle视图建主键

    一个项目要求视图建主键,以下是一个样例 CREATE or replace VIEW SME_V_A....  (AGENTID,AGENTNAME,BUSYNUM,RESTNUM,RESTTIME, ...

  3. x86-64整数寄存器

  4. fork failed.: Cannot allocate memory

    在做压力测试时候: [root@666 ok]# webbench -c 5000 -t30 http://10.100.0.61/ Webbench - Simple Web Benchmark 1 ...

  5. 在TypeScript中扩展JavaScript基础对象的功能

    最近工作中用到,记录一下:假设我们需要一个功能,把一个数字比如10000输出为下面的字符串格式“10,000”,一般是写一个方法,那么我希望更方便一点,直接向Number类型添加一个格式化方法,比如叫 ...

  6. 行为类模式(十):模板方法(Template Method)

    定义 定义一个操作中的算法的骨架,而将步骤延迟到子类中.模板方法使得子类可以不改变一个算法的结构即可重定义算法的某些特定步骤. UML 优点 模板方法模式通过把不变的行为搬移到超类,去除了子类中的重复 ...

  7. 每日英语:KFC's Crisis in China Tests Ingenuity of Man Who Built Brand

    Sam Su for years ran one of the highest-flying foreign business operations in China. These days, he' ...

  8. 每日英语:How to Save Detroit

    Detroit is beautiful-though you probably have to be a child of the industrial Midwest, like me, to s ...

  9. linux命令(35):diff命令

    diff 命令是 linux上非常重要的工具,用于比较文件的内容,特别是比较两个版本不同的文件以找到改动的地方.diff在命令行中打印每一个行的改动.最新版本的diff还支持二进制文件.diff程序的 ...

  10. 【DMQ引擎】-DMQ多进程插件引擎服务平台介绍

    写过服务端项目的程序员可能都有非常痛苦的经历,服务端经常奔溃,无从查起.的确一个服务端要稳定下来要经过长期的积累,不停的测试,调试,发现问题,解决问题.这个周期可能很长,几个月,甚至以年计算.许多企业 ...