一个类和hhc.exe还有hha.dll

用于生成包含html目录的chm项目文件 ,然后通过hhp项目文件和内容文件生成 .chm手册。

/* 函数 listDirTree( $dirName = null )

** 功能 列出目录下所有文件及子目录

** 参数 $dirName 目录名称

** 返回 目录结构数组 false为失败

*/

function listDir($dirName = null) {

if (empty($dirName))

exit("IBFileSystem: directory is empty.");

if (is_dir($dirName)) {

if ($dh = opendir($dirName)) {

$tree = array();

while (( $file = readdir($dh) ) !== false) {

if ($file != "." && $file != "..") {

$filePath = $dirName . DIRECTORY_SEPARATOR . $file;

if (is_dir($filePath)) { //为目录,递归

$tree2 =listDir($filePath);

$tree = $tree2? array_merge($tree,$tree2):$tree;

} else { //为文件,添加到当前数组

$tree[] = $filePath;

}

}

}

closedir($dh);

} else {

exit("IBFileSystem: can not open directory $dirName.");

}

//返回当前的$tree

$tree = array_unique($tree);

natsort($tree);

return $tree;

} else {

exit("IBFileSystem: $dirName is not a directory.");

}

}

function listDirTree($dirName = null,$remove) {

if (empty($dirName))

exit("IBFileSystem: directory is empty.");

if (is_dir($dirName)) {

if ($dh = opendir($dirName)) {

$tree = array();

while (( $file = readdir($dh) ) !== false) {

if ($file != "." && $file != ".." && stripos($remove, $file) === false) {

$filePath = $dirName . DIRECTORY_SEPARATOR . $file;

if (is_dir($filePath)) { //为目录,递归

$arr = listDirTree($filePath,$remove);

natsort($arr);

$tree[$file] = $arr;

} else { //为文件,添加到当前数组

$tree[] = $filePath;

}

}

}

closedir($dh);

} else {

exit("IBFileSystem: can not open directory $dirName.");

}

//返回当前的$tree

return $tree;

} else {

exit("IBFileSystem: $dirName is not a directory.");

}

}

function cmp($a,$b){

$a = (int)$a;

$b = (int)$b;

if($a == $b)    return 0;

return ($a>$b)? 1:-1;

}

class chmBuilder{

// const version = 0.1;

public $chm_name;

public $chm_path;

public $chm_hhp;

public $chm_hhc;

public $chm_hhk;

public $chm_uninclude_dirs;

public $chm_uninclude_files;

public $chm_image_type;

public $chm_first_open;

public $chm_title;

public function __construct($chm_name='your_chm',$chm_path='',$chm_uninclude_dirs,$chm_uninclude_files){

$this->chm_name = $chm_name;

$this->chm_path = $chm_path;

$this->chm_uninclude_dirs = $chm_uninclude_dirs;

$this->chm_uninclude_files = $chm_uninclude_files;

$this->chm_image_type = 'Folder';

}

public function build(){

$this->buildHhp();

$this->buildHhc();

$this->buildHhk();

}

public function buildHhp(){

$manual_files = listDir($this->chm_path);

$files = implode(PHP_EOL, $manual_files);

$this->chm_first_open = iconv('UTF-8', 'GB2312', $this->chm_first_open);

$this->chm_title = iconv('UTF-8', 'GB2312', $this->chm_title);

$tpl = <<

[OPTIONS]

Compatibility=1.1 or later

Compiled file={$this->chm_path}/{$this->chm_name}.chm

Contents file={$this->chm_hhc}.hhc

COPYRIGHT=www.thinkphp.cn

Display compile progress=No

Default topic={$this->chm_first_open}

Error log file=chm_builder.Log

Full-text search=Yes

Index file={$this->chm_hhk}.hhk

ImageType={$this->chm_image_type}

Language=0x804

Title={$this->chm_title}

[FILES]

{$files}

eof;

file_put_contents("{$this->chm_path}/{$this->chm_hhp}.hhp", $tpl);

}

public function buildHhc(){

$list = array();

$file_tree = listDirTree($this->chm_path,"{$this->chm_hhp} {$this->chm_uninclude_dirs}{$this->chm_uninclude_files}");

uksort($file_tree, 'cmp');

foreach ($file_tree as $key => $value) {

if(is_string($value)){

$title = explode(DIRECTORY_SEPARATOR, $value);

$title = array_pop($title);

$title = rtrim($title,'.html');

$list[] = <<

eof;

}else{

$child = array();

foreach ($value as $k => $val) {

$title = explode(DIRECTORY_SEPARATOR, $val);

$title = array_pop($title);

$title = rtrim($title,'.html');

$child[] = <<

eof;

}

$child = implode(PHP_EOL, $child);

$list[] = <<

{$child}

eof;

}

}

$list = implode(PHP_EOL, $list);

$tpl = <<

HTML PUBLIC "-//IETF//DTD HTML//EN">

{$list}

eof;

file_put_contents("{$this->chm_path}/{$this->chm_hhc}.hhc", $tpl);

}

public function buildHhk(){

$list = array();

$file_tree = listDir($this->chm_path);

foreach ($file_tree as $key => $value) {

if(is_string($value)){

if(stripos($value, '.html')){

$title = explode(DIRECTORY_SEPARATOR, $value);

$title = array_pop($title);

$title = rtrim($title,'.html');

$list[] = <<

eof;

}

}

}

$list = implode(PHP_EOL, $list);

$tpl = <<

HTML PUBLIC "-//IETF//DTD HTML//EN">

{$list}

eof;

file_put_contents("{$this->chm_path}/{$this->chm_hhk}.hhk", $tpl);

}

public function makeChm(){

if(!is_file("{$this->chm_path}/{$this->chm_hhp}.hhp"))

return "build error:can't generate *.hhp file!";

$command = "hhc {$this->chm_path}/{$this->chm_hhp}.hhp";

system($command);

if(file_exists("{$this->chm_path}/{$this->chm_name}.chm"))

return true;

else

return 'generate chm failed!';

}

}

