1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 23:28:06 +02:00

Ensure that PDFPageProxy.pageSizeInches handles non-default /Rotate entries correctly

Without this patch, the pageSize will be incorrectly reported for some PDF files.

---

Move pageSizeInches to ui_utils
This commit is contained in:
Jonas Jenwald 2018-03-19 17:27:04 +01:00
parent 0d391daccc
commit d547936827
5 changed files with 56 additions and 25 deletions

View file

@ -13,7 +13,9 @@
* limitations under the License.
*/
import { cloneObj, getPDFFileNameFromURL, NullL10n } from './ui_utils';
import {
cloneObj, getPageSizeInches, getPDFFileNameFromURL, NullL10n
} from './ui_utils';
import { createPromiseCapability } from 'pdfjs-lib';
const DEFAULT_FIELD_CONTENT = '-';
@ -92,7 +94,7 @@ class PDFDocumentProperties {
this._parseDate(info.CreationDate),
this._parseDate(info.ModDate),
this.pdfDocument.getPage(currentPageNumber).then((pdfPage) => {
return this._parsePageSize(pdfPage.pageSizeInches);
return this._parsePageSize(getPageSizeInches(pdfPage));
}),
]);
}).then(([info, metadata, fileName, fileSize, creationDate, modDate,

View file

@ -269,6 +269,27 @@ function roundToDivide(x, div) {
return r === 0 ? x : Math.round(x - r + div);
}
/**
* Gets the size of the specified page, converted from PDF units to inches.
* @param {Object} An Object containing the properties: {Array} `view`,
* {number} `userUnit`, and {number} `rotate`.
* @return {Object} An Object containing the properties: {number} `width`
* and {number} `height`, given in inches.
*/
function getPageSizeInches({ view, userUnit, rotate, }) {
const [x1, y1, x2, y2] = view;
// We need to take the page rotation into account as well.
const changeOrientation = rotate % 180 !== 0;
const width = (x2 - x1) / 72 * userUnit;
const height = (y2 - y1) / 72 * userUnit;
return {
width: (changeOrientation ? height : width),
height: (changeOrientation ? width : height),
};
}
/**
* Generic helper to find out what elements are visible within a scroll pane.
*/
@ -645,6 +666,7 @@ export {
parseQueryString,
getVisibleElements,
roundToDivide,
getPageSizeInches,
approximateFraction,
getOutputScale,
scrollIntoView,