当前位置: 首页 > 工具软件 > DocBook XSL > 使用案例 >

docbook在Windows下的安装与使用

罗毅
2023-12-01

步骤1.

下载docbook-xsl-1.79.1

步骤2.

下载xsltproc

步骤3.

下载手册指南defguide5-zh-fop.pdf

步骤4.

下载docbook-5.0b5

以上服务下载网盘地址:

链接:https://pan.baidu.com/s/1INH0HTQn-WSHPbOtA-sy2A 
提取码:6a9d

步骤5.

Windows环境下新增配置path环境变量,自己的目录\xsltproc\bin

步骤6.

重新启动服务器

步骤7.

Windows环境下cmd进入,执行xsltproc -version命令,如果出现版本号表示安装成功。

步骤8.

测试将xml文件转为html:

找到步骤4中下载好的文件夹docbook-5.0b5中的docs中的xml文件

cmd进入Windows命令行,然后命令行进入该目录下

执行以下命令,将xml文件转为html

xsltproc --output myfile.html D:\SoftwareWork\docbook\docbook-xsl-1.79.1\html\docbook.xsl howto.xml

说明:D:\SoftwareWork\docbook\docbook-xsl-1.79.1\html\docbook.xsl 该目录为下载好的docbook-xsl-1.79.1中的html\docbook.xsl 目录。

执行成功后可以在当前目录下看到新生成的html文件。

后续的文档可以此howto.xml为模板进行编写。

步骤9:

测试将xml文件转为pdf文件:

1.下载fop-2.6-bin压缩文件

2.进入fop.bat所在的目录,或者可以将fop.bat所在的目录加入到path环境变量中

3.在fop.bat所在的目录新建fop.xml文件,设置字体配置,文件内容如下:

<?xml version="1.0"?>

<!-- $Id: fop.xml 901793 2012-12-21 bin.yin $ -->

<!-- NOTE: This is the version of the configuration -->

<fop version="1.0">

<!-- Base URL for resolving relative URLs -->

<base>.</base>

<!-- Source resolution in dpi (dots/pixels per inch) for determining the size of pixels in SVG and bitmap images, default: 72dpi -->

<source-resolution>72</source-resolution>

<!-- Target resolution in dpi (dots/pixels per inch) for specifying the target resolution for generated bitmaps, default: 72dpi -->

<target-resolution>72</target-resolution>

<!-- Default page-height and page-width, in case value is specified as auto -->

<default-page-settings height="29.7cm" width="21cm"/>

<!-- Information for specific renderers -->

<!-- Uses renderer mime type for renderers -->

<renderers>

<renderer mime="application/pdf">

<filterList>

<!-- provides compression using zlib flate (default is on) -->

<value>flate</value>

</filterList>

<fonts>

<!-- embedded fonts -->

<!--

This information must exactly match the font specified

in the fo file. Otherwise it will use a default font.

For example,

<fo:inline font-family="Arial" font-weight="bold" font-style="normal">

Arial-normal-normal font

</fo:inline>

for the font triplet specified by:

<font-triplet name="Arial" style="normal" weight="bold"/>

If you do not want to embed the font in the pdf document

then do not include the "embed-url" attribute.

The font will be needed where the document is viewed

for it to be displayed properly.

possible styles: normal | italic | oblique | backslant

possible weights: normal | bold | 100 | 200 | 300 | 400

| 500 | 600 | 700 | 800 | 900

(normal = 400, bold = 700)

-->

<font metrics-url="file:///D:/SoftwareWork/docbook/fop-2.6-bin/fop-2.6/fop/conf/fonts/SimHei.xml" kerning="yes" embed-url="file:///D:/SoftwareWork/docbook/fop-2.6-bin/fop-2.6/fop/conf/fonts/SimHei.ttf">

<font-triplet name="SimHei" style="normal" weight="normal"/>

<font-triplet name="SimHei" style="normal" weight="bold"/>

<font-triplet name="SimHei" style="italic" weight="normal"/>

<font-triplet name="SimHei" style="italic" weight="bold"/>

</font>

</fonts>

<!-- This option lets you specify additional options on an XML handler -->

<!--xml-handler namespace="http://www.w3.org/2000/svg">

<stroke-text>false</stroke-text>

</xml-handler-->

</renderer>

<renderer mime="application/postscript">

<!-- This option forces the PS renderer to rotate landscape pages -->

<!--auto-rotate-landscape>true</auto-rotate-landscape-->

<!-- This option lets you specify additional options on an XML handler -->

<!--xml-handler namespace="http://www.w3.org/2000/svg">

<stroke-text>false</stroke-text>

</xml-handler-->

</renderer>

<renderer mime="image/png">

<!--transparent-page-background>true</transparent-page-background-->

</renderer>

<renderer mime="image/tiff">

<!--transparent-page-background>true</transparent-page-background-->

<!--compression>CCITT T.6</compression-->

</renderer>

<renderer mime="text/xml">

</renderer>

<!-- RTF does not have a renderer

<renderer mime="text/rtf">

</renderer>

-->

</renderers>

</fop>

4. 进入docbook-xsl-1.79.1\fo\的目录下面新增docbook.zh-CN.xsl文件,文件内容如下:

<?xml version='1.0'?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:fo="http://www.w3.org/1999/XSL/Format"

xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"

exclude-result-prefixes="doc"

version="1.0">

<xsl:import href="docbook.xsl"/>

<xsl:param name="body.font.family">SimHei,serif</xsl:param>

<xsl:param name="body.font.size">12</xsl:param>

<xsl:param name="monospace.font.family">SimHei,serif</xsl:param>

<xsl:param name="title.font.family">SimHei,serif</xsl:param>

<xsl:param name="page.margin.inner">2cm</xsl:param>

<xsl:param name="page.margin.outer">2cm</xsl:param>

<xsl:param name="hyphenate">false</xsl:param>

<xsl:param name="paper.type" select="'A4'"/>

<xsl:param name="draft.mode" select="'no'"/>

</xsl:stylesheet>

5. 进入fop.bat所在的目录:

执行如下命令将xml文件生成fo文件

xsltproc --output test3.fo D:\SoftwareWork\docbook\docbook-xsl-1.79.1\fo\docbook.zh-CN.xsl mes.xml

注意:xsl格式转换文件使用新建的文件。

执行如下命令将fo文件生成pdf文件,即可解决中文乱码问题

fop -c D:\SoftwareWork\docbook\fop-2.6-bin\fop-2.6\fop\fop.xml -fo test3.fo -pdf test4.pdf

 类似资料: