原文链接:
引入类库: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>
最终效果图: