Printing canvases at PDF document size.
This commit is contained in:
parent
9b3a91f365
commit
29947b5a57
@ -546,22 +546,18 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
var pdfPage = this.pdfPage;
|
var pdfPage = this.pdfPage;
|
||||||
|
|
||||||
var viewport = pdfPage.getViewport(1);
|
var viewport = pdfPage.getViewport(1);
|
||||||
// Use the same hack we use for high dpi displays for printing to get
|
|
||||||
// better output until bug 811002 is fixed in FF.
|
|
||||||
var PRINT_OUTPUT_SCALE = 2;
|
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
|
|
||||||
// The logical size of the canvas.
|
// The size of the canvas in pixels for printing.
|
||||||
canvas.width = Math.floor(viewport.width) * PRINT_OUTPUT_SCALE;
|
var PRINT_RESOLUTION = 150;
|
||||||
canvas.height = Math.floor(viewport.height) * PRINT_OUTPUT_SCALE;
|
var PRINT_UNITS = PRINT_RESOLUTION / 72.0;
|
||||||
|
canvas.width = Math.floor(viewport.width * PRINT_UNITS);
|
||||||
|
canvas.height = Math.floor(viewport.height * PRINT_UNITS);
|
||||||
|
|
||||||
// The rendered size of the canvas, relative to the size of canvasWrapper.
|
// The physical size of the canvas as specified by the PDF document.
|
||||||
canvas.style.width = (PRINT_OUTPUT_SCALE * 100) + '%';
|
canvas.style.width = Math.floor(viewport.width * CSS_UNITS) + 'px';
|
||||||
|
canvas.style.height = Math.floor(viewport.height * CSS_UNITS) + 'px';
|
||||||
var cssScale = 'scale(' + (1 / PRINT_OUTPUT_SCALE) + ', ' +
|
|
||||||
(1 / PRINT_OUTPUT_SCALE) + ')';
|
|
||||||
CustomStyle.setProp('transform' , canvas, cssScale);
|
|
||||||
CustomStyle.setProp('transformOrigin' , canvas, '0% 0%');
|
|
||||||
|
|
||||||
var canvasWrapper = document.createElement('div');
|
var canvasWrapper = document.createElement('div');
|
||||||
canvasWrapper.appendChild(canvas);
|
canvasWrapper.appendChild(canvas);
|
||||||
@ -574,15 +570,10 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
ctx.fillStyle = 'rgb(255, 255, 255)';
|
ctx.fillStyle = 'rgb(255, 255, 255)';
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
//#if !(MOZCENTRAL || FIREFOX)
|
|
||||||
// Used by the mozCurrentTransform polyfill in src/display/canvas.js.
|
|
||||||
ctx._transformMatrix =
|
|
||||||
[PRINT_OUTPUT_SCALE, 0, 0, PRINT_OUTPUT_SCALE, 0, 0];
|
|
||||||
//#endif
|
|
||||||
ctx.scale(PRINT_OUTPUT_SCALE, PRINT_OUTPUT_SCALE);
|
|
||||||
|
|
||||||
var renderContext = {
|
var renderContext = {
|
||||||
canvasContext: ctx,
|
canvasContext: ctx,
|
||||||
|
transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
|
||||||
viewport: viewport,
|
viewport: viewport,
|
||||||
intent: 'print'
|
intent: 'print'
|
||||||
};
|
};
|
||||||
|
@ -1,12 +1,4 @@
|
|||||||
<div id="mozPrintCallback-shim" hidden>
|
<div id="mozPrintCallback-shim" hidden>
|
||||||
<style>
|
|
||||||
@media print {
|
|
||||||
#printContainer div {
|
|
||||||
page-break-after: always;
|
|
||||||
page-break-inside: avoid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
#mozPrintCallback-shim {
|
#mozPrintCallback-shim {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
@ -1810,8 +1810,11 @@ html[dir='rtl'] #documentPropertiesOverlay .row > * {
|
|||||||
position: relative;
|
position: relative;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
height: 100%;
|
width: 1px;
|
||||||
overflow: hidden;
|
height: 1px;
|
||||||
|
overflow: visible;
|
||||||
|
page-break-after: always;
|
||||||
|
page-break-inside: avoid;
|
||||||
}
|
}
|
||||||
#printContainer canvas {
|
#printContainer canvas {
|
||||||
display: block;
|
display: block;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user