当前位置: 首页 > news >正文

你认为优酷该网站哪些地方可以做的更好_为什么?完整企业网站模板

你认为优酷该网站哪些地方可以做的更好_为什么?,完整企业网站模板,临海网站开发公司电话,网站 图片 自动往右移QuestPDFQuestPDF是一个开源的工具库#xff0c;可以在.NET或者.Net Core中生成pdf文档它提供了一个布局引擎#xff0c;设计时考虑到了完整的分页支持以及灵活性要求#xff01;比市面上常见的Aspose和iTextSharp好用太多了#xff01;GitHub地址安装Install-Package Ques… QuestPDFQuestPDF是一个开源的工具库可以在.NET或者.Net Core中生成pdf文档它提供了一个布局引擎设计时考虑到了完整的分页支持以及灵活性要求比市面上常见的Aspose和iTextSharp好用太多了GitHub地址安装Install-Package QuestPDF例子简单例子生成Pdf文档一共分为三部分Header(页眉)Content内容,Footer页脚Document.Create(container  {container.Page(page {page.Size(PageSizes.A4);page.Margin(2, Unit.Centimetre);page.Background(Colors.White);page.DefaultTextStyle(x  x.FontSize(20));page.Header().Text(Hello PDF!).SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);page.Content().PaddingVertical(1, Unit.Centimetre).Column(x {x.Spacing(20);x.Item().Text(Placeholders.LoremIpsum());x.Item().Image(Placeholders.Image(200, 100));});page.Footer().AlignCenter().Text(x {x.Span(Page );x.CurrentPageNumber();});}); }) .GeneratePdf(hello.pdf);模板生成使用模板生成一共设计三个应用层的工作:文档Model(一组描述 PDF 文档内容的类)数据源(将域实体映射到文档模型的层)模板(描述如何可视化信息并将其转换为 PDF 文件的表示层)比如我们设计一个基本的发票信息 要设计一个购物清单一个卖家买家的地址以及发票编号等等 我们设计这样的3个Model类public class InvoiceModel{public int InvoiceNumber { get; set; }public DateTime IssueDate { get; set; }public DateTime DueDate { get; set; }public Address SellerAddress { get; set; }public Address CustomerAddress { get; set; }public ListOrderItem Items { get; set; }public string Comments { get; set; }}public class OrderItem{public string Name { get; set; }public decimal Price { get; set; }public int Quantity { get; set; }}public class Address{public string CompanyName { get; set; }public string Street { get; set; }public string City { get; set; }public string State { get; set; }public object Email { get; set; }public string Phone { get; set; }}Model定义好了之后我们就定义一些假数据来填充pdfpublic static class InvoiceDocumentDataSource{private static Random Random  new Random();public static InvoiceModel GetInvoiceDetails(){var items  Enumerable.Range(1, 8).Select(i  GenerateRandomOrderItem()).ToList();return new InvoiceModel{InvoiceNumber  Random.Next(1_000, 10_000),IssueDate  DateTime.Now,DueDate  DateTime.Now  TimeSpan.FromDays(14),SellerAddress  GenerateRandomAddress(),CustomerAddress  GenerateRandomAddress(),Items  items,Comments 测试备注};}private static OrderItem GenerateRandomOrderItem(){return new OrderItem{Name  商品,Price  (decimal)Math.Round(Random.NextDouble() * 100, 2),Quantity  Random.Next(1, 10)};}private static Address GenerateRandomAddress(){return new Address{CompanyName  测试商店,Street  测试街道,City  测试城市,State  测试状态,Email  测试邮件,Phone  测试电话};}}然后搭建我们的模板脚手架 我们要使用模板脚手架,就要定义一个实现IDocument接口的新类开始。该接口包含两个方法DocumentMetadata GetMetadata();void Compose(IDocumentContainer container);第一个是模板文档的一些基础信息 第二个是模板的容器 基于这些原则我们设计一个模板层类public class InvoiceDocument : IDocument{public InvoiceModel Model { get; }public InvoiceDocument(InvoiceModel model){Model  model;}public DocumentMetadata GetMetadata()  DocumentMetadata.Default;public void Compose(IDocumentContainer container){container.Page(page {page.PageColor(Colors.Red.Lighten1);page.Size(PageSizes.A4);page.Margin(10);//外边距page.Header().Height(100).Background(Colors.LightBlue.Lighten1);page.Content().Background(Colors.Grey.Lighten3);page.Footer().Height(50).Background(Colors.Grey.Lighten1);});} }pdf的page页面总是有三个元素:页眉,页脚内容。查看一下我们生成的文档到目前为止我们已经搭建了一个非常简单的页面其中每个部分都有不同的颜色或大小接下来我们来填充他的页眉,我们把数据源整理好了之后就可以调用Element方法填充public void Compose(IDocumentContainer container){container.Page(page {page.PageColor(Colors.Red.Lighten1);page.Size(PageSizes.A4);page.Margin(10);//外边距page.Header().Height(100).Background(Colors.LightBlue.Lighten1).Element(ComposeHeader);page.Content().Background(Colors.Grey.Lighten3);page.Footer().Height(50).Background(Colors.Grey.Lighten1);});}void ComposeHeader(IContainer container){var titleStyle  TextStyle.Default.FontSize(20).SemiBold().FontColor(Colors.Blue.Medium);container.Row(row {row.RelativeItem().Column(column {column.Item().Text($发票 #{Model.InvoiceNumber}).FontFamily(simhei).Style(titleStyle);column.Item().Text(text {text.Span(发行日期: ).SemiBold().FontFamily(simhei);text.Span(${Model.IssueDate:d}).FontFamily(simhei);});column.Item().Text(text {text.Span(支付日期: ).FontFamily(simhei).SemiBold();text.Span(${Model.DueDate:d}).FontFamily(simhei);});});});}最后我们来实现内容public void Compose(IDocumentContainer container){container.Page(page {page.PageColor(Colors.Red.Lighten1);page.Size(PageSizes.A4);page.Margin(10);//外边距page.Header().Height(100).Background(Colors.LightBlue.Lighten1).Element(ComposeHeader);page.Content().Background(Colors.Grey.Lighten3).Element(ComposeContent);page.Footer().Height(50).Background(Colors.Grey.Lighten1);});}void ComposeHeader(IContainer container){var titleStyle  TextStyle.Default.FontSize(20).SemiBold().FontColor(Colors.Blue.Medium);container.Row(row {row.RelativeItem().Column(column {column.Item().Text($发票 #{Model.InvoiceNumber}).FontFamily(simhei).Style(titleStyle);column.Item().Text(text {text.Span(发行日期: ).SemiBold().FontFamily(simhei);text.Span(${Model.IssueDate:d}).FontFamily(simhei);});column.Item().Text(text {text.Span(支付日期: ).FontFamily(simhei).SemiBold();text.Span(${Model.DueDate:d}).FontFamily(simhei);});});});}void ComposeContent(IContainer container){container.Table(table {// step 1table.ColumnsDefinition(columns {columns.ConstantColumn(25);columns.RelativeColumn(3);columns.RelativeColumn();columns.RelativeColumn();columns.RelativeColumn();});// step 2table.Header(header {header.Cell().Text(#).FontFamily(simhei);header.Cell().Text(商品).FontFamily(simhei);header.Cell().AlignRight().Text(价格).FontFamily(simhei);header.Cell().AlignRight().Text(数量).FontFamily(simhei);header.Cell().AlignRight().Text(总价).FontFamily(simhei);header.Cell().ColumnSpan(5).PaddingVertical(5).BorderBottom(1).BorderColor(Colors.Black);});// step 3foreach (var item in Model.Items){table.Cell().Element(CellStyle).Text(Model.Items.IndexOf(item)  1).FontFamily(simhei);table.Cell().Element(CellStyle).Text(item.Name).FontFamily(simhei);table.Cell().Element(CellStyle).AlignRight().Text(${item.Price}$).FontFamily(simhei);table.Cell().Element(CellStyle).AlignRight().Text(item.Quantity).FontFamily(simhei);table.Cell().Element(CellStyle).AlignRight().Text(${item.Price * item.Quantity}$).FontFamily(simhei);static IContainer CellStyle(IContainer container){return container.BorderBottom(1).BorderColor(Colors.Grey.Lighten2).PaddingVertical(5);}}});}在这些准备工作做完了之后我们就可以生成Pdf文档了var filePath  invoice.pdf;var model  InvoiceDocumentDataSource.GetInvoiceDetails();var document  new InvoiceDocument(model);document.GeneratePdf(filePath);当然还有很多好玩的功能今天就给大家讲个概念让大家对这个东西有个印象后面我会继续输出该库的相关功能。如果你们对该库感兴趣可以持续关注我微信公众号【黑哥聊dotNet】
http://www.yutouwan.com/news/136072/

