diff --git a/3rdparty/poppler/git/CairoOutputDev.h b/3rdparty/poppler/git/CairoOutputDev.h
index c9ae33d..727c687 100644
--- a/3rdparty/poppler/git/CairoOutputDev.h
+++ b/3rdparty/poppler/git/CairoOutputDev.h
@@ -272,7 +272,7 @@ protected:
cairo_filter_t getFilterForSurface(cairo_surface_t *image,
GBool interpolate);
GBool getStreamData (Stream *str, char **buffer, int *length);
- void setMimeData(Stream *str, Object *ref, cairo_surface_t *image);
+ virtual void setMimeData(Stream *str, Object *ref, cairo_surface_t *image);
void fillToStrokePathClip(GfxState *state);
void alignStrokeCoords(GfxSubpath *subpath, int i, double *x, double *y);
diff --git a/src/BackgroundRenderer/CairoBackgroundRenderer.cc b/src/BackgroundRenderer/CairoBackgroundRenderer.cc
index 4f30305..795336a 100644
--- a/src/BackgroundRenderer/CairoBackgroundRenderer.cc
+++ b/src/BackgroundRenderer/CairoBackgroundRenderer.cc
@@ -19,8 +19,7 @@
namespace pdf2htmlEX {
-using std::string;
-using std::ifstream;
+using namespace std;
CairoBackgroundRenderer::CairoBackgroundRenderer(HTMLRenderer * html_renderer, const Param & param)
: CairoOutputDev()
@@ -29,6 +28,15 @@ CairoBackgroundRenderer::CairoBackgroundRenderer(HTMLRenderer * html_renderer, c
, surface(nullptr)
{ }
+CairoBackgroundRenderer::~CairoBackgroundRenderer()
+{
+ for(auto i = bitmaps_ref_count.begin(); i != bitmaps_ref_count.end(); ++i)
+ {
+ if (i->second == 0)
+ html_renderer->tmp_files.add(this->get_bitmap_path(i->first));
+ }
+}
+
void CairoBackgroundRenderer::drawChar(GfxState *state, double x, double y,
double dx, double dy,
double originX, double originY,
@@ -86,6 +94,8 @@ bool CairoBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
cairo_t * cr = cairo_create(surface);
setCairo(cr);
+ bitmaps_in_current_page.resize(0);
+
bool process_annotation = param.process_annotation;
doc->displayPage(this, pageno, param.h_dpi, param.v_dpi,
0,
@@ -131,6 +141,10 @@ bool CairoBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
}
}
+ // the svg file is actually used, so add its bitmaps' ref count.
+ for (auto i = bitmaps_in_current_page.begin(); i != bitmaps_in_current_page.end(); i++)
+ ++bitmaps_ref_count[*i];
+
return true;
}
@@ -138,7 +152,19 @@ void CairoBackgroundRenderer::embed_image(int pageno)
{
auto & f_page = *(html_renderer->f_curpage);
- f_page << "
or background-image can't have external resources;
+ // SVGs introduced by