Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support printing page with different rotation #6103

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extensions/chromium/preferences_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
"useOnlyCssZoom": {
"type": "boolean",
"default": false
},
"disablePrintAutoRotate": {
"type": "boolean",
"default": false
}
}
}
1 change: 1 addition & 0 deletions web/default_preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ var DEFAULT_PREFERENCES = {
disableTextLayer: false,
useOnlyCssZoom: false,
externalLinkTarget: 0,
disablePrintAutoRotate: false,
};
23 changes: 18 additions & 5 deletions web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,19 +517,32 @@ var PDFPageView = (function PDFPageViewClosure() {
return promise;
},

beforePrint: function PDFPageView_beforePrint() {
beforePrint: function PDFPageView_beforePrint(isFirstPagePortrait) {
var CustomStyle = PDFJS.CustomStyle;
var pdfPage = this.pdfPage;

var viewport = pdfPage.getViewport(1);

var pageWidth = viewport.width;
var pageHeight = viewport.height;

var isPortrait = pageHeight > pageWidth;
if (!PDFJS.disablePrintAutoRotate && isFirstPagePortrait !== isPortrait) {
// Rotate page by 90deg to make all pages same orientation
var rotate = (pdfPage.rotate + 90) % 360;
pageWidth = viewport.height;
pageHeight = viewport.width;
viewport = pdfPage.getViewport(1, rotate);
}

// 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');

// The logical size of the canvas.
canvas.width = Math.floor(viewport.width) * PRINT_OUTPUT_SCALE;
canvas.height = Math.floor(viewport.height) * PRINT_OUTPUT_SCALE;
canvas.width = Math.floor(pageWidth) * PRINT_OUTPUT_SCALE;
canvas.height = Math.floor(pageHeight) * PRINT_OUTPUT_SCALE;

// The rendered size of the canvas, relative to the size of canvasWrapper.
canvas.style.width = (PRINT_OUTPUT_SCALE * 100) + '%';
Expand All @@ -542,8 +555,8 @@ var PDFPageView = (function PDFPageViewClosure() {

var printContainer = document.getElementById('printContainer');
var canvasWrapper = document.createElement('div');
canvasWrapper.style.width = viewport.width + 'pt';
canvasWrapper.style.height = viewport.height + 'pt';
canvasWrapper.style.width = pageWidth + 'pt';
canvasWrapper.style.height = pageHeight + 'pt';
canvasWrapper.appendChild(canvas);
printContainer.appendChild(canvasWrapper);

Expand Down
11 changes: 10 additions & 1 deletion web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ var PDFViewerApplication = {
}
PDFJS.externalLinkTarget = value;
}),
Preferences.get('disablePrintAutoRotate').then(function resolved(value) {
PDFJS.disablePrintAutoRotate = value;
}),
// TODO move more preferences and other async stuff here
]).catch(function (reason) { });

Expand Down Expand Up @@ -1239,8 +1242,10 @@ var PDFViewerApplication = {
'}';
body.appendChild(this.pageStyleSheet);

var isFirstPagePortrait = pageSize.height > pageSize.width;

for (i = 0, ii = this.pagesCount; i < ii; ++i) {
this.pdfViewer.getPageView(i).beforePrint();
this.pdfViewer.getPageView(i).beforePrint(isFirstPagePortrait);
}

//#if !PRODUCTION
Expand Down Expand Up @@ -1446,6 +1451,10 @@ function webViewerInitialized() {
break;
}
}
if ('disableprintautorotate' in hashParams) {
PDFJS.disablePrintAutoRotate =
(hashParams['disableprintautorotate'] === 'true');
}
if ('pdfbug' in hashParams) {
PDFJS.pdfBug = true;
var pdfBug = hashParams['pdfbug'];
Expand Down