相关文章:

  • 网站开发合同受托方深圳外贸是做什么的
  • 网站模板生成凡客衬衫官方网站
  • 成都优化网站关键词网站建设实训致谢语
  • 做网站用html还是python好wordpress 微信h5
  • 宋家庄网站建设网站开发设计心得
  • 烟台网站建设工作登录百度
  • 郑州做网站公网站建设做的快
  • 新闻标题做的好的网站小公司企业简介怎么写
  • 下载站推广服务器与网站吗
  • 学网站开发应该学什么wordpress 自定义面板
  • 合肥专业网站排名推广网站企业优化
  • 什么是网站后台建设wnmp搭建后怎么做网站
  • 设计网站pc版wordpress中文字体库
  • 商城网站类建设哪家好网站开发浏览器分辨率
  • 福田做商城网站建设哪家便宜推广普通话手抄报句子
  • 网站建设容易出现的问题自媒体app下载
  • 上海网站排名提升今天国际新闻最新消息
  • 做足球直播网站企业信息系统开发
  • 包头北京网站建设wordpress get_search_form()
  • 做app网站公司个人网站开发盈利模式
  • 北京网站设计外包公司优钙网logo设计
  • 做推广的网站微信号做简历做得好的网站
  • wordpress 设h1seo优化技术厂家
  • php协会网站源码长春做网站 长春万网
  • 彩票网站源码下载网页设计制作公司推荐
  • 我帮你建站三维家装设计软件
  • 网站开发ide php南宁企业建站程序
  • 网站建设还有需求么群辉可以做网站服务器吗
  • 海口公司网站建设做设计什么兼职网站建设
  • 怎么注册自己的微网站天津建设网站需要的费用