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

[api-minor] Add support for PageLabels in the API #6803

Merged
merged 2 commits into from
Jan 20, 2016
Merged

[api-minor] Add support for PageLabels in the API #6803

merged 2 commits into from
Jan 20, 2016

Conversation

Snuffleupagus
Copy link
Collaborator

This PR adds support for PageLabels in the API.

TODO:

  • Decide if we actually want this feature in PDF.js.
  • Hook this functionality into the viewer.
  • Add unit-tests.
  • Improve the code (I hacked this together quickly while having a slight fever, so improvements should be possible :)

Re: #3165 and https://bugzilla.mozilla.org/show_bug.cgi?id=793632.

@timvandermeij
Copy link
Contributor

I definitely think that this would be a nice feature to include in PDF.js, especially since it is used in practice and test cases are available. I usually see this kind of page numbering in e-books.

With regards to hooking this into the viewer, we must look into how other readers handle this in their page number box, i.e., if a user enters page 1, will he arrive at the page with page label 1 or at the first page of the document?

I have added some comments to improve the code, but overall it's already looking good. I really like the minimal changes required to re-use the NameTree structure for the NumberTree structure.


switch (style) {
case 'D':
currentLabel = '' + currentIndex;
Copy link
Contributor

Choose a reason for hiding this comment

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

When we reset the label at the end of the loop, we might be able to simplify this to currentLabel += currentIndex, according to a quick fiddle I made at https://jsfiddle.net/evyujauw/1/.

@timvandermeij
Copy link
Contributor

There has been some discussion about this on IRC, starting here: http://logs.glob.uno/?c=mozilla%23pdfjs#c43831

The API for this appears fine, but we need to carefully determine how to hook this into the viewer. Adobe's behavior can be confusing, so we need to implement this in a way that makes more sense. Let's think about ideas to realize this.

@yurydelendik
Copy link
Contributor

I'm thinking there is mistake at "Uppercase letters (A to Z for the first 26 pages, AA to ZZ for the next 26, and so on) " at http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#page=383&zoom=100,-178,800

I'm thinking they meant "... AA to ZZ for the next 26*26 (676)... " -- it goes as AA, AB, ... AZ, BA, ... ZZ

@Snuffleupagus
Copy link
Collaborator Author

I'm thinking they meant "... AA to ZZ for the next 26*26 (676)... " -- it goes as AA, AB, ... AZ, BA, ... ZZ

You might think so, but that's not how it's implemented in Adobe Reader, which seems to follow the specification to the letter (sorry, couldn't resist the pun :-).
I've modified a long document (the PDF spec) to use that kind of page labels, please see https://www.dropbox.com/s/9z7e37sydrrxvb0/PDF_spec.pdf?dl=1 (but beware of the file size, I wasn't able to compress it well enough).

@yurydelendik
Copy link
Contributor

Oh, wow! That's so .... unorthodox.

@Snuffleupagus
Copy link
Collaborator Author

Given that the API/core parts of this are pretty self-contained, and have unit-tests, could we consider landing this as-is and then figure out how/if we should wire this into the default viewer in a follow-up?

In my opinion, having the ability to at least fetch pageLabels in the API seems like a good thing regardless of what we decide to do for the default viewer.

@Snuffleupagus Snuffleupagus changed the title [WIP][api-minor] Add support for PageLabels in the API [api-minor] Add support for PageLabels in the API Jan 7, 2016
@Snuffleupagus
Copy link
Collaborator Author

The test commit was removed, the following code can be used in the console to fetch the pageLabels:

PDFViewerApplication.pdfDocument.getPageLabels().then(function (labels) {
  console.log(labels);
});


var romanStr = romanBuf.join('');
return (lowerCase ? romanStr.toLowerCase() : romanStr);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This line does not appear to be indented correctly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Whoops, fixed now. Thanks for spotting this.

@timvandermeij
Copy link
Contributor

Could you rebase this patch and fix the comment above? We can land the API first and file a follow-up issue for hooking it into the viewer: see http://logs.glob.uno/?c=mozilla%23pdfjs&s=28+Dec+2015&e=28+Dec+2015&h=api#c43853.

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/de07095a1154df9/output.txt

@timvandermeij
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/ec6c40bf43540bd/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://107.22.172.223:8877/868e91673424a49/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/ec6c40bf43540bd/output.txt

Total script time: 21.37 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/868e91673424a49/output.txt

Total script time: 21.49 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

timvandermeij added a commit that referenced this pull request Jan 20, 2016
[api-minor] Add support for PageLabels in the API
@timvandermeij timvandermeij merged commit 58329f7 into mozilla:master Jan 20, 2016
@timvandermeij
Copy link
Contributor

This API looks really good! I'll file a follow-up issue for deciding if/how we want to hook this into the viewer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants