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

大连品牌官网建站html5网站管理系统

大连品牌官网建站,html5网站管理系统,wordpress中文免费企业模板下载,上海建设门户网站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.pierceye.com/news/992023/

相关文章:

  • 模仿网站建设大学生网站设计论文范文
  • 浙江杭州网站建设服务公司哪家好社区推广经验做法
  • 牟平网站制作公司天安云谷网站建设
  • 培训网站建设方案书沈阳定制网站方案
  • 廊坊公司快速建站电子商务网站建设前期规划方案
  • 西安网站建设盈科wordpress 评论模板
  • 网站制作的电话潍坊建立企业网站公司
  • 二级建造师证书查询官方网站21年没封直接可以进的
  • 计科专业毕设做网站傻瓜式做网站程序
  • 创办网站需要怎么做网站的建设方法包括
  • 直邮网站的推广活动怎么做电商美工是做什么的
  • 唐山建设局网站俄罗斯ip地址
  • 贵州省建设厅网站首页旅游seo
  • 郑州网站建设三猫网络新主题 老版本 wordpress
  • 网站 ftp网站首页布局有哪些
  • 3d模型代做网站微分销商城
  • 县区网站建设运行汇报宝塔 wordpress优化
  • 手机网站判断跳转代码怎么写pc网站怎么做自适应
  • 怎样在一个虚拟服务器里做两个网站西安市城乡建设管理局网站
  • 做网站实训总结查看网站建设的特点
  • 淘宝客网站如何让做量化交易网站开发
  • 青岛市城市建设管理局网站网络营销师培训费用是多少
  • 南昌建站模板深圳全网推广效果如何
  • 做网站的好公司wordpress大前端模板下载
  • 建设网站的申请信用卡吗下载百度免费
  • 徐州企业网站设计做瑜伽网站
  • 网站开发就是ssh吗.net 网站开发书籍
  • 网站名称没有排名上海工商网查询企业章程
  • 网站建设方案报价费用明细价格免费开店的电商平台
  • 济南网络建站模板用c 做的网站怎么打开