Convert HTML files to CHM files with C #

xiaoxiao2021-03-06  15

Convert HTML files to CHM files with C #

These days are required to convert some HTML files to a CHM file because of work needs, of course, need to be combined with programs. Later, I found NDOC, and a code was related, so I started analyzing the code. After writing, summary: Mainly using Microsoft's hhc.exe to compile HTML files, the program needs to write specific data to HHP and HHC files. The main code is as follows: public void compileproject () {process helpCompileProcess = new process (); // Create a new process, NDOC starts hhc.exe to compile a CHM file with Process

Try {Judging whether the file does not occupy the try {string path = _chmfile; // CHM generation path

IF (file.exists (path)) {file.delete (path);}} catch {throw new exception ("file is opened!");

ProcessStartInfo processStartInfo = new ProcessStartInfo (); processStartInfo.WindowStyle = ProcessWindowStyle.Hidden; processStartInfo.FileName = hhcFile; // file transferred HHC.EXE processStartInfo.Arguments = "/" " Path.GetFullPath (GetPathToProjectFile ()) " / ""; // Get an empty HHP file

HelpCompileProcess.startInfo = processstartinfo;

// Start generation ... HelpCompileProcess.Start ();

HelpCompileProcess.waitForexit (); // Component is in an indefinitely waiting to exit

IF (helpCompileProcess.exitcode == 0) {messagebox.show (new exception ();};

} 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 file name streamHtmlHelp.WriteLine ( "Contents file =" GetContentsHtmlFilename ()); // hhc file name streamHtmlHelp.WriteLine ( "default topic =" _defaultTopic); // default page streamHtmlHelp.WriteLine ( "Display compile progress = No "); // Whether to display the compilation process streamhtmlhelp.writeline (" Language = 0x804 Chinese (China) "); // CHM file language streamhtmlhelp.wr Iteline (); streamhtmlhelp.writeline ("[Infotypes]");

streamhtmlhelp.close ();

转载请注明原文地址:https://www.9cbs.com/read-49934.html

New Post(0)