diff --git a/app/controllers/templates_uploads_controller.rb b/app/controllers/templates_uploads_controller.rb index a21e8439d..9b9f5f602 100644 --- a/app/controllers/templates_uploads_controller.rb +++ b/app/controllers/templates_uploads_controller.rb @@ -26,6 +26,8 @@ def create rescue StandardError => e Rollbar.error(e) if defined?(Rollbar) + raise if Rails.env.local? + redirect_to root_path, alert: 'Unable to upload file' end diff --git a/lib/submissions/generate_result_attachments.rb b/lib/submissions/generate_result_attachments.rb index 4e37347cc..5cae5d7a4 100644 --- a/lib/submissions/generate_result_attachments.rb +++ b/lib/submissions/generate_result_attachments.rb @@ -383,6 +383,7 @@ def build_pdfs_index(submitter, flatten: true) if flatten begin + pdf.acro_form.create_appearances(force: true) if pdf.acro_form && pdf.acro_form[:NeedAppearances] pdf.acro_form&.flatten rescue StandardError => e Rollbar.error(e) if defined?(Rollbar) diff --git a/lib/templates/process_document.rb b/lib/templates/process_document.rb index 66ae493d1..9fccb7d3f 100644 --- a/lib/templates/process_document.rb +++ b/lib/templates/process_document.rb @@ -48,7 +48,7 @@ def generate_pdf_preview_images(attachment, data) pdf = HexaPDF::Document.new(io: StringIO.new(data)) number_of_pages = pdf.pages.size - data = maybe_flatten_form(data, pdf, attachment) + data = maybe_flatten_form(data, pdf) attachment.metadata['pdf'] ||= {} attachment.metadata['pdf']['number_of_pages'] = number_of_pages @@ -74,15 +74,15 @@ def generate_pdf_preview_images(attachment, data) end end - def maybe_flatten_form(data, pdf, attachment) + def maybe_flatten_form(data, pdf) return data if data.size > MAX_FLATTEN_FILE_SIZE return data if pdf.acro_form.blank? - return data if attachment.record.account.account_configs - .find_or_initialize_by(key: AccountConfig::FLATTEN_RESULT_PDF_KEY).value == false io = StringIO.new - pdf.acro_form&.flatten + pdf.acro_form.create_appearances(force: true) if pdf.acro_form[:NeedAppearances] + pdf.acro_form.flatten + pdf.write(io, incremental: false, validate: false) io.string