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

Save document only once on set-fields #64

Merged

Conversation

lucasdf
Copy link
Contributor

@lucasdf lucasdf commented Jul 13, 2021

Description of your pull request

Change set-fields logic to save the document only once after all fields have been renamed. The current behavior calls .save after filling each field.

Why should it be considered?

The main motivation for this is to support using the function set-fields with a ByteArrayOutputStream.

The current logic calls .save after renaming each field, which appends the whole content of the PDF to the output stream, producing a bloated and potentially invalid PDF.

This is not a problem when passing a file since it just overwrites the file content each time, which works but seems inefficient.

Why am I asking this?

In order to support using this function to save the result to a ByteArray.

Pull request checklist

  • The code is consistent with Clojure style guide.
  • All code passes the linter (clj-kondo --lint src).
  • You've added tests (if possible) to cover your change(s).
  • All tests are passing.
  • The commits are consistent with the Git commit style guide.
  • You've updated the changelog (if adding/changing user-visible functionality).

Thanks for maintaining this lib!

@lucasdf lucasdf force-pushed the avoid-multiple-saves-on-set-fields branch from dbb119b to 5930ee9 Compare July 13, 2021 19:56
@@ -0,0 +1,47 @@
name: Tests
Copy link
Contributor Author

@lucasdf lucasdf Jul 13, 2021

Choose a reason for hiding this comment

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

adding this to run tests automatically using Github actions. seems useful, but I can remove it if you rather not add it. this will apply for next PRs after this one is merged.

(set-fields "test/pdfs/interactiveform.pdf" out {"first_name" "My first name"
"last_name" "Last Name"})
(is (= (seq (Files/readAllBytes (.toPath (io/file "test/pdfs/test.pdf"))))
(seq (.toByteArray out))))))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

using set-fields with either a file or a byte-array produces the same result

@dotemacs
Copy link
Owner

Thanks for the contribution @lucasdf!

I like it. I'll merge it soon.

Thanks again.

@rafaeldelboni
Copy link

rafaeldelboni commented Oct 6, 2021

@dotemacs any news on this? Do we need to do something else to get this merged? Also, it came to my attention that are still several open pull requests for a while, do you need any help evaluating them? :)

@dotemacs dotemacs merged commit 5930ee9 into dotemacs:master Oct 8, 2021
@dotemacs
Copy link
Owner

dotemacs commented Oct 8, 2021

Hey @lucasdf

Thank you for doing this change.
I've merged it to master and I've updated the changelog.

Also, thank you for the patience in waiting for me to merge it

/cc @rafaeldelboni

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

Successfully merging this pull request may close these issues.

3 participants