Skip to content

Commit 094253f

Browse files
Merge pull request #20082 from calixteman/fix_firefox_printing
Use the canvas context from mozPrintCallback when printing a pdf from the Firefox viewer
2 parents 2e0f1ec + 1c15ba7 commit 094253f

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/display/api.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,12 +1182,14 @@ class PDFDocumentProxy {
11821182
* Page render parameters.
11831183
*
11841184
* @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.
11911193
* @property {PageViewport} viewport - Rendering viewport obtained by calling
11921194
* the `PDFPageProxy.getViewport` method.
11931195
* @property {string} [intent] - Rendering intent, can be 'display', 'print',
@@ -1503,6 +1505,7 @@ class PDFPageProxy {
15031505
// Only include the required properties, and *not* the entire object.
15041506
params: {
15051507
canvas,
1508+
canvasContext,
15061509
viewport,
15071510
transform,
15081511
background,
@@ -3148,6 +3151,7 @@ class InternalRenderTask {
31483151
this._scheduleNextBound = this._scheduleNext.bind(this);
31493152
this._nextBound = this._next.bind(this);
31503153
this._canvas = params.canvas;
3154+
this._canvasContext = params.canvas ? null : params.canvasContext;
31513155
this._enableHWA = enableHWA;
31523156
}
31533157

@@ -3180,10 +3184,14 @@ class InternalRenderTask {
31803184
}
31813185
const { viewport, transform, background } = this.params;
31823186

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+
});
31873195

31883196
this.gfx = new CanvasGraphics(
31893197
canvasContext,

web/firefox_print_service.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ function composePage(
7272
currentRenderTask = null;
7373
}
7474
const renderContext = {
75-
canvas: ctx.canvas,
75+
canvasContext: ctx,
76+
canvas: null,
7677
transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
7778
viewport: pdfPage.getViewport({ scale: 1, rotation: size.rotation }),
7879
intent: "print",

0 commit comments

Comments
 (0)