@@ -134,8 +134,8 @@ def _get_metadata(self):
134
134
return get_html_metadata (self .wrapper_element , self .base_url )
135
135
136
136
def render (self , stylesheets = None , enable_hinting = False ,
137
- presentational_hints = False , font_config = None ,
138
- counter_style = None ):
137
+ presentational_hints = False , optimize_images = False ,
138
+ font_config = None , counter_style = None ):
139
139
"""Lay out and paginate the document, but do not (yet) export it
140
140
to PDF or PNG.
141
141
@@ -158,6 +158,8 @@ def render(self, stylesheets=None, enable_hinting=False,
158
158
:type presentational_hints: bool
159
159
:param presentational_hints: Whether HTML presentational hints are
160
160
followed.
161
+ :type optimize_images: bool
162
+ :param optimize_images: Try to optimize the size of embedded images.
161
163
:type font_config: :class:`~fonts.FontConfiguration`
162
164
:param font_config: A font configuration handling ``@font-face`` rules.
163
165
:type counter_style: :class:`~css.counters.CounterStyle`
@@ -167,11 +169,11 @@ def render(self, stylesheets=None, enable_hinting=False,
167
169
"""
168
170
return Document ._render (
169
171
self , stylesheets , enable_hinting , presentational_hints ,
170
- font_config , counter_style )
172
+ optimize_images , font_config , counter_style )
171
173
172
174
def write_pdf (self , target = None , stylesheets = None , zoom = 1 ,
173
175
attachments = None , presentational_hints = False ,
174
- font_config = None , counter_style = None ):
176
+ optimize_images = False , font_config = None , counter_style = None ):
175
177
"""Render the document to a PDF file.
176
178
177
179
This is a shortcut for calling :meth:`render`, then
@@ -199,6 +201,8 @@ def write_pdf(self, target=None, stylesheets=None, zoom=1,
199
201
:type presentational_hints: bool
200
202
:param presentational_hints: Whether HTML presentational hints are
201
203
followed.
204
+ :type optimize_images: bool
205
+ :param optimize_images: Try to optimize the size of embedded images.
202
206
:type font_config: :class:`~fonts.FontConfiguration`
203
207
:param font_config: A font configuration handling ``@font-face`` rules.
204
208
:type counter_style: :class:`~css.counters.CounterStyle`
@@ -212,12 +216,12 @@ def write_pdf(self, target=None, stylesheets=None, zoom=1,
212
216
return self .render (
213
217
stylesheets , enable_hinting = False ,
214
218
presentational_hints = presentational_hints ,
215
- font_config = font_config , counter_style = counter_style ). write_pdf (
216
- target , zoom , attachments )
219
+ optimize_images = optimize_images , font_config = font_config ,
220
+ counter_style = counter_style ). write_pdf ( target , zoom , attachments )
217
221
218
222
def write_image_surface (self , stylesheets = None , resolution = 96 ,
219
- presentational_hints = False , font_config = None ,
220
- counter_style = None ):
223
+ presentational_hints = False , optimize_images = False ,
224
+ font_config = None , counter_style = None ):
221
225
"""Render pages vertically on a cairo image surface.
222
226
223
227
.. versionadded:: 0.17
@@ -242,6 +246,8 @@ def write_image_surface(self, stylesheets=None, resolution=96,
242
246
:type presentational_hints: bool
243
247
:param presentational_hints: Whether HTML presentational hints are
244
248
followed.
249
+ :type optimize_images: bool
250
+ :param optimize_images: Try to optimize the size of embedded images.
245
251
:type font_config: :class:`~fonts.FontConfiguration`
246
252
:param font_config: A font configuration handling ``@font-face`` rules.
247
253
:type counter_style: :class:`~css.counters.CounterStyle`
@@ -250,15 +256,16 @@ def write_image_surface(self, stylesheets=None, resolution=96,
250
256
251
257
"""
252
258
surface , _width , _height = (
253
- self .render (stylesheets , enable_hinting = True ,
254
- presentational_hints = presentational_hints ,
255
- font_config = font_config )
259
+ self .render (
260
+ stylesheets , enable_hinting = True ,
261
+ presentational_hints = presentational_hints ,
262
+ font_config = font_config , optimize_images = optimize_images )
256
263
.write_image_surface (resolution ))
257
264
return surface
258
265
259
266
def write_png (self , target = None , stylesheets = None , resolution = 96 ,
260
- presentational_hints = False , font_config = None ,
261
- counter_style = None ):
267
+ presentational_hints = False , optimize_images = False ,
268
+ font_config = None , counter_style = None ):
262
269
"""Paint the pages vertically to a single PNG image.
263
270
264
271
There is no decoration around pages other than those specified in CSS
@@ -284,6 +291,8 @@ def write_png(self, target=None, stylesheets=None, resolution=96,
284
291
:type presentational_hints: bool
285
292
:param presentational_hints: Whether HTML presentational hints are
286
293
followed.
294
+ :type optimize_images: bool
295
+ :param optimize_images: Try to optimize the size of embedded images.
287
296
:type font_config: :class:`~fonts.FontConfiguration`
288
297
:param font_config: A font configuration handling ``@font-face`` rules.
289
298
:type counter_style: :class:`~css.counters.CounterStyle`
@@ -298,7 +307,8 @@ def write_png(self, target=None, stylesheets=None, resolution=96,
298
307
self .render (
299
308
stylesheets , enable_hinting = True ,
300
309
presentational_hints = presentational_hints ,
301
- font_config = font_config , counter_style = counter_style )
310
+ optimize_images = optimize_images , font_config = font_config ,
311
+ counter_style = counter_style )
302
312
.write_png (target , resolution ))
303
313
return png_bytes
304
314
0 commit comments