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

Implement core support for named actions, and some viewer functionality #3057

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
2 changes: 2 additions & 0 deletions src/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,8 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
}
data.url = url;
data.dest = action.get('D');
} else if (linkType === 'Named') {
data.action = action.get('N').name;
} else {
TODO('unrecognized link type: ' + linkType);
}
Expand Down
53 changes: 52 additions & 1 deletion web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,53 @@ var PageView = function pageView(container, id, scale,
};
link.className = 'internalLink';
}
function bindNamedAction(link, action) {
link.onclick = function pageViewSetupNamedActionOnClick() {
// See PDF reference, table 8.45 - Named action
console.log('Click with action', action);
switch (action) {
case 'GoToPage':
document.getElementById('pageNumber').focus();
break;

case 'GoBack':
PDFHistory.back();
// TODO implement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove TODO

break;

case 'GoForward':
PDFHistory.forward();
// TODO implement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove TODO

break;

case 'Find':
PDFFindBar.toggle();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep the supported-integrated find check: if is not supported allow to toggle internal find bar, if it's supported do nothing

break;

case 'NextPage':
PDFView.page++;
break;

case 'PrevPage':
PDFView.page--;
break;

case 'LastPage':
PDFView.page = PDFView.pages.length;
break;

case 'FirstPage':
PDFView.page = 1;
break;

default:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add 'break' after the comment below or delete default branch

// No action according to spec
}

return false;
};
link.className = 'internalLink';
}

pdfPage.getAnnotations().then(function(annotationsData) {
viewport = viewport.clone({ dontFlip: true });
Expand Down Expand Up @@ -2460,7 +2507,11 @@ var PageView = function pageView(container, id, scale,
CustomStyle.setProp('transformOrigin', element, transformOriginStr);

if (data.subtype === 'Link' && !data.url) {
bindLink(element, ('dest' in data) ? data.dest : null);
if (data.action) {
bindNamedAction(element, data.action);
} else {
bindLink(element, ('dest' in data) ? data.dest : null);
}
}

annotationsDiv.appendChild(element);
Expand Down