在ASP.NET CORE下生成PDF文档


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

在ASP.NET CORE下生成PDF文档_第1张图片

引入类库:Rotativa.AspNetCore

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

添加如下代码:

RotativaConfiguration.Setup(env);

调用ViewAsPdf 方法

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

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

在ASP.NET CORE下生成PDF文档_第2张图片

view 内容

@{
     Layout = null;
}



    
     Index


    


        

Invoice


        

            

Jonathan Neal


            

101 E. Chapman Ave
Orange, CA 92866


            

(800) 555-1234


        

    

    

        

Recipient


        

            

Demo Company
c/o Saineshwar


        

        
            
                
                
            
            
                
                
            
            
                
                
            
        
Invoice #000001
DateJanuary 1, 2018
Amount Dueर 600.00

        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                    
                    
                    
                
            
        
ItemDescriptionRateQuantityPrice
-Front End ConsultationExperience Reviewर 150.004र 600.00

       


            

                

                

            

            

                

                

            

            

                

                

            

        
Totalर 600.00
Amount Paidर 0.00
Balance Dueर 600.00

    

   



最终效果图:

在ASP.NET CORE下生成PDF文档_第3张图片


转载于:https://www.cnblogs.com/mikechang/p/9148784.html

你可能感兴趣的:(在ASP.NET CORE下生成PDF文档)