diff --git a/share/manifest b/share/manifest index abffd73..962e4fe 100644 --- a/share/manifest +++ b/share/manifest @@ -42,7 +42,7 @@ new pdf2htmlEX.Viewer('pdf-main');
""" -$outlines +$outline """
diff --git a/src/HTMLRenderer/HTMLRenderer.h b/src/HTMLRenderer/HTMLRenderer.h index 4b162c0..087cae9 100644 --- a/src/HTMLRenderer/HTMLRenderer.h +++ b/src/HTMLRenderer/HTMLRenderer.h @@ -434,7 +434,7 @@ class HTMLRenderer : public OutputDev struct { std::ofstream fs; std::string path; - } f_pages, f_css, f_outlines; + } f_outline, f_pages, f_css; static const std::string MANIFEST_FILENAME; }; diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index 932cc1e..a81ed09 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -294,20 +294,41 @@ void HTMLRenderer::pre_process(PDFDoc * doc) if(param->single_html && (!param->split_pages)) tmp_files.add((char*)fn); - f_css.path = (char*)fn, + f_css.path = (char*)fn; f_css.fs.open(f_css.path, ofstream::binary); if(!f_css.fs) throw string("Cannot open ") + (char*)fn + " for writing"; set_stream_flags(f_css.fs); } + { + /* + * The logic for outline is similar to css + */ + + auto fn = (param->single_html && (!param->split_pages)) + ? str_fmt("%s/__outline", param->tmp_dir.c_str()) + : str_fmt("%s/%s", param->dest_dir.c_str(), param->outline_filename.c_str()); + + if(param->single_html && (!param->split_pages)) + tmp_files.add((char*)fn); + + f_outline.path = (char*)fn; + f_outline.fs.open(f_outline.path, ofstream::binary); + if(!f_outline.fs) + throw string("Cannot open") + (char*)fn + " for writing"; + + // might not be necessary + set_stream_flags(f_outline.fs); + } + // if split-pages is specified, open & close the file in the process loop // if not, open the file here: if(!param->split_pages) { /* * If single-html - * we have to keep the html file (for page) into a temporary place + * we have to keep the html file for pages into a temporary place * because we'll have to embed css before it * * Otherwise just generate it @@ -326,6 +347,7 @@ void HTMLRenderer::pre_process(PDFDoc * doc) void HTMLRenderer::post_process() { // close files + f_outline.fs.close(); f_pages.fs.close(); f_css.fs.close(); @@ -379,6 +401,13 @@ void HTMLRenderer::post_process() { embed_file(output, f_css.path, ".css", false); } + else if (line == "$outline") + { + ifstream fin(f_outline.path, ifstream::binary); + if(!fin) + throw "Cannot open read the pages"; + output << fin.rdbuf(); + } else if (line == "$pages") { ifstream fin(f_pages.path, ifstream::binary); diff --git a/src/Param.h b/src/Param.h index 2d22396..2a49ddd 100644 --- a/src/Param.h +++ b/src/Param.h @@ -63,6 +63,7 @@ struct Param * Output */ std::string css_filename; + std::string outline_filename; /* * Debug diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc index 162ffea..b337871 100644 --- a/src/pdf2htmlEX.cc +++ b/src/pdf2htmlEX.cc @@ -101,6 +101,7 @@ void parse_options (int argc, char **argv) .add("font-format", ¶m.font_format, "opentype", "format for extracted font files") .add("external-hint-tool", ¶m.external_hint_tool, "", "external tool for hintting fonts.(overrides --auto-hint)") .add("css-filename", ¶m.css_filename, "", "Specify the file name of the generated css file") + .add("outline-filename", ¶m.outline_filename, "", "Specify the file name of the generated outline file") .add("debug", ¶m.debug, 0, "output debug information") .add("clean-tmp", ¶m.clean_tmp, 1, "clean temporary files after processing") @@ -202,7 +203,7 @@ int main(int argc, char **argv) param.first_page = min(max(param.first_page, 1), doc->getNumPages()); param.last_page = min(max(param.last_page, param.first_page), doc->getNumPages()); - if(param.output_filename == "") + if(param.output_filename.empty()) { const string s = get_filename(param.input_filename); @@ -223,7 +224,7 @@ int main(int argc, char **argv) } } - if(param.css_filename == "") + if(param.css_filename.empty()) { const string s = get_filename(param.input_filename); @@ -237,6 +238,21 @@ int main(int argc, char **argv) param.css_filename = s + ".css"; } } + if(param.outline_filename.empty()) + { + const string s = get_filename(param.input_filename); + + if(get_suffix(param.input_filename) == ".pdf") + { + param.outline_filename = s.substr(0, s.size() - 4) + ".outline"; + } + else + { + if(!param.split_pages) + param.outline_filename = s + ".outline"; + } + + } HTMLRenderer * htmlOut = new HTMLRenderer(¶m); htmlOut->process(doc);