@@ -111,66 +111,54 @@ bool SplashBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
111
111
(!(param.use_cropbox )),
112
112
false , false ,
113
113
nullptr , nullptr , &annot_cb, &process_annotation);
114
+
115
+ auto * bitmap = getBitmap ();
116
+
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);
120
+
121
+ SplashImageFileFormat splashImageFileFormat;
122
+ if (format == " png" )
123
+ splashImageFileFormat = splashFormatPng;
124
+ else if (format == " jpg" )
125
+ splashImageFileFormat = splashFormatJpeg;
126
+ else
127
+ throw string (" Image format not supported: " ) + format;
128
+
129
+ SplashError e = bitmap->writeImgFile (splashImageFileFormat, (const char *)fn, param.actual_dpi , param.actual_dpi );
130
+ if (e != splashOk)
131
+ throw string (" Cannot write background image. SplashErrorCode: " ) + std::to_string (e);
132
+
114
133
return true ;
115
134
}
116
135
117
136
void SplashBackgroundRenderer::embed_image (int pageno)
118
137
{
119
- auto * bitmap = getBitmap ();
120
- // dump the background image only when it is not empty
121
- if (bitmap->getWidth () >= 0 && bitmap->getHeight () >= 0 )
138
+ auto & f_page = *(html_renderer->f_curpage );
139
+
140
+ f_page << " <img class=\" " << CSS::FULL_BACKGROUND_IMAGE_CN
141
+ << " \" alt=\"\" src=\" " ;
142
+
143
+ if (param.embed_image )
144
+ {
145
+ auto path = html_renderer->str_fmt (" %s/bg%x.%s" , param.tmp_dir .c_str (), pageno, format.c_str ());
146
+ ifstream fin ((char *)path, ifstream::binary);
147
+ if (!fin)
148
+ throw string (" Cannot read background image " ) + (char *)path;
149
+
150
+ auto iter = FORMAT_MIME_TYPE_MAP.find (format);
151
+ if (iter == FORMAT_MIME_TYPE_MAP.end ())
152
+ throw string (" Image format not supported: " ) + format;
153
+
154
+ string mime_type = iter->second ;
155
+ f_page << " data:" << mime_type << " ;base64," << Base64Stream (fin);
156
+ }
157
+ else
122
158
{
123
- {
124
- 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 ());
125
- if (param.embed_image )
126
- html_renderer->tmp_files .add ((const char *)fn);
127
-
128
- SplashImageFileFormat splashImageFileFormat;
129
- if (format == " png" )
130
- splashImageFileFormat = splashFormatPng;
131
- else if (format == " jpg" )
132
- splashImageFileFormat = splashFormatJpeg;
133
- else
134
- throw string (" Image format not supported: " ) + format;
135
-
136
- SplashError e = bitmap->writeImgFile (splashImageFileFormat, (const char *)fn, param.actual_dpi , param.actual_dpi );
137
- if (e != splashOk)
138
- throw string (" Cannot write background image. SplashErrorCode: " ) + std::to_string (e);
139
- }
140
-
141
- double h_scale = html_renderer->text_zoom_factor () * DEFAULT_DPI / param.actual_dpi ;
142
- double v_scale = html_renderer->text_zoom_factor () * DEFAULT_DPI / param.actual_dpi ;
143
-
144
- auto & f_page = *(html_renderer->f_curpage );
145
- auto & all_manager = html_renderer->all_manager ;
146
-
147
- f_page << " <img class=\" " << CSS::BACKGROUND_IMAGE_CN
148
- << " " << CSS::LEFT_CN << all_manager.left .install (0 .0L )
149
- << " " << CSS::BOTTOM_CN << all_manager.bottom .install (0 .0L )
150
- << " " << CSS::WIDTH_CN << all_manager.width .install (h_scale * bitmap->getWidth ())
151
- << " " << CSS::HEIGHT_CN << all_manager.height .install (v_scale * bitmap->getHeight ())
152
- << " \" alt=\"\" src=\" " ;
153
-
154
- if (param.embed_image )
155
- {
156
- auto path = html_renderer->str_fmt (" %s/bg%x.%s" , param.tmp_dir .c_str (), pageno, format.c_str ());
157
- ifstream fin ((char *)path, ifstream::binary);
158
- if (!fin)
159
- throw string (" Cannot read background image " ) + (char *)path;
160
-
161
- auto iter = FORMAT_MIME_TYPE_MAP.find (format);
162
- if (iter == FORMAT_MIME_TYPE_MAP.end ())
163
- throw string (" Image format not supported: " ) + format;
164
-
165
- string mime_type = iter->second ;
166
- f_page << " data:" << mime_type << " ;base64," << Base64Stream (fin);
167
- }
168
- else
169
- {
170
- f_page << (char *)html_renderer->str_fmt (" bg%x.%s" , pageno, format.c_str ());
171
- }
172
- f_page << " \" />" ;
159
+ f_page << (char *)html_renderer->str_fmt (" bg%x.%s" , pageno, format.c_str ());
173
160
}
161
+ f_page << " \" />" ;
174
162
}
175
163
176
164
} // namespace pdf2htmlEX
0 commit comments