@@ -1182,12 +1182,14 @@ class PDFDocumentProxy {
1182
1182
* Page render parameters.
1183
1183
*
1184
1184
* @typedef {Object } RenderParameters
1185
- * @property {CanvasRenderingContext2D } canvasContext - Deprecated 2D context of
1186
- * a DOM Canvas object for backwards compatibility; it is recommended to use
1187
- * the `canvas` parameter instead.
1188
- * @property {HTMLCanvasElement } canvas - A DOM Canvas object. The default value
1189
- * is the canvas associated with the `canvasContext` parameter if no value is
1190
- * provided explicitly.
1185
+ * @property {CanvasRenderingContext2D } canvasContext - 2D context of a DOM
1186
+ * Canvas object for backwards compatibility; it is recommended to use the
1187
+ * `canvas` parameter instead.
1188
+ * If the context must absolutely be used to render the page, the canvas must
1189
+ * be null.
1190
+ * @property {HTMLCanvasElement|null } canvas - A DOM Canvas object. The default
1191
+ * value is the canvas associated with the `canvasContext` parameter if no
1192
+ * value is provided explicitly.
1191
1193
* @property {PageViewport } viewport - Rendering viewport obtained by calling
1192
1194
* the `PDFPageProxy.getViewport` method.
1193
1195
* @property {string } [intent] - Rendering intent, can be 'display', 'print',
@@ -1503,6 +1505,7 @@ class PDFPageProxy {
1503
1505
// Only include the required properties, and *not* the entire object.
1504
1506
params : {
1505
1507
canvas,
1508
+ canvasContext,
1506
1509
viewport,
1507
1510
transform,
1508
1511
background,
@@ -3148,6 +3151,7 @@ class InternalRenderTask {
3148
3151
this . _scheduleNextBound = this . _scheduleNext . bind ( this ) ;
3149
3152
this . _nextBound = this . _next . bind ( this ) ;
3150
3153
this . _canvas = params . canvas ;
3154
+ this . _canvasContext = params . canvas ? null : params . canvasContext ;
3151
3155
this . _enableHWA = enableHWA ;
3152
3156
}
3153
3157
@@ -3180,10 +3184,14 @@ class InternalRenderTask {
3180
3184
}
3181
3185
const { viewport, transform, background } = this . params ;
3182
3186
3183
- const canvasContext = this . _canvas . getContext ( "2d" , {
3184
- alpha : false ,
3185
- willReadFrequently : ! this . _enableHWA ,
3186
- } ) ;
3187
+ // When printing in Firefox, we get a specific context in mozPrintCallback
3188
+ // which cannot be created from the canvas itself.
3189
+ const canvasContext =
3190
+ this . _canvasContext ||
3191
+ this . _canvas . getContext ( "2d" , {
3192
+ alpha : false ,
3193
+ willReadFrequently : ! this . _enableHWA ,
3194
+ } ) ;
3187
3195
3188
3196
this . gfx = new CanvasGraphics (
3189
3197
canvasContext ,
0 commit comments