-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Add support for saving forms #12137
Add support for saving forms #12137
Conversation
@timvandermeij, @Snuffleupagus, @brendandahl, I'll add some tests tomorrow but it'd be nice to have a first feedback asap. |
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.
My general comment would be that you'll need to be very careful to not accidentally create a corrupt PDF document when editing it. (Given how much trouble corrupt PDF documents have caused us over the years, we really ought to avoid creating such ones ourselves.)
Furthermore, you'll probably want to test this not only with "simple" and/or well-formed documents, to make sure that things still work with e.g. PDF documents that use XRefStm
s (i.e. cross-reference streams) and/or those where the XRef table is corrupt.
Also, I'm guessing that you may also want to hide the toolbar buttons (or at least have them be disabled
), until editing has occurred!?
Finally, note that as I've remarked inline, you'll need to split the XRef writing part into proper main/worker-thread parts.
Looking good overall, but as Jonas mentioned we need to split up the worker/main thread code more. Or we could move most everything to the worker. What about exposing a higher level API, something where the viewer would do:
|
Do you know where I can find these kind of PDF docs with a form inside ?
Done in my last push.
|
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.
Do you know where I can find these kind of PDF docs with a form inside ?
Besides scraping the test-suite for all PDF documents with forms (grep
-ing for something like "/AcroForm" might work), I don't really know unfortunately.
a5062fc
to
2dc13a2
Compare
This patch is ready for review. |
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.
Phew, that was quite a large review. Despite the number of review comments, this looks really good code-wise (not tested yet)! I'm only not really sure about the XRef parts of the patch since I don't know too much about that to judge if the code is correct, and that must be correct because we don't want to make malformed documents. I would really appreciate a review from @Snuffleupagus and/or @brendandahl for that part of the patch.
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 only have two new comments left now that all changes have been made, and the following three comments from above are still open:
- Add support for saving forms #12137 (comment)
- Add support for saving forms #12137 (comment)
- Add support for saving forms #12137 (comment)
Once these five comments are addressed, this looks good to me code-wise. It's only pending manual testing then, and any checks from @brendandahl and/or @Snuffleupagus in particular for the XRef part of the patch.
Really nice work so far!
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.
r+ with the last comments from Tim. There's a few minor things I'd like to tweak/add, but they can be addressed in follow ups.
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.
Unfortunately I don't have nearly enough time to properly review the most complicated/important parts, which is the actual document/XRef writing.
However, I've left a couple of higher-level comments about API and/or default viewer issues that should be addressed; note e.g. that currently this is broken once you've actually built the viewer.
web/app.js
Outdated
eventBus._on( | ||
"download", | ||
AppOptions.get("renderInteractiveForms") | ||
? webViewerSave | ||
: webViewerDownload | ||
); |
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.
Sorry, but this won't work correctly with the event removal since the renderInteractiveForms
option may have been changed by then.
Please revert this, and instead change
Lines 2268 to 2270 in 7fb01f9
function webViewerDownload() { | |
PDFViewerApplication.download(); | |
} |
function webViewerDownload() {
if (AppOptions.get("renderInteractiveForms")) {
PDFViewerApplication.save();
} else {
PDFViewerApplication.download();
}
}
However, ideally you'd actually check if the document has actually been edited first, which once PR #12192 lands could be done easily with:
function webViewerDownload() {
if (
PDFViewerApplication.pdfDocument &&
PDFViewerApplication.pdfDocument.annotationStorage.size > 0
) {
PDFViewerApplication.save();
} else {
PDFViewerApplication.download();
}
}
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.
#12192 is now merged, so the size check can now be added.
web/viewer.js
Outdated
]).then(function ([ | ||
app, | ||
appOptions, | ||
genericCom, | ||
pdfPrintService, | ||
pdfSaveService, | ||
]) { |
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.
Please revert this change, since it's now unused.
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.
Code-wise this looks good to me when the final comments are addressed, namely:
- Add support for saving forms #12137 (comment) (the size check should be added now that the other PR is merged)
- Add support for saving forms #12137 (comment) (this line should be removed)
Functionality-wise Brendan will check the XRef part, do some manual tests and merge it since I'll be away for a few days. Indeed, any other points can be picked up in a follow-up.
You've clearly put a lot of work into this, and it shows. Thank you for your work!
No description provided.