Skip to content

Commit

Permalink
remove js reload; remove tmp image
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Jan 5, 2025
1 parent 41c3300 commit f55e7ec
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
16 changes: 0 additions & 16 deletions pdf2htmlEX/share/pdf2htmlEX.js.in
Original file line number Diff line number Diff line change
Expand Up @@ -335,22 +335,6 @@ Viewer.prototype = {

this.initialize_radio_button();
this.render();

{
// deal with delayed image loading
var images = document.getElementsByTagName('img');
for (var i = 0; i < images.length; i++) {
var image = images[i];
(function(image) {
image.addEventListener('error', function() {
setTimeout(function() {
image.src = image.src;
}, 1000);
});
})(image);
image.src = image.src;
}
}
},

/*
Expand Down
7 changes: 2 additions & 5 deletions pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ bool CairoBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
if (doc->getPageRotate(pageno) == 90 || doc->getPageRotate(pageno) == 270)
std::swap(page_height, page_width);

auto tmp_fn = html_renderer->str_fmt("%s/tmp_bg%x.svg", (param.embed_image ? param.tmp_dir : param.dest_dir).c_str(), pageno);
auto fn = html_renderer->str_fmt("%s/bg%x.svg", (param.embed_image ? param.tmp_dir : param.dest_dir).c_str(), pageno);

surface = cairo_svg_surface_create((const char *)tmp_fn, page_width * param.actual_dpi / DEFAULT_DPI, page_height * param.actual_dpi / DEFAULT_DPI);
surface = cairo_svg_surface_create((const char *)fn, page_width * param.actual_dpi / DEFAULT_DPI, page_height * param.actual_dpi / DEFAULT_DPI);
cairo_svg_surface_restrict_to_version(surface, CAIRO_SVG_VERSION_1_2);
cairo_surface_set_fallback_resolution(surface, param.actual_dpi, param.actual_dpi);

Expand Down Expand Up @@ -173,7 +172,7 @@ bool CairoBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
{
int n = 0;
char c;
ifstream svgfile((const char *)tmp_fn);
ifstream svgfile((const char *)fn);
//count of '<' in the file should be an approximation of node count.
while(svgfile >> c)
{
Expand All @@ -190,8 +189,6 @@ bool CairoBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
for (auto id : bitmaps_in_current_page)
++bitmaps_ref_count[id];

std::rename((const char *)tmp_fn, (const char *)fn);

if(param.embed_image)
html_renderer->tmp_files.add((const char *)fn);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ bool SplashBackgroundRenderer::render_page(PDFDoc * doc, int pageno)

auto * bitmap = getBitmap();

auto tmp_fn = html_renderer->str_fmt("%s/tmp_bg%x.%s", (param.embed_image ? param.tmp_dir : param.dest_dir).c_str(), pageno, format.c_str());
auto fn = html_renderer->str_fmt("%s/bg%x.%s", (param.embed_image ? param.tmp_dir : param.dest_dir).c_str(), pageno, format.c_str());

SplashImageFileFormat splashImageFileFormat;
Expand All @@ -125,12 +124,10 @@ bool SplashBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
else
throw string("Image format not supported: ") + format;

SplashError e = bitmap->writeImgFile(splashImageFileFormat, (const char *)tmp_fn, param.actual_dpi, param.actual_dpi);
SplashError e = bitmap->writeImgFile(splashImageFileFormat, (const char *)fn, param.actual_dpi, param.actual_dpi);
if (e != splashOk)
throw string("Cannot write background image. SplashErrorCode: ") + std::to_string(e);

std::rename((const char *)tmp_fn, (const char *)fn);

if(param.embed_image)
html_renderer->tmp_files.add((const char *)fn);

Expand Down

0 comments on commit f55e7ec

Please sign in to comment.