diff --git a/app/controllers/account_configs_controller.rb b/app/controllers/account_configs_controller.rb
index b5b28982..bb8399db 100644
--- a/app/controllers/account_configs_controller.rb
+++ b/app/controllers/account_configs_controller.rb
@@ -11,7 +11,8 @@ class AccountConfigsController < ApplicationController
AccountConfig::ESIGNING_PREFERENCE_KEY,
AccountConfig::FORM_WITH_CONFETTI_KEY,
AccountConfig::DOWNLOAD_LINKS_AUTH_KEY,
- AccountConfig::FORCE_SSO_AUTH_KEY
+ AccountConfig::FORCE_SSO_AUTH_KEY,
+ AccountConfig::FLATTEN_RESULT_PDF_KEY
].freeze
InvalidKey = Class.new(StandardError)
diff --git a/app/models/account_config.rb b/app/models/account_config.rb
index e1018566..cd4320ef 100644
--- a/app/models/account_config.rb
+++ b/app/models/account_config.rb
@@ -36,6 +36,7 @@ class AccountConfig < ApplicationRecord
WEBHOOK_PREFERENCES_KEY = 'webhook_preferences'
DOWNLOAD_LINKS_AUTH_KEY = 'download_links_auth'
FORCE_SSO_AUTH_KEY = 'force_sso_auth'
+ FLATTEN_RESULT_PDF_KEY = 'flatten_result_pdf'
DEFAULT_VALUES = {
SUBMITTER_INVITATION_EMAIL_KEY => {
diff --git a/app/views/esign_settings/show.html.erb b/app/views/esign_settings/show.html.erb
index 2f2a4171..054f0b1e 100644
--- a/app/views/esign_settings/show.html.erb
+++ b/app/views/esign_settings/show.html.erb
@@ -140,6 +140,18 @@
<% end %>
<% end %>
+ <% account_config = AccountConfig.find_or_initialize_by(account: current_account, key: AccountConfig::FLATTEN_RESULT_PDF_KEY) %>
+ <% if can?(:manage, account_config) %>
+ <%= form_for account_config, url: account_configs_path, method: :post do |f| %>
+ <%= f.hidden_field :key %>
+
+
+ Remove PDF form fillable fields from the signed PDF (flatten form)
+
+ <%= f.check_box :value, { class: 'toggle', checked: account_config.value != false, onchange: 'this.form.requestSubmit()' } %>
+
+ <% end %>
+ <% end %>
<% end %>
diff --git a/lib/submissions/generate_result_attachments.rb b/lib/submissions/generate_result_attachments.rb
index 7ea37a26..7d4e060c 100644
--- a/lib/submissions/generate_result_attachments.rb
+++ b/lib/submissions/generate_result_attachments.rb
@@ -44,12 +44,16 @@ module Submissions
template = submitter.submission.template
+ is_flatten =
+ submitter.account.account_configs
+ .find_or_initialize_by(key: AccountConfig::FLATTEN_RESULT_PDF_KEY).value != false
+
account = submitter.account
pkcs = Accounts.load_signing_pkcs(account)
tsa_url = Accounts.load_timeserver_url(account)
attachments_data_cache = {}
- pdfs_index = build_pdfs_index(submitter)
+ pdfs_index = build_pdfs_index(submitter, flatten: is_flatten)
submitter.submission.template_fields.each do |field|
next if field['submitter_uuid'] != submitter.uuid
@@ -86,10 +90,12 @@ module Submissions
next if Array.wrap(value).compact_blank.blank?
- begin
- page.flatten_annotations
- rescue StandardError => e
- Rollbar.error(e) if defined?(Rollbar)
+ if is_flatten
+ begin
+ page.flatten_annotations
+ rescue StandardError => e
+ Rollbar.error(e) if defined?(Rollbar)
+ end
end
canvas = page.canvas(type: :overlay)
@@ -335,7 +341,7 @@ module Submissions
Digest::UUID.uuid_v5(Digest::UUID::OID_NAMESPACE, attachments.map(&:uuid).sort.join(':'))
end
- def build_pdfs_index(submitter)
+ def build_pdfs_index(submitter, flatten: true)
latest_submitter = find_last_submitter(submitter)
Submissions::EnsureResultGenerated.call(latest_submitter) if latest_submitter
@@ -353,10 +359,12 @@ module Submissions
pdf = maybe_rotate_pdf(pdf)
- begin
- pdf.acro_form&.flatten
- rescue StandardError => e
- Rollbar.error(e) if defined?(Rollbar)
+ if flatten
+ begin
+ pdf.acro_form&.flatten
+ rescue StandardError => e
+ Rollbar.error(e) if defined?(Rollbar)
+ end
end
pdf.config['font.on_missing_glyph'] = method(:on_missing_glyph).to_proc