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

Add support for saving forms #12137

Merged
merged 1 commit into from
Aug 12, 2020
Merged

Add support for saving forms #12137

merged 1 commit into from
Aug 12, 2020

Conversation

calixteman
Copy link
Contributor

No description provided.

@calixteman
Copy link
Contributor Author

@timvandermeij, @Snuffleupagus, @brendandahl, I'll add some tests tomorrow but it'd be nice to have a first feedback asap.

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a 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 XRefStms (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.

web/pdf_save_service.js Outdated Show resolved Hide resolved
src/core/writer.js Outdated Show resolved Hide resolved
src/core/worker.js Outdated Show resolved Hide resolved
src/core/writer.js Outdated Show resolved Hide resolved
@lundjordan lundjordan added the Gecko 81 Tracking work planned for Form Fill in Shirley 81 release label Jul 28, 2020
@brendandahl
Copy link
Contributor

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:

  1. Collect all the annotation storage data in a serializable format
  2. Pass that data into a new function that lives in src/display/api.js on the PDFDocumentProxy (e.g. save(annotationStorages) which would in turn:
    1. Send it to the worker which would do all the xref updating
    2. Return updated PDF data, that would resolve the promise

@calixteman
Copy link
Contributor Author

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.)
I don't want to write corrupted PDF!
I opened newly created PDF with evince successfully and I hope that you help me to find out errors if any.

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 XRefStms (i.e. cross-reference streams) and/or those where the XRef table is corrupt.

Do you know where I can find these kind of PDF docs with a form inside ?

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!?

Done in my last push.
For now I just added a smiley for the icon: I'm not the guy to draw a new icon.

Finally, note that as I've remarked inline, you'll need to split the XRef writing part into proper main/worker-thread parts.
Addressed too.

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a 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.

src/display/api.js Outdated Show resolved Hide resolved
src/core/writer.js Outdated Show resolved Hide resolved
src/core/writer.js Outdated Show resolved Hide resolved
src/core/writer.js Outdated Show resolved Hide resolved
@calixteman
Copy link
Contributor Author

This patch is ready for review.
It'd be nice to have a review for the beginning of next week, I'll address the issues you'll find and then we can merge it wednesday to have this patch in next firefox version.
@reviewers thx for your help.

Copy link
Contributor

@timvandermeij timvandermeij left a 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.

src/core/annotation.js Outdated Show resolved Hide resolved
src/core/annotation.js Outdated Show resolved Hide resolved
src/core/annotation.js Outdated Show resolved Hide resolved
src/core/annotation.js Outdated Show resolved Hide resolved
src/core/annotation.js Outdated Show resolved Hide resolved
web/pdf_save_service.js Outdated Show resolved Hide resolved
web/pdf_save_service.js Outdated Show resolved Hide resolved
web/pdf_save_service.js Outdated Show resolved Hide resolved
web/pdf_save_service.js Outdated Show resolved Hide resolved
web/pdf_save_service.js Outdated Show resolved Hide resolved
Copy link
Contributor

@timvandermeij timvandermeij left a 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:

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!

src/core/annotation.js Outdated Show resolved Hide resolved
src/core/writer.js Show resolved Hide resolved
Copy link
Contributor

@brendandahl brendandahl left a 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.

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a 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.

src/display/api.js Outdated Show resolved Hide resolved
src/display/api.js Outdated Show resolved Hide resolved
src/core/annotation.js Outdated Show resolved Hide resolved
src/core/worker.js Outdated Show resolved Hide resolved
web/app.js Outdated Show resolved Hide resolved
web/app.js Outdated
Comment on lines 1712 to 1717
eventBus._on(
"download",
AppOptions.get("renderInteractiveForms")
? webViewerSave
: webViewerDownload
);
Copy link
Collaborator

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

pdf.js/web/app.js

Lines 2268 to 2270 in 7fb01f9

function webViewerDownload() {
PDFViewerApplication.download();
}
to e.g.

 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(); 
   }
 }

Copy link
Contributor

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/app.js Outdated Show resolved Hide resolved
web/app.js Outdated Show resolved Hide resolved
web/app.js Outdated Show resolved Hide resolved
src/core/worker.js Outdated Show resolved Hide resolved
web/app.js Outdated Show resolved Hide resolved
web/app.js Outdated Show resolved Hide resolved
web/app.js Outdated Show resolved Hide resolved
web/viewer.js Outdated
Comment on lines 196 to 202
]).then(function ([
app,
appOptions,
genericCom,
pdfPrintService,
pdfSaveService,
]) {
Copy link
Collaborator

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.

Copy link
Contributor

@timvandermeij timvandermeij left a 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:

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!

@brendandahl brendandahl merged commit 7edc5cb into mozilla:master Aug 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
annotations form-acroform Gecko 81 Tracking work planned for Form Fill in Shirley 81 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants