diff --git a/pdf2htmlEX.1 b/pdf2htmlEX.1.in similarity index 97% rename from pdf2htmlEX.1 rename to pdf2htmlEX.1.in index 7ae49f3..7de13c4 100644 --- a/pdf2htmlEX.1 +++ b/pdf2htmlEX.1.in @@ -38,6 +38,9 @@ Specify user password .B --dest-dir (Default: ".") Specify destination folder .TP +.B --data-dir (Default: @CMAKE_INSTALL_PREFIX@/share/pdf2htmlEX) +Specify the folder holding the manifest and other files +.TP .B -f, --first-page (Default: 1) Specify the first page to process .TP diff --git a/share/manifest b/share/manifest index 908252f..1ff5e1e 100644 --- a/share/manifest +++ b/share/manifest @@ -7,7 +7,7 @@ # Empty lines are ignored # # # - comment -# @ - include file +# @ - include a file from data dir # $ - special use for pdf2htmlEX # # Special diff --git a/src/HTMLRenderer/export.cc b/src/HTMLRenderer/export.cc index 701f87d..04c3e3f 100644 --- a/src/HTMLRenderer/export.cc +++ b/src/HTMLRenderer/export.cc @@ -23,7 +23,7 @@ void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suff auto fn = str_fmt("f%llx%s", info.id, suffix.c_str()); if(param->single_html) { - css_fout << "'data:font/opentype;base64," << base64stream(ifstream(tmp_dir + "/" + (char*)fn, ifstream::binary)) << "'"; + css_fout << "'data:font/opentype;base64," << base64stream(ifstream(param->tmp_dir + "/" + (char*)fn, ifstream::binary)) << "'"; } else { diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index ef132a5..3429871 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -33,8 +33,6 @@ HTMLRenderer::HTMLRenderer(const Param * param) ,line_buf(this) ,image_count(0) ,param(param) - ,dest_dir(param->dest_dir) - ,tmp_dir(param->tmp_dir) { //disable error function of poppler setErrorCallback(&dummy, nullptr); @@ -89,7 +87,7 @@ void HTMLRenderer::process(PDFDoc *doc) { if(param->split_pages) { - auto page_fn = str_fmt("%s/%s%d.page", dest_dir.c_str(), param->output_filename.c_str(), i); + auto page_fn = str_fmt("%s/%s%d.page", param->dest_dir.c_str(), param->output_filename.c_str(), i); html_fout.open((char*)page_fn, ofstream::binary); fix_stream(html_fout); } @@ -101,7 +99,7 @@ void HTMLRenderer::process(PDFDoc *doc) nullptr, nullptr, &annot_cb, nullptr); { - auto fn = str_fmt("%s/p%llx.png", (param->single_html ? tmp_dir : dest_dir).c_str(), i); + auto fn = str_fmt("%s/p%x.png", (param->single_html ? param->tmp_dir : param->dest_dir).c_str(), i); if(param->single_html) add_tmp_file((char*)fn); @@ -142,15 +140,15 @@ void HTMLRenderer::pre_process() * * * If single-html && split-page - * as there's no place to embed the css file, just leave it alone (into dest_dir) + * as there's no place to embed the css file, just leave it alone (into param->dest_dir) * * If !single-html - * leave it in dest_dir + * leave it in param->dest_dir */ auto fn = (param->single_html && (!param->split_pages)) - ? str_fmt("%s/__css", tmp_dir.c_str()) - : str_fmt("%s/%s", dest_dir.c_str(), param->css_filename.c_str()); + ? str_fmt("%s/__css", param->tmp_dir.c_str()) + : str_fmt("%s/%s", param->dest_dir.c_str(), param->css_filename.c_str()); if(param->single_html && (!param->split_pages)) add_tmp_file((char*)fn); @@ -171,7 +169,7 @@ void HTMLRenderer::pre_process() * * Otherwise just generate it */ - auto fn = str_fmt("%s/__pages", tmp_dir.c_str()); + auto fn = str_fmt("%s/__pages", param->tmp_dir.c_str()); add_tmp_file((char*)fn); html_path = (char*)fn; @@ -190,11 +188,11 @@ void HTMLRenderer::post_process() if(param->split_pages) return; - ofstream output((char*)str_fmt("%s/%s", dest_dir.c_str(), param->output_filename.c_str())); + ofstream output((char*)str_fmt("%s/%s", param->dest_dir.c_str(), param->output_filename.c_str())); fix_stream(output); // apply manifest - ifstream manifest_fin((char*)str_fmt("%s/%s", PDF2HTMLEX_DATA_PATH.c_str(), MANIFEST_FILENAME.c_str())); + ifstream manifest_fin((char*)str_fmt("%s/%s", param->data_dir.c_str(), MANIFEST_FILENAME.c_str())); bool embed_string = false; string line; @@ -218,7 +216,7 @@ void HTMLRenderer::post_process() if(line[0] == '@') { - embed_file(output, PDF2HTMLEX_DATA_PATH + "/" + line.substr(1), "", true); + embed_file(output, param->data_dir + "/" + line.substr(1), "", true); continue; } @@ -259,11 +257,11 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state) { if(param->single_html) { - html_fout << "'data:image/png;base64," << base64stream(ifstream((char*)str_fmt("%s/p%llx.png", tmp_dir.c_str(), pageNum) , ifstream::binary)) << "'"; + html_fout << "'data:image/png;base64," << base64stream(ifstream((char*)str_fmt("%s/p%x.png", param->tmp_dir.c_str(), pageNum) , ifstream::binary)) << "'"; } else { - html_fout << str_fmt("p%llx.png", pageNum); + html_fout << str_fmt("p%x.png", pageNum); } } @@ -329,9 +327,9 @@ void HTMLRenderer::clean_tmp_files() cerr << "Remove temporary file: " << fn << endl; } - remove(tmp_dir.c_str()); + remove(param->tmp_dir.c_str()); if(param->debug) - cerr << "Remove temporary directory: " << tmp_dir << endl; + cerr << "Remove temporary directory: " << param->tmp_dir << endl; } void HTMLRenderer::embed_file(ostream & out, const string & path, const string & type, bool copy) @@ -360,7 +358,7 @@ void HTMLRenderer::embed_file(ostream & out, const string & path, const string & if(copy) { - ofstream(dest_dir + "/" + fn, ofstream::binary) << ifstream(path, ifstream::binary).rdbuf(); + ofstream(param->dest_dir + "/" + fn, ofstream::binary) << ifstream(path, ifstream::binary).rdbuf(); } } } diff --git a/src/HTMLRenderer/text.cc b/src/HTMLRenderer/text.cc index f6ecbdd..d47a25d 100644 --- a/src/HTMLRenderer/text.cc +++ b/src/HTMLRenderer/text.cc @@ -124,7 +124,7 @@ string HTMLRenderer::dump_embedded_font (GfxFont * font, long long fn_id) obj.streamReset(); - filepath = (char*)str_fmt("%s/f%llx%s", tmp_dir.c_str(), fn_id, suffix.c_str()); + filepath = (char*)str_fmt("%s/f%llx%s", param->tmp_dir.c_str(), fn_id, suffix.c_str()); add_tmp_file(filepath); ofstream outf(filepath, ofstream::binary); @@ -349,7 +349,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo // TODO: see if we can get the values without save/load - auto fn = str_fmt("%s/f%llx_.ttf", tmp_dir.c_str(), info.id); + auto fn = str_fmt("%s/f%llx_.ttf", param->tmp_dir.c_str(), info.id); add_tmp_file((char*)fn); ff_save((char*)fn); @@ -383,7 +383,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo { auto fn = str_fmt("%s/f%llx%s", - (param->single_html ? tmp_dir : dest_dir).c_str(), + (param->single_html ? param->tmp_dir : param->dest_dir).c_str(), info.id, param->font_suffix.c_str()); if(param->single_html) diff --git a/src/include/HTMLRenderer.h b/src/include/HTMLRenderer.h index e068dc2..dc76479 100644 --- a/src/include/HTMLRenderer.h +++ b/src/include/HTMLRenderer.h @@ -364,7 +364,6 @@ class HTMLRenderer : public OutputDev int image_count; const Param * param; - std::string dest_dir, tmp_dir; std::ofstream html_fout, css_fout; std::string html_path, css_path; std::set tmp_files; diff --git a/src/include/Param.h b/src/include/Param.h index 9d5174c..4381feb 100644 --- a/src/include/Param.h +++ b/src/include/Param.h @@ -20,7 +20,7 @@ struct Param std::string input_filename, output_filename; // path - std::string dest_dir, tmp_dir; + std::string dest_dir, tmp_dir, data_dir; // normal parameters int first_page, last_page; diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc index 3568211..1c6511e 100644 --- a/src/pdf2htmlEX.cc +++ b/src/pdf2htmlEX.cc @@ -53,7 +53,8 @@ void parse_options (int argc, char **argv) .add("owner-password,o", ¶m.owner_password, "", "owner password (for encrypted files)") .add("user-password,u", ¶m.user_password, "", "user password (for encrypted files)") - .add("dest-dir", ¶m.dest_dir, ".", "destination directory") + .add("dest-dir", ¶m.dest_dir, ".", "specify destination directory") + .add("data-dir", ¶m.data_dir, PDF2HTMLEX_DATA_PATH, "specify data directory") .add("first-page,f", ¶m.first_page, 1, "first page to process") .add("last-page,l", ¶m.last_page, numeric_limits::max(), "last page to process")