mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
dump empty frames for split-pages
This commit is contained in:
parent
69d083b27b
commit
dd41565c3c
@ -39,11 +39,6 @@ pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({
|
||||
container_id : 'page-container',
|
||||
sidebar_id : 'sidebar',
|
||||
outline_id : 'outline',
|
||||
page_urls : [
|
||||
"""
|
||||
$page_urls
|
||||
"""
|
||||
]
|
||||
});
|
||||
</script>
|
||||
"""
|
||||
|
@ -308,8 +308,6 @@ protected:
|
||||
|
||||
Preprocessor preprocessor;
|
||||
TmpFiles tmp_files;
|
||||
// for splitted pages
|
||||
std::vector<std::string> page_filenames;
|
||||
|
||||
// for string formatting
|
||||
StringFormatter str_fmt;
|
||||
@ -318,6 +316,8 @@ protected:
|
||||
std::ofstream fs;
|
||||
std::string path;
|
||||
} f_outline, f_pages, f_css;
|
||||
std::ofstream * f_curpage;
|
||||
std::string cur_page_filename;
|
||||
|
||||
static const std::string MANIFEST_FILENAME;
|
||||
};
|
||||
|
@ -370,50 +370,50 @@ void HTMLRenderer::css_draw_rectangle(double x, double y, double w, double h, co
|
||||
}
|
||||
}
|
||||
|
||||
f_pages.fs << "<div class=\"" << CSS::CSS_DRAW_CN
|
||||
(*f_curpage) << "<div class=\"" << CSS::CSS_DRAW_CN
|
||||
<< ' ' << CSS::TRANSFORM_MATRIX_CN << all_manager.transform_matrix.install(new_tm)
|
||||
<< "\" style=\"";
|
||||
|
||||
if(line_color)
|
||||
{
|
||||
f_pages.fs << "border-color:" << *line_color << ";";
|
||||
(*f_curpage) << "border-color:" << *line_color << ";";
|
||||
|
||||
f_pages.fs << "border-width:";
|
||||
(*f_curpage) << "border-width:";
|
||||
for(int i = 0; i < line_width_count; ++i)
|
||||
{
|
||||
if(i > 0) f_pages.fs << ' ';
|
||||
if(i > 0) (*f_curpage) << ' ';
|
||||
|
||||
double lw = line_width_array[i] * scale;
|
||||
f_pages.fs << round(lw);
|
||||
if(is_positive(lw)) f_pages.fs << "px";
|
||||
(*f_curpage) << round(lw);
|
||||
if(is_positive(lw)) (*f_curpage) << "px";
|
||||
}
|
||||
f_pages.fs << ";";
|
||||
(*f_curpage) << ";";
|
||||
}
|
||||
else
|
||||
{
|
||||
f_pages.fs << "border:none;";
|
||||
(*f_curpage) << "border:none;";
|
||||
}
|
||||
|
||||
if(fill_color)
|
||||
{
|
||||
f_pages.fs << "background-color:" << (*fill_color) << ";";
|
||||
(*f_curpage) << "background-color:" << (*fill_color) << ";";
|
||||
}
|
||||
else
|
||||
{
|
||||
f_pages.fs << "background-color:transparent;";
|
||||
(*f_curpage) << "background-color:transparent;";
|
||||
}
|
||||
|
||||
if(style_function)
|
||||
{
|
||||
style_function(style_function_data, f_pages.fs);
|
||||
style_function(style_function_data, (*f_curpage));
|
||||
}
|
||||
|
||||
f_pages.fs << "bottom:" << round(y) << "px;"
|
||||
(*f_curpage) << "bottom:" << round(y) << "px;"
|
||||
<< "left:" << round(x) << "px;"
|
||||
<< "width:" << round(w * scale) << "px;"
|
||||
<< "height:" << round(h * scale) << "px;";
|
||||
|
||||
f_pages.fs << "\"></div>";
|
||||
(*f_curpage) << "\"></div>";
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,12 +112,12 @@ void HTMLRenderer::process(PDFDoc *doc)
|
||||
{
|
||||
string filled_template_filename = (char*)str_fmt(param.page_filename.c_str(), i);
|
||||
auto page_fn = str_fmt("%s/%s", param.dest_dir.c_str(), filled_template_filename.c_str());
|
||||
f_pages.fs.open((char*)page_fn, ofstream::binary);
|
||||
if(!f_pages.fs)
|
||||
f_curpage = new ofstream((char*)page_fn, ofstream::binary);
|
||||
if(!(*f_curpage))
|
||||
throw string("Cannot open ") + (char*)page_fn + " for writing";
|
||||
set_stream_flags(f_pages.fs);
|
||||
set_stream_flags((*f_curpage));
|
||||
|
||||
page_filenames.push_back(filled_template_filename);
|
||||
cur_page_filename = filled_template_filename;
|
||||
}
|
||||
|
||||
if(param.process_nontext)
|
||||
@ -139,7 +139,8 @@ void HTMLRenderer::process(PDFDoc *doc)
|
||||
|
||||
if(param.split_pages)
|
||||
{
|
||||
f_pages.fs.close();
|
||||
delete f_curpage;
|
||||
f_curpage = nullptr;
|
||||
}
|
||||
}
|
||||
if(page_count >= 0)
|
||||
@ -180,7 +181,7 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
|
||||
|
||||
long long wid = all_manager.width.install(pageWidth);
|
||||
long long hid = all_manager.height.install(pageHeight);
|
||||
f_pages.fs
|
||||
(*f_curpage)
|
||||
<< "<div class=\"" << CSS::PAGE_DECORATION_CN
|
||||
<< " " << CSS::WIDTH_CN << wid
|
||||
<< " " << CSS::HEIGHT_CN << hid
|
||||
@ -192,9 +193,29 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
|
||||
<< " " << CSS::PAGE_CONTENT_BOX_CN << pageNum
|
||||
<< "\">";
|
||||
|
||||
/*
|
||||
* When split_pages is on, f_curpage points to the current page file
|
||||
* and we want to output empty frames in f_pages.fs
|
||||
*/
|
||||
if(param.split_pages)
|
||||
{
|
||||
f_pages.fs
|
||||
<< "<div class=\"" << CSS::PAGE_DECORATION_CN
|
||||
<< " " << CSS::WIDTH_CN << wid
|
||||
<< " " << CSS::HEIGHT_CN << hid
|
||||
<< "\">"
|
||||
<< "<div id=\"" << CSS::PAGE_FRAME_CN << pageNum
|
||||
<< "\" class=\"" << CSS::PAGE_FRAME_CN
|
||||
<< "\" data-page-no=\"" << pageNum
|
||||
<< "\" data-page-url=\"";
|
||||
|
||||
outputURL(f_pages.fs, cur_page_filename);
|
||||
f_pages.fs << "\">";
|
||||
}
|
||||
|
||||
if(param.process_nontext)
|
||||
{
|
||||
f_pages.fs << "<img class=\"" << CSS::BACKGROUND_IMAGE_CN
|
||||
(*f_curpage) << "<img class=\"" << CSS::BACKGROUND_IMAGE_CN
|
||||
<< "\" alt=\"\" src=\"";
|
||||
if(param.embed_image)
|
||||
{
|
||||
@ -202,13 +223,13 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
|
||||
ifstream fin((char*)path, ifstream::binary);
|
||||
if(!fin)
|
||||
throw string("Cannot read background image ") + (char*)path;
|
||||
f_pages.fs << "data:image/png;base64," << Base64Stream(fin);
|
||||
(*f_curpage) << "data:image/png;base64," << Base64Stream(fin);
|
||||
}
|
||||
else
|
||||
{
|
||||
f_pages.fs << (char*)str_fmt("bg%x.png", pageNum);
|
||||
(*f_curpage) << (char*)str_fmt("bg%x.png", pageNum);
|
||||
}
|
||||
f_pages.fs << "\"/>";
|
||||
(*f_curpage) << "\"/>";
|
||||
}
|
||||
|
||||
reset_state();
|
||||
@ -216,7 +237,7 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
|
||||
|
||||
void HTMLRenderer::endPage() {
|
||||
// dump all text
|
||||
html_text_page.dump_text(f_pages.fs);
|
||||
html_text_page.dump_text(*f_curpage);
|
||||
html_text_page.dump_css(f_css.fs);
|
||||
html_text_page.clear();
|
||||
|
||||
@ -224,26 +245,31 @@ void HTMLRenderer::endPage() {
|
||||
cur_doc->processLinks(this, pageNum);
|
||||
|
||||
// close box
|
||||
f_pages.fs << "</div>";
|
||||
(*f_curpage) << "</div>";
|
||||
|
||||
// dump info for js
|
||||
// TODO: create a function for this
|
||||
// BE CAREFUL WITH ESCAPES
|
||||
f_pages.fs << "<div class=\"" << CSS::PAGE_DATA_CN << "\" data-data='{";
|
||||
(*f_curpage) << "<div class=\"" << CSS::PAGE_DATA_CN << "\" data-data='{";
|
||||
|
||||
//default CTM
|
||||
f_pages.fs << "\"ctm\":[";
|
||||
(*f_curpage) << "\"ctm\":[";
|
||||
for(int i = 0; i < 6; ++i)
|
||||
{
|
||||
if(i > 0) f_pages.fs << ",";
|
||||
f_pages.fs << round(default_ctm[i]);
|
||||
if(i > 0) (*f_curpage) << ",";
|
||||
(*f_curpage) << round(default_ctm[i]);
|
||||
}
|
||||
f_pages.fs << "]";
|
||||
(*f_curpage) << "]";
|
||||
|
||||
f_pages.fs << "}'></div>";
|
||||
(*f_curpage) << "}'></div>";
|
||||
|
||||
// close page
|
||||
(*f_curpage) << "</div></div>" << endl;
|
||||
|
||||
if(param.split_pages)
|
||||
{
|
||||
f_pages.fs << "</div></div>" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void HTMLRenderer::pre_process(PDFDoc * doc)
|
||||
@ -324,9 +350,6 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
|
||||
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)
|
||||
{
|
||||
/*
|
||||
* we have to keep the html file for pages into a temporary place
|
||||
@ -343,6 +366,15 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
|
||||
throw string("Cannot open ") + (char*)fn + " for writing";
|
||||
set_stream_flags(f_pages.fs);
|
||||
}
|
||||
|
||||
if(param.split_pages)
|
||||
{
|
||||
f_curpage = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
f_curpage = &f_pages.fs;
|
||||
}
|
||||
}
|
||||
|
||||
void HTMLRenderer::post_process(void)
|
||||
@ -435,8 +467,6 @@ void HTMLRenderer::post_process(void)
|
||||
}
|
||||
}
|
||||
else if (line == "$pages")
|
||||
{
|
||||
if(!param.split_pages)
|
||||
{
|
||||
ifstream fin(f_pages.path, ifstream::binary);
|
||||
if(!fin)
|
||||
@ -444,18 +474,6 @@ void HTMLRenderer::post_process(void)
|
||||
output << fin.rdbuf();
|
||||
output.clear(); // output will set fail bit if fin is empty
|
||||
}
|
||||
}
|
||||
else if (line == "$page_urls")
|
||||
{
|
||||
for(auto iter = page_filenames.begin(); iter != page_filenames.end(); ++iter)
|
||||
{
|
||||
if(iter != page_filenames.begin())
|
||||
output << ",";
|
||||
output << "'";
|
||||
outputJSON(output, *iter);
|
||||
output << "'";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "Warning: manifest line " << line_no << ": Unknown content \"" << line << "\"" << endl;
|
||||
|
@ -195,17 +195,17 @@ void HTMLRenderer::processLink(AnnotLink * al)
|
||||
|
||||
if(!dest_str.empty())
|
||||
{
|
||||
f_pages.fs << "<a class=\"" << CSS::LINK_CN << "\" href=\"";
|
||||
outputURL(f_pages.fs, dest_str);
|
||||
f_pages.fs << "\"";
|
||||
(*f_curpage) << "<a class=\"" << CSS::LINK_CN << "\" href=\"";
|
||||
outputURL((*f_curpage), dest_str);
|
||||
(*f_curpage) << "\"";
|
||||
|
||||
if(!dest_detail_str.empty())
|
||||
f_pages.fs << " data-dest-detail='" << dest_detail_str << "'";
|
||||
(*f_curpage) << " data-dest-detail='" << dest_detail_str << "'";
|
||||
|
||||
f_pages.fs << ">";
|
||||
(*f_curpage) << ">";
|
||||
}
|
||||
|
||||
f_pages.fs << "<div class=\"" << CSS::CSS_DRAW_CN << ' ' << CSS::TRANSFORM_MATRIX_CN
|
||||
(*f_curpage) << "<div class=\"" << CSS::CSS_DRAW_CN << ' ' << CSS::TRANSFORM_MATRIX_CN
|
||||
<< all_manager.transform_matrix.install(default_ctm)
|
||||
<< "\" style=\"";
|
||||
|
||||
@ -232,31 +232,31 @@ void HTMLRenderer::processLink(AnnotLink * al)
|
||||
border_top_bottom_width, border_left_right_width);
|
||||
|
||||
if(abs(border_top_bottom_width - border_left_right_width) < EPS)
|
||||
f_pages.fs << "border-width:" << round(border_top_bottom_width) << "px;";
|
||||
(*f_curpage) << "border-width:" << round(border_top_bottom_width) << "px;";
|
||||
else
|
||||
f_pages.fs << "border-width:" << round(border_top_bottom_width) << "px " << round(border_left_right_width) << "px;";
|
||||
(*f_curpage) << "border-width:" << round(border_top_bottom_width) << "px " << round(border_left_right_width) << "px;";
|
||||
}
|
||||
auto style = border->getStyle();
|
||||
switch(style)
|
||||
{
|
||||
case AnnotBorder::borderSolid:
|
||||
f_pages.fs << "border-style:solid;";
|
||||
(*f_curpage) << "border-style:solid;";
|
||||
break;
|
||||
case AnnotBorder::borderDashed:
|
||||
f_pages.fs << "border-style:dashed;";
|
||||
(*f_curpage) << "border-style:dashed;";
|
||||
break;
|
||||
case AnnotBorder::borderBeveled:
|
||||
f_pages.fs << "border-style:outset;";
|
||||
(*f_curpage) << "border-style:outset;";
|
||||
break;
|
||||
case AnnotBorder::borderInset:
|
||||
f_pages.fs << "border-style:inset;";
|
||||
(*f_curpage) << "border-style:inset;";
|
||||
break;
|
||||
case AnnotBorder::borderUnderlined:
|
||||
f_pages.fs << "border-style:none;border-bottom-style:solid;";
|
||||
(*f_curpage) << "border-style:none;border-bottom-style:solid;";
|
||||
break;
|
||||
default:
|
||||
cerr << "Warning:Unknown annotation border style: " << style << endl;
|
||||
f_pages.fs << "border-style:solid;";
|
||||
(*f_curpage) << "border-style:solid;";
|
||||
}
|
||||
|
||||
|
||||
@ -274,36 +274,36 @@ void HTMLRenderer::processLink(AnnotLink * al)
|
||||
r = g = b = 0;
|
||||
}
|
||||
|
||||
f_pages.fs << "border-color:rgb("
|
||||
(*f_curpage) << "border-color:rgb("
|
||||
<< dec << (int)dblToByte(r) << "," << (int)dblToByte(g) << "," << (int)dblToByte(b) << hex
|
||||
<< ");";
|
||||
}
|
||||
else
|
||||
{
|
||||
f_pages.fs << "border-style:none;";
|
||||
(*f_curpage) << "border-style:none;";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
f_pages.fs << "border-style:none;";
|
||||
(*f_curpage) << "border-style:none;";
|
||||
}
|
||||
|
||||
tm_transform(default_ctm, x, y);
|
||||
|
||||
f_pages.fs << "position:absolute;"
|
||||
(*f_curpage) << "position:absolute;"
|
||||
<< "left:" << round(x) << "px;"
|
||||
<< "bottom:" << round(y) << "px;"
|
||||
<< "width:" << round(w) << "px;"
|
||||
<< "height:" << round(h) << "px;";
|
||||
|
||||
// fix for IE
|
||||
f_pages.fs << "background-color:rgba(255,255,255,0.000001);";
|
||||
(*f_curpage) << "background-color:rgba(255,255,255,0.000001);";
|
||||
|
||||
f_pages.fs << "\"></div>";
|
||||
(*f_curpage) << "\"></div>";
|
||||
|
||||
if(dest_str != "")
|
||||
{
|
||||
f_pages.fs << "</a>";
|
||||
(*f_curpage) << "</a>";
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user