mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-07-01 07:59:00 +00:00
add data-dir
This commit is contained in:
parent
0a7d0f20a2
commit
4b2b7be7cf
|
@ -38,6 +38,9 @@ Specify user password
|
||||||
.B --dest-dir <dir> (Default: ".")
|
.B --dest-dir <dir> (Default: ".")
|
||||||
Specify destination folder
|
Specify destination folder
|
||||||
.TP
|
.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)
|
.B -f, --first-page <num> (Default: 1)
|
||||||
Specify the first page to process
|
Specify the first page to process
|
||||||
.TP
|
.TP
|
|
@ -7,7 +7,7 @@
|
||||||
# Empty lines are ignored
|
# Empty lines are ignored
|
||||||
#
|
#
|
||||||
# # - comment
|
# # - comment
|
||||||
# @ - include file
|
# @ - include a file from data dir
|
||||||
# $ - special use for pdf2htmlEX
|
# $ - special use for pdf2htmlEX
|
||||||
#
|
#
|
||||||
# Special
|
# Special
|
||||||
|
|
|
@ -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());
|
auto fn = str_fmt("f%llx%s", info.id, suffix.c_str());
|
||||||
if(param->single_html)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,8 +33,6 @@ HTMLRenderer::HTMLRenderer(const Param * param)
|
||||||
,line_buf(this)
|
,line_buf(this)
|
||||||
,image_count(0)
|
,image_count(0)
|
||||||
,param(param)
|
,param(param)
|
||||||
,dest_dir(param->dest_dir)
|
|
||||||
,tmp_dir(param->tmp_dir)
|
|
||||||
{
|
{
|
||||||
//disable error function of poppler
|
//disable error function of poppler
|
||||||
setErrorCallback(&dummy, nullptr);
|
setErrorCallback(&dummy, nullptr);
|
||||||
|
@ -89,7 +87,7 @@ void HTMLRenderer::process(PDFDoc *doc)
|
||||||
{
|
{
|
||||||
if(param->split_pages)
|
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);
|
html_fout.open((char*)page_fn, ofstream::binary);
|
||||||
fix_stream(html_fout);
|
fix_stream(html_fout);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +99,7 @@ void HTMLRenderer::process(PDFDoc *doc)
|
||||||
nullptr, nullptr, &annot_cb, nullptr);
|
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)
|
if(param->single_html)
|
||||||
add_tmp_file((char*)fn);
|
add_tmp_file((char*)fn);
|
||||||
|
|
||||||
|
@ -142,15 +140,15 @@ void HTMLRenderer::pre_process()
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* If single-html && split-page
|
* 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
|
* If !single-html
|
||||||
* leave it in dest_dir
|
* leave it in param->dest_dir
|
||||||
*/
|
*/
|
||||||
|
|
||||||
auto fn = (param->single_html && (!param->split_pages))
|
auto fn = (param->single_html && (!param->split_pages))
|
||||||
? str_fmt("%s/__css", tmp_dir.c_str())
|
? str_fmt("%s/__css", param->tmp_dir.c_str())
|
||||||
: str_fmt("%s/%s", dest_dir.c_str(), param->css_filename.c_str());
|
: str_fmt("%s/%s", param->dest_dir.c_str(), param->css_filename.c_str());
|
||||||
|
|
||||||
if(param->single_html && (!param->split_pages))
|
if(param->single_html && (!param->split_pages))
|
||||||
add_tmp_file((char*)fn);
|
add_tmp_file((char*)fn);
|
||||||
|
@ -171,7 +169,7 @@ void HTMLRenderer::pre_process()
|
||||||
*
|
*
|
||||||
* Otherwise just generate it
|
* 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);
|
add_tmp_file((char*)fn);
|
||||||
|
|
||||||
html_path = (char*)fn;
|
html_path = (char*)fn;
|
||||||
|
@ -190,11 +188,11 @@ void HTMLRenderer::post_process()
|
||||||
if(param->split_pages)
|
if(param->split_pages)
|
||||||
return;
|
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);
|
fix_stream(output);
|
||||||
|
|
||||||
// apply manifest
|
// 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;
|
bool embed_string = false;
|
||||||
string line;
|
string line;
|
||||||
|
@ -218,7 +216,7 @@ void HTMLRenderer::post_process()
|
||||||
|
|
||||||
if(line[0] == '@')
|
if(line[0] == '@')
|
||||||
{
|
{
|
||||||
embed_file(output, PDF2HTMLEX_DATA_PATH + "/" + line.substr(1), "", true);
|
embed_file(output, param->data_dir + "/" + line.substr(1), "", true);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,11 +257,11 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state)
|
||||||
{
|
{
|
||||||
if(param->single_html)
|
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
|
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;
|
cerr << "Remove temporary file: " << fn << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(tmp_dir.c_str());
|
remove(param->tmp_dir.c_str());
|
||||||
if(param->debug)
|
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)
|
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)
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ string HTMLRenderer::dump_embedded_font (GfxFont * font, long long fn_id)
|
||||||
|
|
||||||
obj.streamReset();
|
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);
|
add_tmp_file(filepath);
|
||||||
|
|
||||||
ofstream outf(filepath, ofstream::binary);
|
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
|
// 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);
|
add_tmp_file((char*)fn);
|
||||||
|
|
||||||
ff_save((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",
|
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());
|
info.id, param->font_suffix.c_str());
|
||||||
|
|
||||||
if(param->single_html)
|
if(param->single_html)
|
||||||
|
|
|
@ -364,7 +364,6 @@ class HTMLRenderer : public OutputDev
|
||||||
int image_count;
|
int image_count;
|
||||||
|
|
||||||
const Param * param;
|
const Param * param;
|
||||||
std::string dest_dir, tmp_dir;
|
|
||||||
std::ofstream html_fout, css_fout;
|
std::ofstream html_fout, css_fout;
|
||||||
std::string html_path, css_path;
|
std::string html_path, css_path;
|
||||||
std::set<std::string> tmp_files;
|
std::set<std::string> tmp_files;
|
||||||
|
|
|
@ -20,7 +20,7 @@ struct Param
|
||||||
std::string input_filename, output_filename;
|
std::string input_filename, output_filename;
|
||||||
|
|
||||||
// path
|
// path
|
||||||
std::string dest_dir, tmp_dir;
|
std::string dest_dir, tmp_dir, data_dir;
|
||||||
|
|
||||||
// normal parameters
|
// normal parameters
|
||||||
int first_page, last_page;
|
int first_page, last_page;
|
||||||
|
|
|
@ -53,7 +53,8 @@ void parse_options (int argc, char **argv)
|
||||||
.add("owner-password,o", ¶m.owner_password, "", "owner password (for encrypted files)")
|
.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("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("first-page,f", ¶m.first_page, 1, "first page to process")
|
||||||
.add("last-page,l", ¶m.last_page, numeric_limits<int>::max(), "last page to process")
|
.add("last-page,l", ¶m.last_page, numeric_limits<int>::max(), "last page to process")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user