mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
new parameter for outline
This commit is contained in:
parent
b7ffd969e5
commit
e0c859188e
@ -42,7 +42,7 @@ new pdf2htmlEX.Viewer('pdf-main');
|
||||
<div id="pdf-outline">
|
||||
"""
|
||||
|
||||
$outlines
|
||||
$outline
|
||||
|
||||
"""
|
||||
</div>
|
||||
|
@ -434,7 +434,7 @@ class HTMLRenderer : public OutputDev
|
||||
struct {
|
||||
std::ofstream fs;
|
||||
std::string path;
|
||||
} f_pages, f_css, f_outlines;
|
||||
} f_outline, f_pages, f_css;
|
||||
|
||||
static const std::string MANIFEST_FILENAME;
|
||||
};
|
||||
|
@ -294,20 +294,41 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
|
||||
if(param->single_html && (!param->split_pages))
|
||||
tmp_files.add((char*)fn);
|
||||
|
||||
f_css.path = (char*)fn,
|
||||
f_css.path = (char*)fn;
|
||||
f_css.fs.open(f_css.path, ofstream::binary);
|
||||
if(!f_css.fs)
|
||||
throw string("Cannot open ") + (char*)fn + " for writing";
|
||||
set_stream_flags(f_css.fs);
|
||||
}
|
||||
|
||||
{
|
||||
/*
|
||||
* The logic for outline is similar to css
|
||||
*/
|
||||
|
||||
auto fn = (param->single_html && (!param->split_pages))
|
||||
? str_fmt("%s/__outline", param->tmp_dir.c_str())
|
||||
: str_fmt("%s/%s", param->dest_dir.c_str(), param->outline_filename.c_str());
|
||||
|
||||
if(param->single_html && (!param->split_pages))
|
||||
tmp_files.add((char*)fn);
|
||||
|
||||
f_outline.path = (char*)fn;
|
||||
f_outline.fs.open(f_outline.path, ofstream::binary);
|
||||
if(!f_outline.fs)
|
||||
throw string("Cannot open") + (char*)fn + " for writing";
|
||||
|
||||
// might not be necessary
|
||||
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)
|
||||
{
|
||||
/*
|
||||
* If single-html
|
||||
* we have to keep the html file (for page) into a temporary place
|
||||
* we have to keep the html file for pages into a temporary place
|
||||
* because we'll have to embed css before it
|
||||
*
|
||||
* Otherwise just generate it
|
||||
@ -326,6 +347,7 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
|
||||
void HTMLRenderer::post_process()
|
||||
{
|
||||
// close files
|
||||
f_outline.fs.close();
|
||||
f_pages.fs.close();
|
||||
f_css.fs.close();
|
||||
|
||||
@ -379,6 +401,13 @@ void HTMLRenderer::post_process()
|
||||
{
|
||||
embed_file(output, f_css.path, ".css", false);
|
||||
}
|
||||
else if (line == "$outline")
|
||||
{
|
||||
ifstream fin(f_outline.path, ifstream::binary);
|
||||
if(!fin)
|
||||
throw "Cannot open read the pages";
|
||||
output << fin.rdbuf();
|
||||
}
|
||||
else if (line == "$pages")
|
||||
{
|
||||
ifstream fin(f_pages.path, ifstream::binary);
|
||||
|
@ -63,6 +63,7 @@ struct Param
|
||||
* Output
|
||||
*/
|
||||
std::string css_filename;
|
||||
std::string outline_filename;
|
||||
|
||||
/*
|
||||
* Debug
|
||||
|
@ -101,6 +101,7 @@ void parse_options (int argc, char **argv)
|
||||
.add("font-format", ¶m.font_format, "opentype", "format for extracted font files")
|
||||
.add("external-hint-tool", ¶m.external_hint_tool, "", "external tool for hintting fonts.(overrides --auto-hint)")
|
||||
.add("css-filename", ¶m.css_filename, "", "Specify the file name of the generated css file")
|
||||
.add("outline-filename", ¶m.outline_filename, "", "Specify the file name of the generated outline file")
|
||||
|
||||
.add("debug", ¶m.debug, 0, "output debug information")
|
||||
.add("clean-tmp", ¶m.clean_tmp, 1, "clean temporary files after processing")
|
||||
@ -202,7 +203,7 @@ int main(int argc, char **argv)
|
||||
param.first_page = min<int>(max<int>(param.first_page, 1), doc->getNumPages());
|
||||
param.last_page = min<int>(max<int>(param.last_page, param.first_page), doc->getNumPages());
|
||||
|
||||
if(param.output_filename == "")
|
||||
if(param.output_filename.empty())
|
||||
{
|
||||
const string s = get_filename(param.input_filename);
|
||||
|
||||
@ -223,7 +224,7 @@ int main(int argc, char **argv)
|
||||
|
||||
}
|
||||
}
|
||||
if(param.css_filename == "")
|
||||
if(param.css_filename.empty())
|
||||
{
|
||||
const string s = get_filename(param.input_filename);
|
||||
|
||||
@ -237,6 +238,21 @@ int main(int argc, char **argv)
|
||||
param.css_filename = s + ".css";
|
||||
}
|
||||
}
|
||||
if(param.outline_filename.empty())
|
||||
{
|
||||
const string s = get_filename(param.input_filename);
|
||||
|
||||
if(get_suffix(param.input_filename) == ".pdf")
|
||||
{
|
||||
param.outline_filename = s.substr(0, s.size() - 4) + ".outline";
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!param.split_pages)
|
||||
param.outline_filename = s + ".outline";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
HTMLRenderer * htmlOut = new HTMLRenderer(¶m);
|
||||
htmlOut->process(doc);
|
||||
|
Loading…
Reference in New Issue
Block a user