日期:2014-05-18  浏览次数:21009 次

高分求将htm打包成chm格式的思路
问题是这样的,我有一堆htm文件,想打包成一个chm或者是其他格式的单个文件方便存储和管理。

可用以下语言实现:
VB/VB.Net
C#

可提供思路,链接,代码片段均可

不要现成软件,因为要自己编程实现便于控制,但是可以接受引用其他组件(免费收费的均可)

本贴在VB.Net/C#/VB区发布,时间两周,如果找到解决方法,除贴内分(贴内分将分配给各位回帖的朋友)外,额外给出500分。

非常感谢~~

------解决方案--------------------
可以参考现成软件呀。
------解决方案--------------------
参考如下博文:
Html文件转CHM文件类--------用C#实现将html文件转换为chm文件
------解决方案--------------------
[转载]

这些天因为工作需要,要将一些html文件转换为chm文件,当然是需要和程序结合在一起。 
后来找到NDoc,里头有一段代码是相关的,于是开始分析代码,写完之后,总结:主要是利用微软的hhc.exe来编译html文件,程序需要将具体的数据写入hhp和hhc文件。 

代码如下:

C# code
public void CompileProject()
{
    Process helpCompileProcess = new Process();  //创建新的进程,NDOC采用Process启动HHC.EXE来Compile一个CHM文件

    try
    {
        ////判断文件是否存在并不被占用
        try
        {
            string path = _chmFile;  //chm生成路径 

            if (File.Exists(path))
            {
                File.Delete(path);
            }
        }
        catch
        {
            throw new Exception("文件被打开!");
        }

        ProcessStartInfo processStartInfo = new ProcessStartInfo();
        processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        processStartInfo.FileName = hhcFile;  //调入HHC.EXE文件  
        processStartInfo.Arguments = "\"" + Path.GetFullPath(GetPathToProjectFile()) + "\"";//获取空的HHP文件

        helpCompileProcess.StartInfo = processStartInfo;

        //开始生成....
        helpCompileProcess.Start();

        helpCompileProcess.WaitForExit(); //组件无限期地等待关联进程退出

        if (helpCompileProcess.ExitCode == 0)
        {
            MessageBox.Show(new Exception().Message);
        }

    }
    finally
    {
        helpCompileProcess.Close();
    }
}
public void OpenProjectFile()
{
    FileStream fs = new FileStream(GetPathToProjectFile(), FileMode.Create);
    streamHtmlHelp = new System.IO.StreamWriter(fs, System.Text.Encoding.GetEncoding("GB18030"));
    streamHtmlHelp.WriteLine("[FILES]");
}

public void AddFileToProject(string filename)
{
    streamHtmlHelp.WriteLine(filename);
}

public void CloseProjectFile(string title)
{
    streamHtmlHelp.WriteLine();
    streamHtmlHelp.WriteLine("[OPTIONS]");
    streamHtmlHelp.WriteLine("Title=" + title);
    streamHtmlHelp.WriteLine("Compatibility=1.1 or later");
    streamHtmlHelp.WriteLine("Compiled file=" + GetCompiledHtmlFilename());  //chm文件名
    streamHtmlHelp.WriteLine("Contents file=" + GetContentsHtmlFilename());  //hhc文件名
    streamHtmlHelp.WriteLine("Default topic=" + _defaultTopic);  //默认页
    streamHtmlHelp.WriteLine("Display compile progress=No"); //是否显示编译过程 
    streamHtmlHelp.WriteLine("Language=0x804 中文(中国)");  //chm文件语言
    streamHtmlHelp.WriteLine();
    streamHtmlHelp.WriteLine("[INFOTYPES]");
    streamHtmlHelp.Close();
}

------解决方案--------------------
http://www.xdesigner.cn/chmbuilder/chmbuilder.rar