Skip to content

Commit dc61272

Browse files
committed
tmp image then move; remove debug output
1 parent b2bfeb5 commit dc61272

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

pdf2htmlEX/share/pdf2htmlEX.js.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,11 @@ Viewer.prototype = {
343343
var image = images[i];
344344
(function(image) {
345345
image.addEventListener('error', function() {
346-
console.debug('image load error, retry in 1s', image);
347346
setTimeout(function() {
348-
console.debug('retrying image load', image);
349347
image.src = image.src;
350348
}, 1000);
351349
});
352350
})(image);
353-
console.debug('image reload', image);
354351
image.src = image.src;
355352
}
356353
}

pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ bool CairoBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
130130
if (doc->getPageRotate(pageno) == 90 || doc->getPageRotate(pageno) == 270)
131131
std::swap(page_height, page_width);
132132

133-
string fn = (char*)html_renderer->str_fmt("%s/bg%x.svg", (param.embed_image ? param.tmp_dir : param.dest_dir).c_str(), pageno);
134-
if(param.embed_image)
135-
html_renderer->tmp_files.add(fn);
133+
134+
std::string 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());
135+
std::string fn = html_renderer->str_fmt("%s/bg%x.%s", (param.embed_image ? param.tmp_dir : param.dest_dir).c_str(), pageno, format.c_str());
136136

137-
surface = cairo_svg_surface_create(fn.c_str(), page_width * param.actual_dpi / DEFAULT_DPI, page_height * param.actual_dpi / DEFAULT_DPI);
137+
surface = cairo_svg_surface_create(tmp_fn.c_str(), page_width * param.actual_dpi / DEFAULT_DPI, page_height * param.actual_dpi / DEFAULT_DPI);
138138
cairo_svg_surface_restrict_to_version(surface, CAIRO_SVG_VERSION_1_2);
139139
cairo_surface_set_fallback_resolution(surface, param.actual_dpi, param.actual_dpi);
140140

@@ -174,15 +174,14 @@ bool CairoBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
174174
{
175175
int n = 0;
176176
char c;
177-
ifstream svgfile(fn);
177+
ifstream svgfile(tmp_fn);
178178
//count of '<' in the file should be an approximation of node count.
179179
while(svgfile >> c)
180180
{
181181
if (c == '<')
182182
++n;
183183
if (n > param.svg_node_count_limit)
184184
{
185-
html_renderer->tmp_files.add(fn);
186185
return false;
187186
}
188187
}
@@ -192,6 +191,11 @@ bool CairoBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
192191
for (auto id : bitmaps_in_current_page)
193192
++bitmaps_ref_count[id];
194193

194+
std::rename(tmp_fn.c_str(), fn.c_str());
195+
196+
if(param.embed_image)
197+
html_renderer->tmp_files.add(fn);
198+
195199
return true;
196200
}
197201

pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ bool SplashBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
114114

115115
auto * bitmap = getBitmap();
116116

117-
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());
118-
if(param.embed_image)
119-
html_renderer->tmp_files.add((const char *)fn);
117+
std::string 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());
118+
std::string fn = html_renderer->str_fmt("%s/bg%x.%s", (param.embed_image ? param.tmp_dir : param.dest_dir).c_str(), pageno, format.c_str());
120119

121120
SplashImageFileFormat splashImageFileFormat;
122121
if(format == "png")
@@ -126,10 +125,15 @@ bool SplashBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
126125
else
127126
throw string("Image format not supported: ") + format;
128127

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

132+
std::rename(tmp_fn.c_str(), fn.c_str());
133+
134+
if(param.embed_image)
135+
html_renderer->tmp_files.add(fn);
136+
133137
return true;
134138
}
135139

0 commit comments

Comments
 (0)