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

奶茶网站建设方案模板免费留电话号码的广告

奶茶网站建设方案模板,免费留电话号码的广告,德州网站制作公司,中小型网站建设与管理 唐军民目录 使用 XSL-FO 生成电子发票 PDF:从布局设计到优化为什么选择 XSL-FO?1. 初始设置2. 标题区块3. 买卖方信息4. 商品明细表格5. 合计信息6. 优化代码结构与布局7. 生成 PDF 文件8. 示例总结 使用 XSL-FO 生成电子发票 PDF:从布局设计到优化…

目录

      • 使用 XSL-FO 生成电子发票 PDF:从布局设计到优化
        • 为什么选择 XSL-FO?
        • 1. 初始设置
        • 2. 标题区块
        • 3. 买卖方信息
        • 4. 商品明细表格
        • 5. 合计信息
        • 6. 优化代码结构与布局
        • 7. 生成 PDF 文件
        • 8. 示例
        • 总结

使用 XSL-FO 生成电子发票 PDF:从布局设计到优化

在电子商务和财务系统中,生成规范化的发票 PDF 文件是一个常见需求。利用 XSL-FO(Extensible Stylesheet Language Formatting Objects),我们可以设计和生成格式规范的发票 PDF。本文将介绍如何使用 XSL-FO 构建电子发票的 PDF 文件,并提供一些优化布局的建议,以实现更清晰美观的发票。

为什么选择 XSL-FO?

XSL-FO 是 W3C 的标准,用于将 XML 文档格式化为 PDF、PostScript 等格式的高质量输出文档。它尤其适合结构化数据的排版需求。结合 Apache FOP(Formatting Objects Processor)等工具,我们可以从 XML 模板生成发票 PDF。

1. 初始设置

首先,在根节点 <fo:root> 中设置页面布局:

<fo:layout-master-set><fo:simple-page-master master-name="invoice"><fo:region-body margin="5mm"/></fo:simple-page-master>
</fo:layout-master-set>

这里指定了页面的边距和布局,便于后续的内容排版。

2. 标题区块

发票的顶部通常包含发票标题、二维码、公司信息和发票号。可以通过 <fo:table> 元素来布局这些信息,利用列宽度来控制内容的对齐和分布:

<fo:table table-layout="fixed" width="100%"><fo:table-column column-width="22%"/><fo:table-column column-width="56%"/><fo:table-column column-width="22%"/>...
</fo:table>

在这个表格中,我们在左右两侧显示二维码和发票信息,中间展示发票标题。通过设置 column-width,可以确保不同元素之间的布局合理。

3. 买卖方信息

发票中买方和卖方的信息是关键内容。我们使用 <fo:table> 元素创建一个两列的表格来放置这些信息:

<fo:table-column column-width="5%"/>
<fo:table-column column-width="45%"/>

每个列块中包括公司名称、税号等信息,并使用 writing-mode="tb-rl" 为标签列设置垂直方向书写,从而增强布局的清晰度。

4. 商品明细表格

商品明细表格包含了商品的名称、规格、单位、数量、单价、金额、税率、税额等。可以通过固定列宽设置,确保不同商品数据的显示一致:

<fo:table-column column-width="20%"/>
...

对于每个商品的明细行,我们使用了 fo:table-body 标签,包含具体的内容。可以进一步通过 min-height="50pt" 设置行高度,确保无数据时也有足够的空间。

5. 合计信息

在表格的下方,使用一个新的表格展示“价税合计”信息,包括大小写金额:

<fo:table-body><fo:table-row><fo:table-cell text-align="center"><fo:block>价税合计(大写)</fo:block></fo:table-cell>...</fo:table-row>
</fo:table-body>

通过将列宽和内容对齐调整为居中,可以确保整体布局对齐美观。

6. 优化代码结构与布局

在发票生成过程中,统一样式设置和简化代码结构可以提高代码的可读性和可维护性,以下是几点优化建议:

  • 统一表格样式:将表格边框样式、颜色等属性集中设置,避免重复代码。
  • 简化内容布局:对于标签文本等内容,使用 writing-mode="tb-rl" 实现垂直对齐,避免复杂的布局调整。
  • 表格布局的合理分配:使用 table-layout="fixed" 和精确的 column-width 设置,确保表格布局稳定。
7. 生成 PDF 文件

在完成 XSL-FO 模板后,可以使用 Apache FOP 工具将其转换为 PDF 文件:

fop -xml invoice.xml -xsl invoice.xsl -pdf invoice.pdf

这样即可获得一份规范、清晰的电子发票 PDF 文件。