?>

使用方法,放到要生成目录的外面 定义好路径,手册名,不包含目录,不包含文件 字符串(空格分割),设置好一些属性后, 将hhc.exe的位置加入环境变量path中,cmd 里调用 执行的index.php 可以看到生成的信息,或者错误

index.php

header('Content-type:text/plain;charset=utf-8');

error_reporting(E_ERROR);

ini_set('memory_limit', '30M');

include 'chm_builder.php';

$chm = new chmBuilder('ThinkPHP manual',__DIR__.DIRECTORY_SEPARATOR.'manual','public ','.DS_Store Thumbs.db book.tpl');

$chm->chm_hhp = 'index';

$chm->chm_hhc = 'index';

$chm->chm_first_open = $chm->chm_path.DIRECTORY_SEPARATOR.'序言.html';

$chm->chm_hhk = 'index';

$chm->chm_title = 'ThinkPHP 3.1.2官方手册';

$chm->build();

//$chm->makeChm();

?>

这个可以配合ThinkPHP Sublime 插件来生成手册,目前排序方面有点问题,故没集成到插件里去。目前只支持二级分类,多级的大家递归时tab缩进好个是就行了,用手册里第一层目录和单文件名作为章节,里面的文件作为子章节

python chm制作_生成chm文档的方法相关推荐

  1. python 生成html文档,Python使用pyh生成HTML文档的方法示例

    Python使用pyh生成HTML文档的方法示例 来源:中文源码网    浏览: 次    日期:2018年9月2日 [下载文档:  Python使用pyh生成HTML文档的方法示例.txt ] (友 ...

  2. php导出doc文件_PHP生成Word文档的方法

    PHP生成Word文档的方法 首先,请确保在你的Windows系统中已经安装并配置好了一个典型的WAMP环境.由于Interop纯粹是一个Windows的特性,我们将在Windows平台下搭建Apac ...

  3. php 2003生成word,使用PHPWord生成word文档的方法详解

    使用PHPWord生成word文档的方法详解 来源:中文源码网    浏览: 次    日期:2019年11月5日 [下载文档:  使用PHPWord生成word文档的方法详解.txt ] (友情提示 ...

  4. php生成word设置纸张,PHP生成Word文档的方法

    首先,请确保在你的Windows系统中已经安装并配置好了一个典型的WAMP环境.由于Interop纯粹是一个Windows的特性,我们将在Windows平台下搭建Apache和PHP,下面,小编为大家 ...

  5. Java基础:生成JavaDoc文档的方法

    Java Doc javadoc命令是用来生成自己API文档的 参数信息 @author 作者名 @version 版本号 @since 指明需要最早使用的jdk版本 @param 参数名 @retu ...

  6. php生成 word,使用PHPWord生成word文档的方法详解

    本文实例讲述了使用PHPWord生成word文档的方法.分享给大家供大家参考,具体如下: 有时我们需要把网页内容保存为Word文档格式,以供其他人员查看和编辑.PHPWord是一个用纯PHP编写的库, ...

  7. 数据库数据生成word文档的方法

    从库里取纪录生成word文档. 主要有这么几种方法: 1.改头,就是象excel似的 Response.Buffer = TRUE Response.ContentType = "appli ...

  8. 我鼓捣的数据库数据生成word文档的方法!

    <script language="javascript" src="/js/content_top.js" type="text/javasc ...

  9. python教程112-Python批量生成合同文档

    Python可是实现办公自动化的利器,本文使用Python批量生成合同,学会这个即可解决重复制作合同的问题 开发系统 :window10家庭版 示例工具:anconda3.7 python3.8 本文 ...

最新文章

  1. 2022-2028全球及中国呼吸麻醉消耗品行业研究及十四五规划分析报告
  2. nexus 4 下 DualBootInstallation 安装 ubuntu touch
  3. 2018年中国研究生数学建模竞赛C题 二等奖 赛题论文
  4. 深度强化学习-马尔科夫决策过程和表格型方法
  5. LeetCode 16 最接近的三数之和
  6. 注解_自定义注解_属性定义
  7. C++ | 内联函数 inline
  8. Angular页面里元素class的动态绑定的实现源代码调试
  9. Redis 混合存储最佳实践指南
  10. 浅谈JavaScript中forEach与each
  11. openfeign远程调用不起作用解决_使用Spring Boot的spring.factories进行注入---SpringCloud Alibaba_若依微服务框架改造---工作笔记007
  12. 普通人,怎么改变命运?
  13. 数据分析与可视化(四)Pandas学习基础一:统计分析基础
  14. 用CSS3实现无限循环的无缝滚动
  15. node的HTPP请求
  16. 地雷復 (易經大意 韓長庚)
  17. 地标海之珠夜色素材高清图片
  18. ProcessingJoy —— 粒子流逝特效【JAVA】
  19. bat(batch)
  20. Bootstrap按钮元素使用方法

热门文章

  1. winform利用委托传值到datagridview_C# Winform 跨多级窗体/控件传值
  2. php+html5+jquery断点续传_PHP学习路线:PHP从入门到精通教程
  3. matlab朴素贝叶斯手写数字识别_TensorFlow手写数字识别(一)
  4. win7系统备份还原软件_收藏备用!操作系统的快速备份与还原技巧
  5. ViewPager留两边 显示左右两边的视图
  6. 计算沙盒中一个目录的大小
  7. Android - 网络基础
  8. Stereo matching code
  9. linux下使用sftp
  10. windows phone 学习之页面导航和数据传递