首页 > 其他分享 >wkhtmltopdf 目录对象使用 及 目录样式分享

wkhtmltopdf 目录对象使用 及 目录样式分享

时间:2023-01-12 17:44:06浏览次数:36  
标签:样式 wkhtmltopdf padding ul 使用 font 目录

最近又是更新了报告模板的样式新使用了目录对象 因为直接生成的目录样式比较丑所以这边使用的是自定义xsl

 

                                                    直接生成的目录样式

 

 

 

                  自定义样式

 

因为需求所以写了些特殊判断

<xsl:if test="">  只能单条件判断

多条件要使用

<xsl:when> 相当于if

<xsl:otherwise 判断语句> 相当于 else if

<xsl:otherwise> 相当于 else

test 里面可以使用函数 这边只使用到了 contains 包含  前面加 ! 不好使 只能使用上面的 判断语句实现效果

需要使用其他函数的 搜一下 xlst 函数

 

这里分享下使用到的代码。

 toc --xsl-style-sheet C:\Users\Administrator\Desktop\myself.xsl 

这句是 生成目录 使用 指定位置的样式

 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:outline="http://wkhtmltopdf.org/outline"
                xmlns="http://www.w3.org/1999/xhtml">
  <xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
              doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
              indent="yes" />
  <xsl:template match="outline:outline">
    <html>
      <head>
        <title>目录</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style>
          body{
            padding:2%
          }
          h1 {         
            color: #364063!important;
            margin: 2% 0%;
            padding:2% 0;
            font-size: 30px;
            font-family: calibri;
          }
          div {border-bottom: 1px dashed rgb(200,200,200);  padding:2% 0%;}
          span {float: right;}
          li {list-style: none; color: #364063;}
          ul {
            font-size: 30px;
            font-family: calibri;         
            color: #364063;
          }
          ul ul {font-size: 80%; }
          ul {padding-left: 0em;}
          ul ul {padding-left: 1em;}
          a {text-decoration:none; color: #364063;}
        
        </style>
      </head>
      <body>
        <h1 style="font-size:45px;">目录</h1>
        <ul><xsl:apply-templates select="outline:item/outline:item"/></ul>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="outline:item">
    <li>
        <xsl:if test="@title!='目录'">
      <xsl:if test="@title!=''">
          
        <div>
            <xsl:choose>
              <xsl:when test="contains(@title,' 异常')">
              <a style="color: #FF8B07!important;">
                <xsl:if test="@link">
                  <xsl:attribute name="href"><xsl:value-of select="@link"/></xsl:attribute>
                </xsl:if>
                <xsl:if test="@backLink">
                  <xsl:attribute name="name"><xsl:value-of select="@backLink"/></xsl:attribute>
                </xsl:if>
                <xsl:value-of select="@title" /> 
              </a>
              </xsl:when>
                  <xsl:otherwise>
                  <a>
                    <xsl:if test="@link">
                      <xsl:attribute name="href"><xsl:value-of select="@link"/></xsl:attribute>
                    </xsl:if>
                    <xsl:if test="@backLink">
                      <xsl:attribute name="name"><xsl:value-of select="@backLink"/></xsl:attribute>
                    </xsl:if>
                    <xsl:value-of select="@title" /> 
                  </a>
                  </xsl:otherwise>
                  </xsl:choose>
          <span> <xsl:value-of select="@page - 4" /> </span>
        </div>        
      </xsl:if>
          </xsl:if>
      <ul>
        <xsl:comment>added to prevent self-closing tags in QtXmlPatterns</xsl:comment>
        <xsl:apply-templates select="outline:item"/>
      </ul>
    </li>
  </xsl:template>
</xsl:stylesheet>

这是文件内容可以拷贝直接使用 再根据需求调整

 

分享结束 感谢 !!

因为要生成页码 所以底下能看到 目录 1 目录   没研究出怎么让目录不生成知道的大佬告知下 谢谢。

 

xsl中 page - 4 是因为 wkhtmltopdf 生成的页码是正常的  但是 目录里面的指向 多了 目录的页数 所以  page - 目录页数

 

 

2023-01-12 17:39:24

 

标签:样式,wkhtmltopdf,padding,ul,使用,font,目录
From: https://www.cnblogs.com/-ccj/p/17047365.html

相关文章

  • Styles 样式
    InlineStyles 内联样式<ButtonMargin="0,0,2,2"Grid.Row="0"Grid.Column="0"Name="cell00"><Button.Style><Style>......
  • jQuery的css(操作样式标签,找到元素位置 p15~p17 and p19)
    视频CSS<!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>11_css</title></head><body><pstyle="color:blue;">尚硅谷的后裔</p><pstyle="colo......
  • 如何为 mdbook pdf 生成书签目录
    以RustByExample.pdf为例,分享如何为mdbook打入书签目录。生成本地网页书籍,并保存为pdfgitclonehttps://github.com/rust-lang/rust-by-example把书籍仓库克......
  • 在h5和微信小程序中修改checkbox、radia的样式
    由于引用了colorUI导致checbox的样式修改无效,因为colorUI的原因导致checkbox.uni-checkbox-input::before不显示。colorUI的main.css:switch.wx-switch-input::before,......
  • 【快应用】按钮的圆角样式不生效
    ​ 现象描述在div里包含两个input,分别定义“取消”和“确定”两个按钮,但是“取消”按钮的圆角样式不生效。​ 问题分析分析如下两个按钮样式定义的代码,定义两个按......
  • Linux:文件与目录
    目录网络不通畅运维操作规范(运维⼈员==救⽕队员)具体操作:一、etc目录下重要的数据文件1./etc/fstab-filesystemtable系统挂载信息表2./etc/rc.local-此文件中只能存放......
  • Win11右键菜单回到Win10样式
    管理员运行命令reg.exeadd"HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"/f/ve设置为Win10样式。重启电脑,或执行taskkill......
  • css 样式 正三角,倒三角 小三角
    提示框、菜单栏的三角样式效果图精髓正三角.h{width:0;height:0;border:6pxsolidtransparent;border-......
  • thinkphp安装在子目录的nginx配置
    进行URL重写,将默认访问URL中的index.php?s=通过rewrite隐藏location/blog/{indexindex.phpindex.htmlindex.htm;if(!-e$request_filename){rewrite......
  • Echarts —自定义label标签的样式(formatter,rich,添加图标等操作)
    最近公司项目中在使用Echarts绘制图表时,由于默认的label标签不能满足设计稿需求,所以研究了对label标签进行格式化的方案,了解到可以使用formatter内容格式器对标签内......