8. 示例
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"xmlns:xe="http://www.x-easypdf.cn/ns"xmlns:svg="http://www.w3.org/2000/svg"><fo:layout-master-set><fo:simple-page-master master-name="invoice"><fo:region-body margin="5mm"/></fo:simple-page-master></fo:layout-master-set><fo:page-sequence master-reference="invoice"><fo:flow flow-name="xsl-region-body" color="rgb(188, 119, 76)"><fo:block font-family="SimSun" space-before="10pt"><fo:table table-layout="fixed" width="100%"><fo:table-column column-width="22%"/><fo:table-column column-width="56%"/><fo:table-column column-width="22%"/><fo:table-body><fo:table-row><fo:table-cell><fo:block text-align="left"><!-- 二维码图片所在位置 --><fo:external-graphic src="image/qrcode.png" content-width="60pt" content-height="60pt"/></fo:block></fo:table-cell><fo:table-cell display-align="center"><fo:block text-align="center" font-family="SimSun" font-size="20pt">电子发票(增值税专用发票)</fo:block><fo:block text-align="center" font-family="SimSun" font-size="14pt">==========================</fo:block><fo:block text-align="center" space-before="-50pt"> <!-- 使用负值移动位置 --><!-- 章图片所在位置 --><fo:external-graphic src="image/seal.png" content-width="70pt" content-height="70pt"/></fo:block></fo:table-cell><fo:table-cell font-size="10pt" display-align="center" text-align="left"><fo:block>发票号码:123456789</fo:block><fo:block>开票日期:2024年01月01日</fo:block></fo:table-cell></fo:table-row></fo:table-body></fo:table></fo:block><!-- Buyer and Seller Information --><fo:block font-family="SimSun" font-size="10pt"><fo:table table-layout="fixed" width="100%" border-style="solid" border-width="0.5pt"><fo:table-column column-width="5%" border-style="solid" border-color="rgb(188, 119, 76)" /><fo:table-column column-width="45%" border-style="solid" border-color="rgb(188, 119, 76)" /><fo:table-column column-width="5%" border-style="solid" border-color="rgb(188, 119, 76)" /><fo:table-column column-width="45%" border-style="solid" border-color="rgb(188, 119, 76)" /><fo:table-body><fo:table-row><fo:table-cell padding="5pt" writing-mode="tb-rl"><fo:block>购买方信息</fo:block></fo:table-cell><fo:table-cell display-align="center"><fo:block>名称:</fo:block><fo:block>统一社会信用代码/纳税人识别号:</fo:block></fo:table-cell><fo:table-cell padding="5pt" writing-mode="tb-rl"><fo:block>销售方信息</fo:block></fo:table-cell><fo:table-cell display-align="center"><fo:block>名称:</fo:block><fo:block>统一社会信用代码/纳税人识别号:</fo:block></fo:table-cell></fo:table-row></fo:table-body></fo:table></fo:block><!-- Item Details Table --><fo:block font-family="SimSun" font-size="10pt"><fo:table table-layout="fixed" width="100%" border-style="solid" border-color="rgb(188, 119, 76)" border-width="0.5pt"><fo:table-column column-width="20%" border-left-style="solid" border-color="rgb(188, 119, 76)"/><fo:table-column column-width="10%" border-color="rgb(188, 119, 76)"/><fo:table-column column-width="10%" border-color="rgb(188, 119, 76)"/><fo:table-column column-width="10%" border-color="rgb(188, 119, 76)"/><fo:table-column column-width="15%" border-color="rgb(188, 119, 76)"/><fo:table-column column-width="10%" border-color="rgb(188, 119, 76)"/><fo:table-column column-width="15%" border-color="rgb(188, 119, 76)"/><fo:table-column column-width="10%" border-right-style="solid" border-color="rgb(188, 119, 76)"/><fo:table-header><fo:table-row><fo:table-cell text-align="center"><fo:block>项目名称</fo:block></fo:table-cell><fo:table-cell text-align="center"><fo:block>规格型号</fo:block></fo:table-cell><fo:table-cell text-align="center"><fo:block>单位</fo:block></fo:table-cell><fo:table-cell text-align="center"><fo:block>数量</fo:block></fo:table-cell><fo:table-cell text-align="center"><fo:block>单价</fo:block></fo:table-cell><fo:table-cell text-align="center"><fo:block>金额</fo:block></fo:table-cell><fo:table-cell text-align="center"><fo:block>税率/征收率</fo:block></fo:table-cell><fo:table-cell text-align="center"><fo:block>税额</fo:block></fo:table-cell></fo:table-row></fo:table-header><fo:table-body min-height="50pt"><fo:table-row><fo:table-cell text-align="center" padding-top="5pt"><fo:block>商品A</fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block>型号A</fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block></fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block>1</fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block>100.00</fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block>100.00</fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block>10%</fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block>10.00</fo:block></fo:table-cell></fo:table-row><fo:table-row><fo:table-cell text-align="center" padding-top="5pt"><fo:block>合   计</fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block></fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block></fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block></fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block></fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block>¥100.00</fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block></fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt"><fo:block>¥10.00</fo:block></fo:table-cell></fo:table-row></fo:table-body></fo:table></fo:block><!-- Summary Section --><fo:block font-family="SimSun" font-size="10pt"><fo:table table-layout="fixed" width="100%"  border-style="solid" border-width="0.5pt" border-color="rgb(188, 119, 76)"><fo:table-column column-width="25%" border-style="solid" border-color="rgb(188, 119, 76)"/><fo:table-column column-width="40%" border-top-style="solid" border-color="rgb(188, 119, 76)"/><fo:table-column column-width="10%" border-top-style="solid" border-color="rgb(188, 119, 76)"/><fo:table-column column-width="25%" border-top-style="solid" border-right-style="solid" border-color="rgb(188, 119, 76)"/><fo:table-body><fo:table-row><fo:table-cell text-align="center" padding-top="5pt" padding-bottom="5pt"><fo:block>价税合计(大写)</fo:block></fo:table-cell><fo:table-cell text-align="left" padding-top="5pt" padding-bottom="5pt"><fo:block>壹佰壹拾元整</fo:block></fo:table-cell><fo:table-cell text-align="center" padding-top="5pt" padding-bottom="5pt"><fo:block>(小写)</fo:block></fo:table-cell><fo:table-cell text-align="left" padding-top="5pt" padding-bottom="5pt"><fo:block>¥110.00</fo:block></fo:table-cell></fo:table-row></fo:table-body></fo:table></fo:block><!-- Footer Section --><fo:block font-family="SimSun" font-size="10pt" space-after="10pt" border-color="rgb(188, 119, 76)"><fo:table table-layout="fixed" width="100%" border-style="solid" border-width="0.5pt"><fo:table-column column-width="5%" border-style="solid" border-color="rgb(188, 119, 76)"/><fo:table-column column-width="95%" border-style="solid" border-color="rgb(188, 119, 76)"/><fo:table-body><fo:table-row><fo:table-cell padding="5pt" writing-mode="tb-rl"><fo:block>备注</fo:block></fo:table-cell></fo:table-row></fo:table-body></fo:table><fo:block>开票人:</fo:block></fo:block></fo:flow></fo:page-sequence>
</fo:root>
总结

