mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
[api-minor] Add basic support for PageLayout in the API and the viewer
Please see the specification, https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G6.2393749, and refer to the inline comments for additional details.
This commit is contained in:
parent
57abddc9ca
commit
7a999d1d67
5 changed files with 85 additions and 2 deletions
32
web/app.js
32
web/app.js
|
@ -889,6 +889,8 @@ let PDFViewerApplication = {
|
|||
|
||||
// Since the `setInitialView` call below depends on this being resolved,
|
||||
// fetch it early to avoid delaying initial rendering of the PDF document.
|
||||
const pageLayoutPromise = pdfDocument.getPageLayout().catch(
|
||||
function() { /* Avoid breaking initial rendering; ignoring errors. */ });
|
||||
const pageModePromise = pdfDocument.getPageMode().catch(
|
||||
function() { /* Avoid breaking initial rendering; ignoring errors. */ });
|
||||
const openActionDestPromise = pdfDocument.getOpenActionDestination().catch(
|
||||
|
@ -934,8 +936,8 @@ let PDFViewerApplication = {
|
|||
}).catch(() => { /* Unable to read from storage; ignoring errors. */ });
|
||||
|
||||
Promise.all([
|
||||
storePromise, pageModePromise, openActionDestPromise,
|
||||
]).then(async ([values = {}, pageMode, openActionDest]) => {
|
||||
storePromise, pageLayoutPromise, pageModePromise, openActionDestPromise,
|
||||
]).then(async ([values = {}, pageLayout, pageMode, openActionDest]) => {
|
||||
const viewOnLoad = AppOptions.get('viewOnLoad');
|
||||
|
||||
this._initializePdfHistory({
|
||||
|
@ -974,6 +976,9 @@ let PDFViewerApplication = {
|
|||
if (pageMode && sidebarView === SidebarView.UNKNOWN) {
|
||||
sidebarView = apiPageModeToSidebarView(pageMode);
|
||||
}
|
||||
if (pageLayout && spreadMode === SpreadMode.UNKNOWN) {
|
||||
spreadMode = apiPageLayoutToSpreadMode(pageLayout);
|
||||
}
|
||||
|
||||
this.setInitialView(hash, {
|
||||
rotation, sidebarView, scrollMode, spreadMode,
|
||||
|
@ -2434,6 +2439,29 @@ function webViewerKeyDown(evt) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts API PageLayout values to the format used by `PDFViewer`.
|
||||
* NOTE: This is supported to the extent that the viewer implements the
|
||||
* necessary Scroll/Spread modes (since SinglePage, TwoPageLeft,
|
||||
* and TwoPageRight all suggests using non-continuous scrolling).
|
||||
* @param {string} mode - The API PageLayout value.
|
||||
* @returns {number} A value from {SpreadMode}.
|
||||
*/
|
||||
function apiPageLayoutToSpreadMode(layout) {
|
||||
switch (layout) {
|
||||
case 'SinglePage':
|
||||
case 'OneColumn':
|
||||
return SpreadMode.NONE;
|
||||
case 'TwoColumnLeft':
|
||||
case 'TwoPageLeft':
|
||||
return SpreadMode.ODD;
|
||||
case 'TwoColumnRight':
|
||||
case 'TwoPageRight':
|
||||
return SpreadMode.EVEN;
|
||||
}
|
||||
return SpreadMode.NONE; // Default value.
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts API PageMode values to the format used by `PDFSidebar`.
|
||||
* NOTE: There's also a "FullScreen" parameter which is not possible to support,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue