Skip to content

Commit

Permalink
fix pdf form flatten fields
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed May 26, 2024
1 parent 99bc46b commit a249b0a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/controllers/templates_uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions lib/submissions/generate_result_attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions lib/templates/process_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a249b0a

Please sign in to comment.