diff --git a/share/manifest b/share/manifest index 0fd9f4c..a3fbe8c 100644 --- a/share/manifest +++ b/share/manifest @@ -39,11 +39,6 @@ pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({ container_id : 'page-container', sidebar_id : 'sidebar', outline_id : 'outline', - page_urls : [ -""" -$page_urls -""" -] }); """ diff --git a/src/HTMLRenderer/HTMLRenderer.h b/src/HTMLRenderer/HTMLRenderer.h index 4634592..4d07f7d 100644 --- a/src/HTMLRenderer/HTMLRenderer.h +++ b/src/HTMLRenderer/HTMLRenderer.h @@ -308,8 +308,6 @@ protected: Preprocessor preprocessor; TmpFiles tmp_files; - // for splitted pages - std::vector page_filenames; // for string formatting StringFormatter str_fmt; @@ -318,6 +316,8 @@ protected: std::ofstream fs; std::string path; } f_outline, f_pages, f_css; + std::ofstream * f_curpage; + std::string cur_page_filename; static const std::string MANIFEST_FILENAME; }; diff --git a/src/HTMLRenderer/draw.cc b/src/HTMLRenderer/draw.cc index 9926916..9bc0ead 100644 --- a/src/HTMLRenderer/draw.cc +++ b/src/HTMLRenderer/draw.cc @@ -370,50 +370,50 @@ void HTMLRenderer::css_draw_rectangle(double x, double y, double w, double h, co } } - f_pages.fs << "
0) f_pages.fs << ' '; + if(i > 0) (*f_curpage) << ' '; double lw = line_width_array[i] * scale; - f_pages.fs << round(lw); - if(is_positive(lw)) f_pages.fs << "px"; + (*f_curpage) << round(lw); + if(is_positive(lw)) (*f_curpage) << "px"; } - f_pages.fs << ";"; + (*f_curpage) << ";"; } else { - f_pages.fs << "border:none;"; + (*f_curpage) << "border:none;"; } if(fill_color) { - f_pages.fs << "background-color:" << (*fill_color) << ";"; + (*f_curpage) << "background-color:" << (*fill_color) << ";"; } else { - f_pages.fs << "background-color:transparent;"; + (*f_curpage) << "background-color:transparent;"; } if(style_function) { - style_function(style_function_data, f_pages.fs); + style_function(style_function_data, (*f_curpage)); } - f_pages.fs << "bottom:" << round(y) << "px;" + (*f_curpage) << "bottom:" << round(y) << "px;" << "left:" << round(x) << "px;" << "width:" << round(w * scale) << "px;" << "height:" << round(h * scale) << "px;"; - f_pages.fs << "\">
"; + (*f_curpage) << "\">"; } diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index d94e732..7918abe 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -112,12 +112,12 @@ void HTMLRenderer::process(PDFDoc *doc) { string filled_template_filename = (char*)str_fmt(param.page_filename.c_str(), i); auto page_fn = str_fmt("%s/%s", param.dest_dir.c_str(), filled_template_filename.c_str()); - f_pages.fs.open((char*)page_fn, ofstream::binary); - if(!f_pages.fs) + f_curpage = new ofstream((char*)page_fn, ofstream::binary); + if(!(*f_curpage)) throw string("Cannot open ") + (char*)page_fn + " for writing"; - set_stream_flags(f_pages.fs); + set_stream_flags((*f_curpage)); - page_filenames.push_back(filled_template_filename); + cur_page_filename = filled_template_filename; } if(param.process_nontext) @@ -139,7 +139,8 @@ void HTMLRenderer::process(PDFDoc *doc) if(param.split_pages) { - f_pages.fs.close(); + delete f_curpage; + f_curpage = nullptr; } } if(page_count >= 0) @@ -180,7 +181,7 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref) long long wid = all_manager.width.install(pageWidth); long long hid = all_manager.height.install(pageHeight); - f_pages.fs + (*f_curpage) << "
"; + /* + * When split_pages is on, f_curpage points to the current page file + * and we want to output empty frames in f_pages.fs + */ + if(param.split_pages) + { + f_pages.fs + << "
" + << "
"; + } + if(param.process_nontext) { - f_pages.fs << "\"\""; + (*f_curpage) << "\"/>"; } reset_state(); @@ -216,7 +237,7 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref) void HTMLRenderer::endPage() { // dump all text - html_text_page.dump_text(f_pages.fs); + html_text_page.dump_text(*f_curpage); html_text_page.dump_css(f_css.fs); html_text_page.clear(); @@ -224,26 +245,31 @@ void HTMLRenderer::endPage() { cur_doc->processLinks(this, pageNum); // close box - f_pages.fs << "
"; + (*f_curpage) << "
"; // dump info for js // TODO: create a function for this // BE CAREFUL WITH ESCAPES - f_pages.fs << "
0) f_pages.fs << ","; - f_pages.fs << round(default_ctm[i]); + if(i > 0) (*f_curpage) << ","; + (*f_curpage) << round(default_ctm[i]); } - f_pages.fs << "]"; + (*f_curpage) << "]"; - f_pages.fs << "}'>
"; + (*f_curpage) << "}'>
"; // close page - f_pages.fs << "" << endl; + (*f_curpage) << "" << endl; + + if(param.split_pages) + { + f_pages.fs << "" << endl; + } } void HTMLRenderer::pre_process(PDFDoc * doc) @@ -324,9 +350,6 @@ void HTMLRenderer::pre_process(PDFDoc * doc) 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) { /* * we have to keep the html file for pages into a temporary place @@ -343,6 +366,15 @@ void HTMLRenderer::pre_process(PDFDoc * doc) throw string("Cannot open ") + (char*)fn + " for writing"; set_stream_flags(f_pages.fs); } + + if(param.split_pages) + { + f_curpage = nullptr; + } + else + { + f_curpage = &f_pages.fs; + } } void HTMLRenderer::post_process(void) @@ -436,25 +468,11 @@ void HTMLRenderer::post_process(void) } else if (line == "$pages") { - if(!param.split_pages) - { - ifstream fin(f_pages.path, ifstream::binary); - if(!fin) - throw "Cannot open pages for reading"; - output << fin.rdbuf(); - output.clear(); // output will set fail bit if fin is empty - } - } - else if (line == "$page_urls") - { - for(auto iter = page_filenames.begin(); iter != page_filenames.end(); ++iter) - { - if(iter != page_filenames.begin()) - output << ","; - output << "'"; - outputJSON(output, *iter); - output << "'"; - } + ifstream fin(f_pages.path, ifstream::binary); + if(!fin) + throw "Cannot open pages for reading"; + output << fin.rdbuf(); + output.clear(); // output will set fail bit if fin is empty } else { diff --git a/src/HTMLRenderer/link.cc b/src/HTMLRenderer/link.cc index c185d61..76446a4 100644 --- a/src/HTMLRenderer/link.cc +++ b/src/HTMLRenderer/link.cc @@ -195,17 +195,17 @@ void HTMLRenderer::processLink(AnnotLink * al) if(!dest_str.empty()) { - f_pages.fs << ""; + (*f_curpage) << ">"; } - f_pages.fs << "
getStyle(); switch(style) { case AnnotBorder::borderSolid: - f_pages.fs << "border-style:solid;"; + (*f_curpage) << "border-style:solid;"; break; case AnnotBorder::borderDashed: - f_pages.fs << "border-style:dashed;"; + (*f_curpage) << "border-style:dashed;"; break; case AnnotBorder::borderBeveled: - f_pages.fs << "border-style:outset;"; + (*f_curpage) << "border-style:outset;"; break; case AnnotBorder::borderInset: - f_pages.fs << "border-style:inset;"; + (*f_curpage) << "border-style:inset;"; break; case AnnotBorder::borderUnderlined: - f_pages.fs << "border-style:none;border-bottom-style:solid;"; + (*f_curpage) << "border-style:none;border-bottom-style:solid;"; break; default: cerr << "Warning:Unknown annotation border style: " << style << endl; - f_pages.fs << "border-style:solid;"; + (*f_curpage) << "border-style:solid;"; } @@ -274,36 +274,36 @@ void HTMLRenderer::processLink(AnnotLink * al) r = g = b = 0; } - f_pages.fs << "border-color:rgb(" + (*f_curpage) << "border-color:rgb(" << dec << (int)dblToByte(r) << "," << (int)dblToByte(g) << "," << (int)dblToByte(b) << hex << ");"; } else { - f_pages.fs << "border-style:none;"; + (*f_curpage) << "border-style:none;"; } } else { - f_pages.fs << "border-style:none;"; + (*f_curpage) << "border-style:none;"; } tm_transform(default_ctm, x, y); - f_pages.fs << "position:absolute;" + (*f_curpage) << "position:absolute;" << "left:" << round(x) << "px;" << "bottom:" << round(y) << "px;" << "width:" << round(w) << "px;" << "height:" << round(h) << "px;"; // fix for IE - f_pages.fs << "background-color:rgba(255,255,255,0.000001);"; + (*f_curpage) << "background-color:rgba(255,255,255,0.000001);"; - f_pages.fs << "\">
"; + (*f_curpage) << "\">"; if(dest_str != "") { - f_pages.fs << "
"; + (*f_curpage) << ""; } }