1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-06-26 06:09:21 +00:00

add data-dir

This commit is contained in:
Lu Wang 2012-09-13 00:16:34 +08:00
parent 0a7d0f20a2
commit 4b2b7be7cf
8 changed files with 26 additions and 25 deletions

View File

@ -38,6 +38,9 @@ Specify user password
.B --dest-dir <dir> (Default: ".")
Specify destination folder
.TP
.B --data-dir <dir> (Default: @CMAKE_INSTALL_PREFIX@/share/pdf2htmlEX)
Specify the folder holding the manifest and other files
.TP
.B -f, --first-page <num> (Default: 1)
Specify the first page to process
.TP

View File

@ -7,7 +7,7 @@
# Empty lines are ignored
#
# # - comment
# @ - include file
# @ - include a file from data dir
# $ - special use for pdf2htmlEX
#
# Special

View File

@ -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
{

View File

@ -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();
}
}
}

View File

@ -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)

View File

@ -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<std::string> tmp_files;

View File

@ -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;

View File

@ -53,7 +53,8 @@ void parse_options (int argc, char **argv)
.add("owner-password,o", &param.owner_password, "", "owner password (for encrypted files)")
.add("user-password,u", &param.user_password, "", "user password (for encrypted files)")
.add("dest-dir", &param.dest_dir, ".", "destination directory")
.add("dest-dir", &param.dest_dir, ".", "specify destination directory")
.add("data-dir", &param.data_dir, PDF2HTMLEX_DATA_PATH, "specify data directory")
.add("first-page,f", &param.first_page, 1, "first page to process")
.add("last-page,l", &param.last_page, numeric_limits<int>::max(), "last page to process")