-
Notifications
You must be signed in to change notification settings - Fork 10k
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 support for FileAttachment annotations #6988
Implement support for FileAttachment annotations #6988
Conversation
931c6f1
to
2568dc1
Compare
Sure, I'll try to review this as soon as possible! |
var pdfUrl = combineUrl(window.location.href, | ||
'../pdfs/annotation-fileattachment.pdf'); | ||
loadingTask = PDFJS.getDocument(pdfUrl); | ||
waitsForPromiseResolved(loadingTask.promise, function(pdfDocument) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small suggestion, to make this code a bit simpler. Remember that you can chain promises, i.e. this could instead become:
waitsForPromiseResolved(loadingTask.promise, function (pdfDocument) {
return pdfDocument.getPage(1).then(function (pdfPage) {
return pdfPage.getAnnotations().then(function (pdfAnnotations) {
annotations = pdfAnnotations;
});
});
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this, but unfortunately it does not seem to work. If I don't explicitly use waitsForPromiseResolved
everywhere, the annotations
variable is undefined when we reach the unit test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this?
waitsForPromiseResolved(loadingTask.promise, function (pdfDocument) {
return pdfDocument.getPage(1).then(function (pdfPage) {
return pdfPage.getAnnotations().then(function (pdfAnnotations) {
annotations = pdfAnnotations;
return Promise.resolve();
});
});
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's really strange, but that does not work either. This is the result:
TEST-UNEXPECTED-FAIL | should correctly parse a file attachment | TypeError: annotations is undefined in http://127.0.0.1:63625/test/unit/annotation_layer_spec.js (line 215)
There is #6905 for replacing waitsForPromiseResolved
when we upgrade Jasmine, so maybe we can live with it for now.
I did some quick testing with the PDF file from https://bugzilla.mozilla.org/show_bug.cgi?id=1230933, and it appears that there are some edge-cases left to handle. For example, the annotation icons doesn't show up, and the file names have weird initial characters (e.g Also, two quick observations when comparing with Adobe Reader.
|
It seems the answer is no :-(
The missing icons here are probably connected with missing |
Thank you for the thorough checks! Do you mean that we should not move the |
In https://github.com/mozilla/pdf.js/blob/master/web/annotation_layer_builder.js#L62, we're passing in a
Yes, note how it's not included in Firefox: https://github.com/mozilla/pdf.js/blob/master/web/viewer.js#L61-L63. |
Oh, I see now! Thanks, I'll make the necessary adjustment for this PR soon. |
9c564a0
to
f9785f2
Compare
I'm going over your feedback to make sure I addressed it all:
Could you check the commits again? |
@@ -757,7 +757,8 @@ var PDFViewer = (function pdfViewer() { | |||
return new AnnotationLayerBuilder({ | |||
pageDiv: pageDiv, | |||
pdfPage: pdfPage, | |||
linkService: this.linkService | |||
linkService: this.linkService, | |||
downloadManager: new DownloadManager() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too sure that this will work with the viewer components.
You probably need to add PDFJS.DownloadManager = DownloadManager;
to https://github.com/mozilla/pdf.js/blob/master/web/pdf_viewer.component.js, and pass in a new DownloadManager()
when initializing PDFViewer
, instead of initializing it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in the new commit. Since I'm not too familiar with the components, could you check if this works? I ran node make generic components
and inspected the code. I see the DownloadManager
class there now, so I think this will work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still wondering if it wouldn't make more sense to pass it into PDFViewer
, similar to this: https://github.com/mozilla/pdf.js/blob/master/web/pdf_viewer.js#L42. And the do (in PDFViewer
), this.downloadManager = options.downloadManager || null;
The reason for asking is that DownloadManager
won't be available in the pageviewer
component (the LinkService
is stubbed out too, so I wouldn't worry about that).
Similarily, you probably want to check that it's defined before calling it here: https://github.com/mozilla/pdf.js/pull/6988/files#diff-1097e3b131ba22f8e8a6c2f20e3ab5ecR786.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I should be done like you suggested in the new commit.
909fcd4
to
91e55be
Compare
This is required to be able to use it in the annotation display code, where we now apply it to sanitize the filename of the FileAttachment annotation. The PDF file from https://bugzilla.mozilla.org/show_bug.cgi?id=1230933 has shown that some PDF generators include the path of the file rather than the filename, which causes filenames with weird initial characters. PDF viewers handle this differently (for example Foxit Reader just replaces forward slashes with spaces), but we think it's better to only show the filename as intended. Additionally we add unit tests for the `getFilenameFromUrl` helper function.
5bf670b
to
0351c7e
Compare
@Snuffleupagus Yes, sorry for the delay on this. I have implemented and tested your two ideas and they look really good. I have also updated the patch to do the same as 266cedd did. |
/botio-linux preview |
From: Bot.io (Linux)ReceivedCommand cmd_preview from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/dba2a25c1982c7a/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/dba2a25c1982c7a/output.txt Total script time: 0.93 mins Published |
/botio test |
From: Bot.io (Linux)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/eb88712052ad642/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://107.22.172.223:8877/d35d3b1fc907736/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/d35d3b1fc907736/output.txt Total script time: 20.44 mins
|
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/eb88712052ad642/output.txt Total script time: 21.84 mins
|
Looks good, thank you for the patch! /botio makeref |
From: Bot.io (Windows)ReceivedCommand cmd_makeref from @Snuffleupagus received. Current queue size: 0 Live output at: http://107.22.172.223:8877/509eeb6d2acb2a1/output.txt |
From: Bot.io (Linux)ReceivedCommand cmd_makeref from @Snuffleupagus received. Current queue size: 0 Live output at: http://107.21.233.14:8877/315e64df63bf6ad/output.txt |
Implement support for FileAttachment annotations
From: Bot.io (Linux)FailedFull output at http://107.21.233.14:8877/315e64df63bf6ad/output.txt Total script time: 13.78 mins
|
/botio-linux makeref |
From: Bot.io (Linux)ReceivedCommand cmd_makeref from @Snuffleupagus received. Current queue size: 0 Live output at: http://107.21.233.14:8877/f08d181bcc678a8/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/509eeb6d2acb2a1/output.txt Total script time: 19.80 mins
|
From: Bot.io (Linux)FailedFull output at http://107.21.233.14:8877/f08d181bcc678a8/output.txt Total script time: 13.76 mins
|
/botio-linux makeref |
From: Bot.io (Linux)ReceivedCommand cmd_makeref from @Snuffleupagus received. Current queue size: 0 Live output at: http://107.21.233.14:8877/7248b3cbd0f6f3c/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/7248b3cbd0f6f3c/output.txt Total script time: 21.02 mins
|
Actually, I'm not sure if this would be too difficult to implement :-) However, very recently, I started re-factoring the sidebar code since it seemed in need of some clean-up. The current state of this work is available here: master...Snuffleupagus:PDFSidebar. |
Thank you for reviewing this! I have opened a new issue for tracking the sidebar feature. |
Fixes #6276.
The file from the unit testing commit can be used for testing, as well as the file in #6276 and the extra file I attach here (thanks to Terry Corbet for providing it): FileAtt_ex_3.8_01.pdf
@Snuffleupagus Since you were so kind to review my previous annotation layer PRs, would you be have time to review this one too? If not, feel free to unassign yourself.