Merge pull request #8043 from Rob--W/issue6696-auto-rotate-page

Allow automatic print rotation via the enablePrintAutoRotate preference
This commit is contained in:
Tim van der Meij 2017-02-08 23:57:28 +01:00 committed by GitHub
commit 573236e3ad
6 changed files with 43 additions and 5 deletions

View File

@ -114,6 +114,12 @@
"renderInteractiveForms": {
"type": "boolean",
"default": false
},
"enablePrintAutoRotate": {
"title": "Automatically rotate printed pages",
"description": "When enabled, pages whose orientation differ from the first page are rotated when printed.",
"type": "boolean",
"default": false
}
}
}

View File

@ -190,6 +190,7 @@ var PDFViewerApplication = {
renderer: 'canvas',
enhanceTextSelection: false,
renderInteractiveForms: false,
enablePrintAutoRotate: false,
},
isViewerEmbedded: (window.parent !== window),
url: '',
@ -304,6 +305,9 @@ var PDFViewerApplication = {
Preferences.get('disablePageLabels').then(function resolved(value) {
self.viewerPrefs['disablePageLabels'] = value;
}),
Preferences.get('enablePrintAutoRotate').then(function resolved(value) {
self.viewerPrefs['enablePrintAutoRotate'] = value;
}),
]).catch(function (reason) { });
},
@ -342,6 +346,7 @@ var PDFViewerApplication = {
renderer: self.viewerPrefs['renderer'],
enhanceTextSelection: self.viewerPrefs['enhanceTextSelection'],
renderInteractiveForms: self.viewerPrefs['renderInteractiveForms'],
enablePrintAutoRotate: self.viewerPrefs['enablePrintAutoRotate'],
});
pdfRenderingQueue.setViewer(self.pdfViewer);
pdfLinkService.setViewer(self.pdfViewer);

View File

@ -15,5 +15,6 @@
"enhanceTextSelection": false,
"renderer": "canvas",
"renderInteractiveForms": false,
"enablePrintAutoRotate": false,
"disablePageLabels": false
}

View File

@ -61,7 +61,7 @@
var renderContext = {
canvasContext: ctx,
transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
viewport: pdfPage.getViewport(1),
viewport: pdfPage.getViewport(1, size.rotation),
intent: 'print'
};
return pdfPage.render(renderContext).promise;

View File

@ -60,7 +60,7 @@
var renderContext = {
canvasContext: ctx,
transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
viewport: pdfPage.getViewport(1),
viewport: pdfPage.getViewport(1, size.rotation),
intent: 'print'
};
return pdfPage.render(renderContext).promise;

View File

@ -81,6 +81,9 @@ var DEFAULT_CACHE_SIZE = 10;
* text selection behaviour. The default is `false`.
* @property {boolean} renderInteractiveForms - (optional) Enables rendering of
* interactive form elements. The default is `false`.
* @property {boolean} enablePrintAutoRotate - (optional) Enables automatic
* rotation of pages whose orientation differ from the first page upon
* printing. The default is `false`.
* @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'.
*/
@ -122,6 +125,10 @@ var PDFViewer = (function pdfViewer() {
return false;
}
function isPortraitOrientation(size) {
return size.width <= size.height;
}
/**
* @constructs PDFViewer
* @param {PDFViewerOptions} options
@ -135,6 +142,7 @@ var PDFViewer = (function pdfViewer() {
this.removePageBorders = options.removePageBorders || false;
this.enhanceTextSelection = options.enhanceTextSelection || false;
this.renderInteractiveForms = options.renderInteractiveForms || false;
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
this.renderer = options.renderer || RendererType.CANVAS;
this.defaultRenderingQueue = !options.renderingQueue;
@ -949,12 +957,30 @@ var PDFViewer = (function pdfViewer() {
/**
* Returns sizes of the pages.
* @returns {Array} Array of objects with width/height fields.
* @returns {Array} Array of objects with width/height/rotation fields.
*/
getPagesOverview: function () {
return this._pages.map(function (pageView) {
var pagesOverview = this._pages.map(function (pageView) {
var viewport = pageView.pdfPage.getViewport(1);
return {width: viewport.width, height: viewport.height};
return {
width: viewport.width,
height: viewport.height,
rotation: viewport.rotation,
};
});
if (!this.enablePrintAutoRotate) {
return pagesOverview;
}
var isFirstPagePortrait = isPortraitOrientation(pagesOverview[0]);
return pagesOverview.map(function (size) {
if (isFirstPagePortrait === isPortraitOrientation(size)) {
return size;
}
return {
width: size.height,
height: size.width,
rotation: (size.rotation + 90) % 360,
};
});
},
};