1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-07 18:30:34 +00:00

show warning when file cannot be opened

This commit is contained in:
Lu Wang 2012-09-14 14:53:24 +08:00
parent 2e2382c446
commit 4a5c3e1d3e
2 changed files with 24 additions and 5 deletions

View File

@ -23,7 +23,11 @@ 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(param->tmp_dir + "/" + (char*)fn, ifstream::binary)) << "'"; auto path = param->tmp_dir + "/" + (char*)fn;
ifstream fin(path, ifstream::binary);
if(!fin)
throw "Cannot locate font file: " + path;
css_fout << "'data:font/" + fontfileformat + ";base64," << base64stream(fin) << "'";
} }
else else
{ {

View File

@ -193,6 +193,8 @@ void HTMLRenderer::post_process()
// apply manifest // apply manifest
ifstream manifest_fin((char*)str_fmt("%s/%s", param->data_dir.c_str(), MANIFEST_FILENAME.c_str())); ifstream manifest_fin((char*)str_fmt("%s/%s", param->data_dir.c_str(), MANIFEST_FILENAME.c_str()));
if(!manifest_fin)
throw "Cannot open the manifest file";
bool embed_string = false; bool embed_string = false;
string line; string line;
@ -228,7 +230,10 @@ void HTMLRenderer::post_process()
} }
else if (line == "$pages") else if (line == "$pages")
{ {
output << ifstream(html_path, ifstream::binary).rdbuf(); ifstream fin(html_path, ifstream::binary);
if(!fin)
throw "Cannot open read the pages";
output << fin.rdbuf();
} }
else else
{ {
@ -257,7 +262,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%x.png", param->tmp_dir.c_str(), pageNum) , ifstream::binary)) << "'"; auto path = str_fmt("%s/p%x.png", param->tmp_dir.c_str(), pageNum);
ifstream fin((char*)path, ifstream::binary);
if(!fin)
throw string("Cannot read background image ") + (char*)path;
html_fout << "'data:image/png;base64," << base64stream(fin) << "'";
} }
else else
{ {
@ -346,8 +355,11 @@ void HTMLRenderer::embed_file(ostream & out, const string & path, const string &
if(param->single_html) if(param->single_html)
{ {
ifstream fin(path, ifstream::binary);
if(!fin)
throw string("Cannot open file for embedding: ") + path;
out << iter->second.first << endl out << iter->second.first << endl
<< ifstream(path, ifstream::binary).rdbuf() << fin.rdbuf()
<< iter->second.second << endl; << iter->second.second << endl;
} }
else else
@ -358,7 +370,10 @@ void HTMLRenderer::embed_file(ostream & out, const string & path, const string &
if(copy) if(copy)
{ {
ofstream(param->dest_dir + "/" + fn, ofstream::binary) << ifstream(path, ifstream::binary).rdbuf(); ifstream fin(path, ifstream::binary);
if(!fin)
throw string("Cannot copy file: ") + path;
ofstream(param->dest_dir + "/" + fn, ofstream::binary) << fin.rdbuf();
} }
} }
} }