1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00

use img instead of background-image for better printing

This commit is contained in:
Lu Wang 2013-03-01 13:24:29 +08:00
parent 0bafee4a03
commit 34a53f9d14
4 changed files with 26 additions and 21 deletions

View File

@ -112,12 +112,17 @@
-moz-transform-origin:0% 0%;
-webkit-transform-origin:0% 0%;
-o-transform-origin:0% 0%;
background-position:0 0;
background-repeat:no-repeat;
}
.@CSS_PAGE_CONTENT_BOX_CN@.opened { /* used by pdf2htmlEX.js, to show/hide pages */
display:block;
}
.@CSS_BACKGROUND_IMAGE_CN@ {
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
}
@media print {
.@CSS_PAGE_DECORATION_CN@ {
margin:0;

View File

@ -110,7 +110,7 @@ void HTMLRenderer::process(PDFDoc *doc)
if(param->process_nontext)
{
auto fn = str_fmt("%s/p%x.png", (param->single_html ? param->tmp_dir : param->dest_dir).c_str(), i);
auto fn = str_fmt("%s/bg%x.png", (param->single_html ? param->tmp_dir : param->dest_dir).c_str(), i);
if(param->single_html)
tmp_files.add((char*)fn);
@ -174,31 +174,27 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
<< "\" data-page-no=\"" << pageNum << "\">"
<< "<div class=\"" << CSS::PAGE_CONTENT_BOX_CN
<< " " << CSS::PAGE_CONTENT_BOX_CN << pageNum
<< "\" style=\"";
<< "\">";
if(param->process_nontext)
{
f_pages.fs << "background-image:url(";
f_pages.fs << "<img class=\"" << CSS::BACKGROUND_IMAGE_CN
<< "\" alt=\"\" src=\"";
if(param->single_html)
{
if(param->single_html)
{
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;
f_pages.fs << "'data:image/png;base64," << base64stream(fin) << "'";
}
else
{
f_pages.fs << str_fmt("p%x.png", pageNum);
}
auto path = str_fmt("%s/bg%x.png", param->tmp_dir.c_str(), pageNum);
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_pages.fs << ");";
bgimage_size_manager.install(pageNum, state->getPageWidth(), state->getPageHeight());
else
{
f_pages.fs << str_fmt("bg%x.png", pageNum);
}
f_pages.fs << "\"/>";
}
f_pages.fs << "\">";
reset_state();
}

View File

@ -14,6 +14,8 @@ set(CSS_PAGE_FRAME_CN "pf") # page frame
set(CSS_PAGE_CONTENT_BOX_CN "pc") # page content
set(CSS_PAGE_DATA_CN "pi") # page info
set(CSS_BACKGROUND_IMAGE_CN "bi") # background image
set(CSS_FONT_FAMILY_CN "ff") # font family
set(CSS_FONT_SIZE_CN "fs") # font size

View File

@ -35,6 +35,8 @@ const char * const PAGE_FRAME_CN = "@CSS_PAGE_FRAME_CN@";
const char * const PAGE_CONTENT_BOX_CN = "@CSS_PAGE_CONTENT_BOX_CN@";
const char * const PAGE_DATA_CN = "@CSS_PAGE_DATA_CN@";
const char * const BACKGROUND_IMAGE_CN = "@CSS_BACKGROUND_IMAGE_CN@";
const char * const FONT_FAMILY_CN = "@CSS_FONT_FAMILY_CN@";
const char * const FONT_SIZE_CN = "@CSS_FONT_SIZE_CN@";
const char * const FILL_COLOR_CN = "@CSS_FILL_COLOR_CN@";