XSL-FO 提供了一个强大的格式化模型,适合用来生成电子发票等结构化文档。通过灵活的表格布局和样式控制,可以实现专业的 PDF 输出。

http://www.jinmujx.cn/news/109291.html

相关文章:

  • 米拓网站建设-app定制开发什么是淘宝搜索关键词
  • 企业网站用视频做首页龙华百度快速排名
  • 优定软件网站建设痘痘如何去除效果好
  • 咖啡网站建设市场分析大批量刷关键词排名软件
  • 社会团建官网登录怎么做优化
  • wordpress4.9教学广州百度seo公司
  • 头像代做网站制作网站要找什么公司
  • 怎么样建立学校网站360收录提交入口
  • 益阳北京网站建设百度查重
  • 本地建站软件有哪些网店营销策划方案ppt
  • 做单平台网站制作谷歌关键词分析工具
  • 成都学校网站建设企业新产品怎样推广
  • 个人设计师网站 青春响应式网站模板的优势
  • 微网站和普通网站区别石家庄百度seo排名
  • 规模大的企业建站淘宝推广哪种方式最好
  • 网站怎么做前台跟后台的接口百度输入法下载
  • 英德网站seo网络推广方式
  • 做app要不要建网站北京网站制作建设公司
  • 社区网站制作教程最佳磁力引擎吧
  • 多媒体教学网站开发的一般步骤关键词优化方法
  • 网站突然消失了石家庄seo代理商
  • 武汉网站建设网站推广网络营销做得比较好的企业
  • 做1688网站到哪里找图片谷歌全球营销
  • 制作网站高手网站推广网络营销方案
  • 网站导航结构设计网络营销师课程
  • 昆明房产网站建设怎么做好推广和营销
  • 网吧网站怎么做微信如何引流推广精准加人
  • 公司企业文化内容跨境电商seo是什么意思
  • 网络推广员是干嘛的网站seo完整seo优化方案
  • 洛阳市政建设集团网站网站的排名优化怎么做